Skip to content

Commit d35ac78

Browse files
committed
Auto merge of #143985 - makai410:rp-rename, r=<try>
rustc_public: de-StableMIR-ize This PR updates relevant docs about StableMIR, basically just rewording StableMIR/SMIR to rustc_public/rustc_public's IR. The README.md in the `rustc_public` crate is out-dated. I plan to rewrite it after we fork rustc_public into its own repository. This PR doesn't change the fact that we still use `-Z unpretty=stable-mir` as a rustc parameter for printing the IR, since I feel it's a bit verbose and weird if we use `-Z unpretty=rustc-public-ir`. I was wondering if we can have a short and easy alias for rustc_public's IR.
2 parents bf5e6cc + 01dba83 commit d35ac78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+309
-310
lines changed

compiler/rustc_public/src/alloc.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Memory allocation implementation for StableMIR.
1+
//! Memory allocation implementation for rustc_public.
22
//!
33
//! This module is responsible for constructing stable components.
44
//! All operations requiring rustc queries must be delegated
@@ -7,8 +7,8 @@
77
use rustc_abi::Align;
88
use rustc_middle::mir::ConstValue;
99
use rustc_middle::mir::interpret::AllocRange;
10-
use rustc_public_bridge::bridge::SmirError;
11-
use rustc_public_bridge::context::SmirCtxt;
10+
use rustc_public_bridge::bridge::Error as _;
11+
use rustc_public_bridge::context::CompilerCtxt;
1212
use rustc_public_bridge::{Tables, alloc};
1313

1414
use super::Error;
@@ -35,7 +35,7 @@ pub(crate) fn new_allocation<'tcx>(
3535
ty: rustc_middle::ty::Ty<'tcx>,
3636
const_value: ConstValue<'tcx>,
3737
tables: &mut Tables<'tcx, BridgeTys>,
38-
cx: &SmirCtxt<'tcx, BridgeTys>,
38+
cx: &CompilerCtxt<'tcx, BridgeTys>,
3939
) -> Allocation {
4040
try_new_allocation(ty, const_value, tables, cx)
4141
.unwrap_or_else(|_| panic!("Failed to convert: {const_value:?} to {ty:?}"))
@@ -46,7 +46,7 @@ pub(crate) fn try_new_allocation<'tcx>(
4646
ty: rustc_middle::ty::Ty<'tcx>,
4747
const_value: ConstValue<'tcx>,
4848
tables: &mut Tables<'tcx, BridgeTys>,
49-
cx: &SmirCtxt<'tcx, BridgeTys>,
49+
cx: &CompilerCtxt<'tcx, BridgeTys>,
5050
) -> Result<Allocation, Error> {
5151
let layout = alloc::create_ty_and_layout(cx, ty).map_err(|e| Error::from_internal(e))?;
5252
match const_value {
@@ -59,7 +59,7 @@ pub(crate) fn try_new_allocation<'tcx>(
5959
}
6060
ConstValue::Indirect { alloc_id, offset } => {
6161
let alloc = alloc::try_new_indirect(alloc_id, cx);
62-
use rustc_public_bridge::context::SmirAllocRange;
62+
use rustc_public_bridge::context::AllocRangeHelpers;
6363
Ok(allocation_filter(&alloc.0, cx.alloc_range(offset, layout.size), tables, cx))
6464
}
6565
}
@@ -70,7 +70,7 @@ pub(super) fn allocation_filter<'tcx>(
7070
alloc: &rustc_middle::mir::interpret::Allocation,
7171
alloc_range: AllocRange,
7272
tables: &mut Tables<'tcx, BridgeTys>,
73-
cx: &SmirCtxt<'tcx, BridgeTys>,
73+
cx: &CompilerCtxt<'tcx, BridgeTys>,
7474
) -> Allocation {
7575
alloc::allocation_filter(alloc, alloc_range, tables, cx)
7676
}

compiler/rustc_public/src/compiler_interface.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Define the interface with the Rust compiler.
22
//!
3-
//! StableMIR users should not use any of the items in this module directly.
3+
//! rustc_public users should not use any of the items in this module directly.
44
//! These APIs have no stability guarantee.
55
66
use std::cell::Cell;
77

88
use rustc_hir::def::DefKind;
9-
use rustc_public_bridge::context::SmirCtxt;
10-
use rustc_public_bridge::{Bridge, SmirContainer};
9+
use rustc_public_bridge::context::CompilerCtxt;
10+
use rustc_public_bridge::{Bridge, Container};
1111
use tracing::debug;
1212

1313
use crate::abi::{FnAbi, Layout, LayoutShape, ReprOptions};
@@ -66,13 +66,13 @@ impl Bridge for BridgeTys {
6666
type Allocation = crate::ty::Allocation;
6767
}
6868

69-
/// Stable public API for querying compiler information.
69+
/// Public API for querying compiler information.
7070
///
71-
/// All queries are delegated to [`rustc_public_bridge::context::SmirCtxt`] that provides
71+
/// All queries are delegated to [`rustc_public_bridge::context::CompilerCtxt`] that provides
7272
/// similar APIs but based on internal rustc constructs.
7373
///
7474
/// Do not use this directly. This is currently used in the macro expansion.
75-
pub(crate) trait SmirInterface {
75+
pub(crate) trait CompilerInterface {
7676
fn entry_fn(&self) -> Option<CrateItem>;
7777
/// Retrieve all items of the local crate that have a MIR associated with them.
7878
fn all_local_items(&self) -> CrateItems;
@@ -316,7 +316,7 @@ pub(crate) trait SmirInterface {
316316
fn associated_items(&self, def_id: DefId) -> AssocItems;
317317
}
318318

319-
impl<'tcx> SmirInterface for SmirContainer<'tcx, BridgeTys> {
319+
impl<'tcx> CompilerInterface for Container<'tcx, BridgeTys> {
320320
fn entry_fn(&self) -> Option<CrateItem> {
321321
let mut tables = self.tables.borrow_mut();
322322
let cx = &*self.cx.borrow();
@@ -567,7 +567,7 @@ impl<'tcx> SmirInterface for SmirContainer<'tcx, BridgeTys> {
567567
DefKind::Fn => ForeignItemKind::Fn(tables.fn_def(def_id)),
568568
DefKind::Static { .. } => ForeignItemKind::Static(tables.static_def(def_id)),
569569
DefKind::ForeignTy => {
570-
use rustc_public_bridge::context::SmirTy;
570+
use rustc_public_bridge::context::TyHelpers;
571571
ForeignItemKind::Type(tables.intern_ty(cx.new_foreign(def_id)))
572572
}
573573
def_kind => unreachable!("Unexpected kind for a foreign item: {:?}", def_kind),
@@ -1059,36 +1059,36 @@ impl<'tcx> SmirInterface for SmirContainer<'tcx, BridgeTys> {
10591059
}
10601060
}
10611061

1062-
// A thread local variable that stores a pointer to [`SmirInterface`].
1062+
// A thread local variable that stores a pointer to [`CompilerInterface`].
10631063
scoped_tls::scoped_thread_local!(static TLV: Cell<*const ()>);
10641064

1065-
pub(crate) fn run<F, T>(interface: &dyn SmirInterface, f: F) -> Result<T, Error>
1065+
pub(crate) fn run<F, T>(interface: &dyn CompilerInterface, f: F) -> Result<T, Error>
10661066
where
10671067
F: FnOnce() -> T,
10681068
{
10691069
if TLV.is_set() {
1070-
Err(Error::from("StableMIR already running"))
1070+
Err(Error::from("rustc_public already running"))
10711071
} else {
10721072
let ptr: *const () = (&raw const interface) as _;
10731073
TLV.set(&Cell::new(ptr), || Ok(f()))
10741074
}
10751075
}
10761076

1077-
/// Execute the given function with access the [`SmirInterface`].
1077+
/// Execute the given function with access the [`CompilerInterface`].
10781078
///
10791079
/// I.e., This function will load the current interface and calls a function with it.
10801080
/// Do not nest these, as that will ICE.
1081-
pub(crate) fn with<R>(f: impl FnOnce(&dyn SmirInterface) -> R) -> R {
1081+
pub(crate) fn with<R>(f: impl FnOnce(&dyn CompilerInterface) -> R) -> R {
10821082
assert!(TLV.is_set());
10831083
TLV.with(|tlv| {
10841084
let ptr = tlv.get();
10851085
assert!(!ptr.is_null());
1086-
f(unsafe { *(ptr as *const &dyn SmirInterface) })
1086+
f(unsafe { *(ptr as *const &dyn CompilerInterface) })
10871087
})
10881088
}
10891089

10901090
fn smir_crate<'tcx>(
1091-
cx: &SmirCtxt<'tcx, BridgeTys>,
1091+
cx: &CompilerCtxt<'tcx, BridgeTys>,
10921092
crate_num: rustc_span::def_id::CrateNum,
10931093
) -> Crate {
10941094
let name = cx.crate_name(crate_num);

compiler/rustc_public/src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! When things go wrong, we need some error handling.
2-
//! There are a few different types of errors in StableMIR:
2+
//! There are a few different types of errors in rustc_public:
33
//!
44
//! - [CompilerError]: This represents errors that can be raised when invoking the compiler.
55
//! - [Error]: Generic error that represents the reason why a request that could not be fulfilled.
66
77
use std::fmt::{Debug, Display, Formatter};
88
use std::{fmt, io};
99

10-
use rustc_public_bridge::bridge::SmirError;
10+
use rustc_public_bridge::bridge;
1111

1212
macro_rules! error {
1313
($fmt: literal $(,)?) => { Error(format!($fmt)) };
@@ -32,7 +32,7 @@ pub enum CompilerError<T> {
3232
#[derive(Clone, Debug, Eq, PartialEq)]
3333
pub struct Error(pub(crate) String);
3434

35-
impl SmirError for Error {
35+
impl bridge::Error for Error {
3636
fn new(msg: String) -> Self {
3737
Self(msg)
3838
}

compiler/rustc_public/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use std::{fmt, io};
2424

2525
pub(crate) use rustc_public_bridge::IndexedVal;
2626
use rustc_public_bridge::Tables;
27-
use rustc_public_bridge::context::SmirCtxt;
27+
use rustc_public_bridge::context::CompilerCtxt;
2828
/// Export the rustc_internal APIs. Note that this module has no stability
2929
/// guarantees and it is not taken into account for semver.
3030
#[cfg(feature = "rustc_internal")]
@@ -288,7 +288,7 @@ impl rustc_public_bridge::bridge::Allocation<compiler_interface::BridgeTys>
288288
align: u64,
289289
mutability: rustc_middle::mir::Mutability,
290290
tables: &mut Tables<'tcx, compiler_interface::BridgeTys>,
291-
cx: &SmirCtxt<'tcx, compiler_interface::BridgeTys>,
291+
cx: &CompilerCtxt<'tcx, compiler_interface::BridgeTys>,
292292
) -> Self {
293293
Self {
294294
bytes,

compiler/rustc_public/src/mir/alloc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::target::{Endian, MachineInfo};
99
use crate::ty::{Allocation, Binder, ExistentialTraitRef, Ty};
1010
use crate::{Error, IndexedVal, with};
1111

12-
/// An allocation in the SMIR global memory can be either a function pointer,
12+
/// An allocation in the rustc_public's IR global memory can be either a function pointer,
1313
/// a static, or a "real" allocation with some data in it.
1414
#[derive(Debug, Clone, Eq, PartialEq, Serialize)]
1515
pub enum GlobalAlloc {

compiler/rustc_public/src/mir/body.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::ty::{
1010
};
1111
use crate::{Error, Opaque, Span, Symbol};
1212

13-
/// The SMIR representation of a single function.
13+
/// The rustc_public's IR representation of a single function.
1414
#[derive(Clone, Debug, Serialize)]
1515
pub struct Body {
1616
pub blocks: Vec<BasicBlock>,
@@ -771,8 +771,8 @@ pub enum VarDebugInfoContents {
771771
// In MIR ProjectionElem is parameterized on the second Field argument and the Index argument. This
772772
// is so it can be used for both Places (for which the projection elements are of type
773773
// ProjectionElem<Local, Ty>) and user-provided type annotations (for which the projection elements
774-
// are of type ProjectionElem<(), ()>). In SMIR we don't need this generality, so we just use
775-
// ProjectionElem for Places.
774+
// are of type ProjectionElem<(), ()>).
775+
// In rustc_public's IR we don't need this generality, so we just use ProjectionElem for Places.
776776
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
777777
pub enum ProjectionElem {
778778
/// Dereference projections (e.g. `*_1`) project to the address referenced by the base place.

compiler/rustc_public/src/mir/mono.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::{Debug, Formatter};
22
use std::io;
33

4-
use rustc_public_bridge::bridge::SmirError;
4+
use rustc_public_bridge::bridge;
55
use serde::Serialize;
66

77
use crate::abi::FnAbi;
@@ -62,7 +62,7 @@ impl Instance {
6262
/// For more information on fallback body, see <https://github.com/rust-lang/rust/issues/93145>.
6363
///
6464
/// This call is much cheaper than `instance.body().is_some()`, since it doesn't try to build
65-
/// the StableMIR body.
65+
/// the rustc_public's IR body.
6666
pub fn has_body(&self) -> bool {
6767
with(|cx| cx.has_body(self.def.def_id()))
6868
}
@@ -120,9 +120,9 @@ impl Instance {
120120
/// Resolve an instance starting from a function definition and generic arguments.
121121
pub fn resolve(def: FnDef, args: &GenericArgs) -> Result<Instance, Error> {
122122
with(|context| {
123-
context
124-
.resolve_instance(def, args)
125-
.ok_or_else(|| Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`")))
123+
context.resolve_instance(def, args).ok_or_else(|| {
124+
bridge::Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`"))
125+
})
126126
})
127127
}
128128

@@ -134,9 +134,9 @@ impl Instance {
134134
/// Resolve an instance for a given function pointer.
135135
pub fn resolve_for_fn_ptr(def: FnDef, args: &GenericArgs) -> Result<Instance, Error> {
136136
with(|context| {
137-
context
138-
.resolve_for_fn_ptr(def, args)
139-
.ok_or_else(|| Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`")))
137+
context.resolve_for_fn_ptr(def, args).ok_or_else(|| {
138+
bridge::Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`"))
139+
})
140140
})
141141
}
142142

@@ -147,17 +147,17 @@ impl Instance {
147147
kind: ClosureKind,
148148
) -> Result<Instance, Error> {
149149
with(|context| {
150-
context
151-
.resolve_closure(def, args, kind)
152-
.ok_or_else(|| Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`")))
150+
context.resolve_closure(def, args, kind).ok_or_else(|| {
151+
bridge::Error::new(format!("Failed to resolve `{def:?}` with `{args:?}`"))
152+
})
153153
})
154154
}
155155

156156
/// Check whether this instance is an empty shim.
157157
///
158158
/// Allow users to check if this shim can be ignored when called directly.
159159
///
160-
/// We have decided not to export different types of Shims to StableMIR users, however, this
160+
/// We have decided not to export different types of Shims to rustc_public users, however, this
161161
/// is a query that can be very helpful for users when processing DropGlue.
162162
///
163163
/// When generating code for a Drop terminator, users can ignore an empty drop glue.
@@ -201,7 +201,7 @@ impl TryFrom<CrateItem> for Instance {
201201
if !context.requires_monomorphization(def_id) {
202202
Ok(context.mono_instance(def_id))
203203
} else {
204-
Err(Error::new("Item requires monomorphization".to_string()))
204+
Err(bridge::Error::new("Item requires monomorphization".to_string()))
205205
}
206206
})
207207
}
@@ -217,7 +217,7 @@ impl TryFrom<Instance> for CrateItem {
217217
if value.kind == InstanceKind::Item && context.has_body(value.def.def_id()) {
218218
Ok(CrateItem(context.instance_def_id(value.def)))
219219
} else {
220-
Err(Error::new(format!("Item kind `{:?}` cannot be converted", value.kind)))
220+
Err(bridge::Error::new(format!("Item kind `{:?}` cannot be converted", value.kind)))
221221
}
222222
})
223223
}
@@ -263,7 +263,7 @@ impl TryFrom<CrateItem> for StaticDef {
263263
if matches!(value.kind(), ItemKind::Static) {
264264
Ok(StaticDef(value.0))
265265
} else {
266-
Err(Error::new(format!("Expected a static item, but found: {value:?}")))
266+
Err(bridge::Error::new(format!("Expected a static item, but found: {value:?}")))
267267
}
268268
}
269269
}

compiler/rustc_public/src/mir/pretty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Implement methods to pretty print stable MIR body.
1+
//! Implement methods to pretty print rustc_public's IR body.
22
use std::fmt::Debug;
33
use std::io::Write;
44
use std::{fmt, io, iter};

compiler/rustc_public/src/mir/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! # The Stable MIR Visitor
1+
//! # The rustc_public's IR Visitor
22
//!
33
//! ## Overview
44
//!

0 commit comments

Comments
 (0)