Rollup merge of #119141 - celinval:smir-instance-args, r=compiler-errors

Add method to get instance instantiation arguments

Add a method to get the instance instantiation arguments, and include that information in the instance debug.
This commit is contained in:
Matthias Krüger 2023-12-20 21:18:59 +01:00 committed by GitHub
commit f6a04f693b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -341,6 +341,12 @@ fn instance_ty(&self, def: InstanceDef) -> stable_mir::ty::Ty {
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_abi(&self, def: InstanceDef) -> Result<FnAbi, Error> {
let mut tables = self.0.borrow_mut();
let instance = tables.instances[def];

View File

@ -125,6 +125,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;

View File

@ -35,6 +35,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))
@ -148,6 +153,7 @@ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Instance")
.field("kind", &self.kind)
.field("def", &self.mangled_name())
.field("args", &self.args())
.finish()
}
}