Skip to content

Commit 5344e63

Browse files
committed
Move check to public API
1 parent a54683b commit 5344e63

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

Diff for: compiler/rustc_smir/src/rustc_smir/context.rs

+6-19
Original file line numberDiff line numberDiff line change
@@ -587,27 +587,14 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
587587
}
588588
}
589589

590-
/// Retrieve the plain intrinsic name of an instance if it's an intrinsic.
591-
fn intrinsic_name(&self, def: InstanceDef) -> Option<Symbol> {
590+
/// Retrieve the plain intrinsic name of an instance.
591+
///
592+
/// This assumes that the instance is an intrinsic.
593+
fn intrinsic_name(&self, def: InstanceDef) -> Symbol {
592594
let tables = self.0.borrow_mut();
593595
let instance = tables.instances[def];
594-
match instance.def {
595-
ty::InstanceDef::Intrinsic(..) | ty::InstanceDef::Item(..) => {
596-
let intrinsic = tables.tcx.intrinsic(instance.def_id())?;
597-
Some(intrinsic.name.to_string())
598-
}
599-
ty::InstanceDef::VTableShim(..)
600-
| ty::InstanceDef::ReifyShim(..)
601-
| ty::InstanceDef::Virtual(..)
602-
| ty::InstanceDef::ThreadLocalShim(..)
603-
| ty::InstanceDef::ClosureOnceShim { .. }
604-
| ty::InstanceDef::ConstructCoroutineInClosureShim { .. }
605-
| ty::InstanceDef::CoroutineKindShim { .. }
606-
| ty::InstanceDef::DropGlue(..)
607-
| ty::InstanceDef::FnPtrShim(..)
608-
| ty::InstanceDef::CloneShim(..)
609-
| ty::InstanceDef::FnPtrAddrShim(..) => None,
610-
}
596+
let intrinsic = tables.tcx.intrinsic(instance.def_id()).unwrap();
597+
intrinsic.name.to_string()
611598
}
612599

613600
fn ty_layout(&self, ty: Ty) -> Result<Layout, Error> {

Diff for: compiler/stable_mir/src/compiler_interface.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub trait Context {
183183
fn vtable_allocation(&self, global_alloc: &GlobalAlloc) -> Option<AllocId>;
184184
fn krate(&self, def_id: DefId) -> Crate;
185185
fn instance_name(&self, def: InstanceDef, trimmed: bool) -> Symbol;
186-
fn intrinsic_name(&self, def: InstanceDef) -> Option<Symbol>;
186+
fn intrinsic_name(&self, def: InstanceDef) -> Symbol;
187187

188188
/// Return information about the target machine.
189189
fn target_info(&self) -> MachineInfo;

Diff for: compiler/stable_mir/src/mir/mono.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ impl Instance {
9595
/// The plain name does not include type arguments (as `trimmed_name` does),
9696
/// which is more convenient to match with intrinsic symbols.
9797
pub fn intrinsic_name(&self) -> Option<Symbol> {
98-
with(|context| context.intrinsic_name(self.def))
98+
match self.kind {
99+
InstanceKind::Intrinsic => Some(with(|context| context.intrinsic_name(self.def))),
100+
InstanceKind::Item | InstanceKind::Virtual { .. } | InstanceKind::Shim => None,
101+
}
99102
}
100103

101104
/// Resolve an instance starting from a function definition and generic arguments.

0 commit comments

Comments
 (0)