Skip to content

Commit b9db38f

Browse files
committed
Fix CrateItem::kind() to include constructors
- Also add a method to get the instance instantiation arguments, and include that information in the instance debug.
1 parent 36bb79f commit b9db38f

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

compiler/rustc_smir/src/rustc_smir/context.rs

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

338+
fn instance_args(&self, def: InstanceDef) -> GenericArgs {
339+
let mut tables = self.0.borrow_mut();
340+
let instance = tables.instances[def];
341+
instance.args.stable(&mut *tables)
342+
}
343+
338344
fn instance_def_id(&self, def: InstanceDef) -> stable_mir::DefId {
339345
let mut tables = self.0.borrow_mut();
340346
let def_id = tables.instances[def].def_id();

compiler/rustc_smir/src/rustc_smir/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind {
8585
| DefKind::Field
8686
| DefKind::LifetimeParam
8787
| DefKind::Impl { .. }
88-
| DefKind::Ctor(_, _)
8988
| DefKind::GlobalAsm => {
9089
unreachable!("Not a valid item kind: {kind:?}");
9190
}
92-
DefKind::Closure | DefKind::AssocFn | DefKind::Fn => ItemKind::Fn,
91+
DefKind::Ctor(_, _) | DefKind::Closure | DefKind::AssocFn | DefKind::Fn => ItemKind::Fn,
9392
DefKind::Const | DefKind::InlineConst | DefKind::AssocConst | DefKind::AnonConst => {
9493
ItemKind::Const
9594
}

compiler/stable_mir/src/compiler_interface.rs

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

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

compiler/stable_mir/src/mir/mono.rs

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

3636
impl Instance {
37+
/// Get the arguments this instance was instantiated with.
38+
pub fn args(&self) -> GenericArgs {
39+
with(|cx| cx.instance_args(self.def))
40+
}
41+
3742
/// Get the body of an Instance. The body will be eagerly monomorphized.
3843
pub fn body(&self) -> Option<Body> {
3944
with(|context| context.instance_body(self.def))
@@ -142,6 +147,7 @@ impl Debug for Instance {
142147
f.debug_struct("Instance")
143148
.field("kind", &self.kind)
144149
.field("def", &self.mangled_name())
150+
.field("args", &self.args())
145151
.finish()
146152
}
147153
}

0 commit comments

Comments
 (0)