Skip to content

Commit

Permalink
Move check to public API
Browse files Browse the repository at this point in the history
  • Loading branch information
adpaco-aws committed Mar 12, 2024
1 parent a54683b commit 5344e63
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 21 deletions.
25 changes: 6 additions & 19 deletions compiler/rustc_smir/src/rustc_smir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,27 +587,14 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
}
}

/// Retrieve the plain intrinsic name of an instance if it's an intrinsic.
fn intrinsic_name(&self, def: InstanceDef) -> Option<Symbol> {
/// Retrieve the plain intrinsic name of an instance.
///
/// This assumes that the instance is an intrinsic.
fn intrinsic_name(&self, def: InstanceDef) -> Symbol {
let tables = self.0.borrow_mut();
let instance = tables.instances[def];
match instance.def {
ty::InstanceDef::Intrinsic(..) | ty::InstanceDef::Item(..) => {
let intrinsic = tables.tcx.intrinsic(instance.def_id())?;
Some(intrinsic.name.to_string())
}
ty::InstanceDef::VTableShim(..)
| ty::InstanceDef::ReifyShim(..)
| ty::InstanceDef::Virtual(..)
| ty::InstanceDef::ThreadLocalShim(..)
| ty::InstanceDef::ClosureOnceShim { .. }
| ty::InstanceDef::ConstructCoroutineInClosureShim { .. }
| ty::InstanceDef::CoroutineKindShim { .. }
| ty::InstanceDef::DropGlue(..)
| ty::InstanceDef::FnPtrShim(..)
| ty::InstanceDef::CloneShim(..)
| ty::InstanceDef::FnPtrAddrShim(..) => None,
}
let intrinsic = tables.tcx.intrinsic(instance.def_id()).unwrap();
intrinsic.name.to_string()
}

fn ty_layout(&self, ty: Ty) -> Result<Layout, Error> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/stable_mir/src/compiler_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ pub trait Context {
fn vtable_allocation(&self, global_alloc: &GlobalAlloc) -> Option<AllocId>;
fn krate(&self, def_id: DefId) -> Crate;
fn instance_name(&self, def: InstanceDef, trimmed: bool) -> Symbol;
fn intrinsic_name(&self, def: InstanceDef) -> Option<Symbol>;
fn intrinsic_name(&self, def: InstanceDef) -> Symbol;

/// Return information about the target machine.
fn target_info(&self) -> MachineInfo;
Expand Down
5 changes: 4 additions & 1 deletion compiler/stable_mir/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ impl Instance {
/// The plain name does not include type arguments (as `trimmed_name` does),
/// which is more convenient to match with intrinsic symbols.
pub fn intrinsic_name(&self) -> Option<Symbol> {
with(|context| context.intrinsic_name(self.def))
match self.kind {
InstanceKind::Intrinsic => Some(with(|context| context.intrinsic_name(self.def))),
InstanceKind::Item | InstanceKind::Virtual { .. } | InstanceKind::Shim => None,
}
}

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

0 comments on commit 5344e63

Please sign in to comment.