Skip to content

Commit e0a4693

Browse files
committed
Add method to get instance instantiation arguments
1 parent 92ad4b4 commit e0a4693

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

compiler/rustc_smir/src/rustc_smir/context.rs

+6
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> {
341341
instance.ty(tables.tcx, ParamEnv::reveal_all()).stable(&mut *tables)
342342
}
343343

344+
fn instance_args(&self, def: InstanceDef) -> GenericArgs {
345+
let mut tables = self.0.borrow_mut();
346+
let instance = tables.instances[def];
347+
instance.args.stable(&mut *tables)
348+
}
349+
344350
fn instance_abi(&self, def: InstanceDef) -> Result<FnAbi, Error> {
345351
let mut tables = self.0.borrow_mut();
346352
let instance = tables.instances[def];

compiler/stable_mir/src/compiler_interface.rs

+3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ pub trait Context {
125125
/// Get the instance type with generic substitutions applied and lifetimes erased.
126126
fn instance_ty(&self, instance: InstanceDef) -> Ty;
127127

128+
/// Get the instantiation types.
129+
fn instance_args(&self, def: InstanceDef) -> GenericArgs;
130+
128131
/// Get the instance.
129132
fn instance_def_id(&self, instance: InstanceDef) -> DefId;
130133

compiler/stable_mir/src/mir/mono.rs

+6
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ pub enum InstanceKind {
3535
}
3636

3737
impl Instance {
38+
/// Get the arguments this instance was instantiated with.
39+
pub fn args(&self) -> GenericArgs {
40+
with(|cx| cx.instance_args(self.def))
41+
}
42+
3843
/// Get the body of an Instance. The body will be eagerly monomorphized.
3944
pub fn body(&self) -> Option<Body> {
4045
with(|context| context.instance_body(self.def))
@@ -148,6 +153,7 @@ impl Debug for Instance {
148153
f.debug_struct("Instance")
149154
.field("kind", &self.kind)
150155
.field("def", &self.mangled_name())
156+
.field("args", &self.args())
151157
.finish()
152158
}
153159
}

0 commit comments

Comments
 (0)