Skip to content

Commit

Permalink
Add method to get instance instantiation arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
celinval committed Dec 19, 2023
1 parent a7690a3 commit 2fd4c26
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_smir/src/rustc_smir/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
instance.ty(tables.tcx, ParamEnv::reveal_all()).stable(&mut *tables)
}

fn instance_args(&self, def: InstanceDef) -> GenericArgs {
let mut tables = self.0.borrow_mut();
let instance = tables.instances[def];
instance.args.stable(&mut *tables)
}

fn instance_def_id(&self, def: InstanceDef) -> stable_mir::DefId {
let mut tables = self.0.borrow_mut();
let def_id = tables.instances[def].def_id();
Expand Down
3 changes: 3 additions & 0 deletions compiler/stable_mir/src/compiler_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ pub trait Context {
/// Get the instance type with generic substitutions applied and lifetimes erased.
fn instance_ty(&self, instance: InstanceDef) -> Ty;

/// Get the instantiation types.
fn instance_args(&self, def: InstanceDef) -> GenericArgs;

/// Get the instance.
fn instance_def_id(&self, instance: InstanceDef) -> DefId;

Expand Down
6 changes: 6 additions & 0 deletions compiler/stable_mir/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ pub enum InstanceKind {
}

impl Instance {
/// Get the arguments this instance was instantiated with.
pub fn args(&self) -> GenericArgs {
with(|cx| cx.instance_args(self.def))
}

/// Get the body of an Instance. The body will be eagerly monomorphized.
pub fn body(&self) -> Option<Body> {
with(|context| context.instance_body(self.def))
Expand Down Expand Up @@ -142,6 +147,7 @@ impl Debug for Instance {
f.debug_struct("Instance")
.field("kind", &self.kind)
.field("def", &self.mangled_name())
.field("args", &self.args())
.finish()
}
}
Expand Down

0 comments on commit 2fd4c26

Please sign in to comment.