Skip to content

Commit 5b390cd

Browse files
makai410celinval
andcommitted
Make SmirInterface pub(crate) and rename Context to SmirContext
Co-authored-by: Celina G. Val <[email protected]>
1 parent 35a20de commit 5b390cd

File tree

3 files changed

+114
-102
lines changed

3 files changed

+114
-102
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use stable_mir::abi::Layout;
2121
use stable_mir::compiler_interface::SmirInterface;
2222
use stable_mir::ty::IndexedVal;
2323

24-
use crate::rustc_smir::context::Context;
24+
use crate::rustc_smir::context::SmirCtxt;
2525
use crate::rustc_smir::{Stable, Tables};
2626
use crate::stable_mir;
2727

@@ -197,7 +197,7 @@ pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
197197
// datastructures and stable MIR datastructures
198198
scoped_thread_local! (static TLV: Cell<*const ()>);
199199

200-
pub(crate) fn init<'tcx, F, T>(cx: &Context<'tcx>, f: F) -> T
200+
pub(crate) fn init<'tcx, F, T>(cx: &SmirCtxt<'tcx>, f: F) -> T
201201
where
202202
F: FnOnce() -> T,
203203
{
@@ -213,7 +213,7 @@ pub(crate) fn with_tables<R>(f: impl for<'tcx> FnOnce(&mut Tables<'tcx>) -> R) -
213213
TLV.with(|tlv| {
214214
let ptr = tlv.get();
215215
assert!(!ptr.is_null());
216-
let context = ptr as *const Context<'_>;
216+
let context = ptr as *const SmirCtxt<'_>;
217217
let mut tables = unsafe { (*context).0.borrow_mut() };
218218
f(&mut *tables)
219219
})
@@ -223,7 +223,7 @@ pub fn run<F, T>(tcx: TyCtxt<'_>, f: F) -> Result<T, Error>
223223
where
224224
F: FnOnce() -> T,
225225
{
226-
let tables = Context(RefCell::new(Tables {
226+
let tables = SmirCtxt(RefCell::new(Tables {
227227
tcx,
228228
def_ids: IndexMap::default(),
229229
alloc_ids: IndexMap::default(),

compiler/rustc_smir/src/rustc_smir/context.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
//! Implementation of `[stable_mir::compiler_interface::Context]` trait.
2-
//!
3-
//! This trait is currently the main interface between the Rust compiler,
4-
//! and the `stable_mir` crate.
1+
//! Implementation of StableMIR Context.
52
63
#![allow(rustc::usage_of_qualified_ty)]
74

@@ -36,10 +33,13 @@ use crate::rustc_smir::builder::BodyBuilder;
3633
use crate::rustc_smir::{Stable, Tables, alloc, filter_def_ids, new_item_kind, smir_crate};
3734
use crate::stable_mir;
3835

39-
/// Internal context holding direct rustc access.
40-
pub struct Context<'tcx>(pub RefCell<Tables<'tcx>>);
36+
/// Provides direct access to rustc's internal queries.
37+
///
38+
/// The [`crate::stable_mir::compiler_interface::SmirInterface`] must go through
39+
/// this context to obtain rustc-level information.
40+
pub struct SmirCtxt<'tcx>(pub RefCell<Tables<'tcx>>);
4141

42-
impl<'tcx> Context<'tcx> {
42+
impl<'tcx> SmirCtxt<'tcx> {
4343
pub fn target_info(&self) -> MachineInfo {
4444
let mut tables = self.0.borrow_mut();
4545
MachineInfo {

0 commit comments

Comments
 (0)