|
1 | 1 | //! Define the interface with the Rust compiler. |
2 | 2 | //! |
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. |
4 | 4 | //! These APIs have no stability guarantee. |
5 | 5 |
|
6 | 6 | use std::cell::Cell; |
7 | 7 |
|
8 | 8 | 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}; |
11 | 11 | use tracing::debug; |
12 | 12 |
|
13 | 13 | use crate::abi::{FnAbi, Layout, LayoutShape, ReprOptions}; |
@@ -66,13 +66,13 @@ impl Bridge for BridgeTys { |
66 | 66 | type Allocation = crate::ty::Allocation; |
67 | 67 | } |
68 | 68 |
|
69 | | -/// Stable public API for querying compiler information. |
| 69 | +/// Public API for querying compiler information. |
70 | 70 | /// |
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 |
72 | 72 | /// similar APIs but based on internal rustc constructs. |
73 | 73 | /// |
74 | 74 | /// Do not use this directly. This is currently used in the macro expansion. |
75 | | -pub(crate) trait SmirInterface { |
| 75 | +pub(crate) trait CompilerInterface { |
76 | 76 | fn entry_fn(&self) -> Option<CrateItem>; |
77 | 77 | /// Retrieve all items of the local crate that have a MIR associated with them. |
78 | 78 | fn all_local_items(&self) -> CrateItems; |
@@ -316,7 +316,7 @@ pub(crate) trait SmirInterface { |
316 | 316 | fn associated_items(&self, def_id: DefId) -> AssocItems; |
317 | 317 | } |
318 | 318 |
|
319 | | -impl<'tcx> SmirInterface for SmirContainer<'tcx, BridgeTys> { |
| 319 | +impl<'tcx> CompilerInterface for Container<'tcx, BridgeTys> { |
320 | 320 | fn entry_fn(&self) -> Option<CrateItem> { |
321 | 321 | let mut tables = self.tables.borrow_mut(); |
322 | 322 | let cx = &*self.cx.borrow(); |
@@ -567,7 +567,7 @@ impl<'tcx> SmirInterface for SmirContainer<'tcx, BridgeTys> { |
567 | 567 | DefKind::Fn => ForeignItemKind::Fn(tables.fn_def(def_id)), |
568 | 568 | DefKind::Static { .. } => ForeignItemKind::Static(tables.static_def(def_id)), |
569 | 569 | DefKind::ForeignTy => { |
570 | | - use rustc_public_bridge::context::SmirTy; |
| 570 | + use rustc_public_bridge::context::TyHelpers; |
571 | 571 | ForeignItemKind::Type(tables.intern_ty(cx.new_foreign(def_id))) |
572 | 572 | } |
573 | 573 | def_kind => unreachable!("Unexpected kind for a foreign item: {:?}", def_kind), |
@@ -1059,36 +1059,36 @@ impl<'tcx> SmirInterface for SmirContainer<'tcx, BridgeTys> { |
1059 | 1059 | } |
1060 | 1060 | } |
1061 | 1061 |
|
1062 | | -// A thread local variable that stores a pointer to [`SmirInterface`]. |
| 1062 | +// A thread local variable that stores a pointer to [`CompilerInterface`]. |
1063 | 1063 | scoped_tls::scoped_thread_local!(static TLV: Cell<*const ()>); |
1064 | 1064 |
|
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> |
1066 | 1066 | where |
1067 | 1067 | F: FnOnce() -> T, |
1068 | 1068 | { |
1069 | 1069 | if TLV.is_set() { |
1070 | | - Err(Error::from("StableMIR already running")) |
| 1070 | + Err(Error::from("rustc_public already running")) |
1071 | 1071 | } else { |
1072 | 1072 | let ptr: *const () = (&raw const interface) as _; |
1073 | 1073 | TLV.set(&Cell::new(ptr), || Ok(f())) |
1074 | 1074 | } |
1075 | 1075 | } |
1076 | 1076 |
|
1077 | | -/// Execute the given function with access the [`SmirInterface`]. |
| 1077 | +/// Execute the given function with access the [`CompilerInterface`]. |
1078 | 1078 | /// |
1079 | 1079 | /// I.e., This function will load the current interface and calls a function with it. |
1080 | 1080 | /// 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 { |
1082 | 1082 | assert!(TLV.is_set()); |
1083 | 1083 | TLV.with(|tlv| { |
1084 | 1084 | let ptr = tlv.get(); |
1085 | 1085 | assert!(!ptr.is_null()); |
1086 | | - f(unsafe { *(ptr as *const &dyn SmirInterface) }) |
| 1086 | + f(unsafe { *(ptr as *const &dyn CompilerInterface) }) |
1087 | 1087 | }) |
1088 | 1088 | } |
1089 | 1089 |
|
1090 | 1090 | fn smir_crate<'tcx>( |
1091 | | - cx: &SmirCtxt<'tcx, BridgeTys>, |
| 1091 | + cx: &CompilerCtxt<'tcx, BridgeTys>, |
1092 | 1092 | crate_num: rustc_span::def_id::CrateNum, |
1093 | 1093 | ) -> Crate { |
1094 | 1094 | let name = cx.crate_name(crate_num); |
|
0 commit comments