-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
I try to get stable MIR for a project built by cargo
. As the project is large(8k+ lines codes), I try to get the body of each function. But it fails to covert datas from Table
.
The code called mir_body
:
for item in stable_mir::all_local_items() {
if item.kind() == ItemKind::Fn {
println!("{item:?}");
if item.trimmed_name() == "Convert::convert_address_of" {
println!("{:?}", item.body());
}
}
}
The output:
...
CrateItem(DefId { id: 449, name: "solvers::smt::smt_conv::Convert::convert_symbol" })
CrateItem(DefId { id: 450, name: "solvers::smt::smt_conv::Convert::convert_address_of" })
thread 'rustc' panicked at compiler/rustc_smir/src/rustc_smir/alloc.rs:30:10:
Failed to convert: Scalar(0x0000000000000000) to std::option::Option<&'{erased} Ast/#2>: Error("TooGeneric(Alias(Projection, AliasTy { args: [Ast/#2], def_id: DefId(2:2374 ~ core[9e5e]::ptr::metadata::Pointee::Metadata), .. }))")
stack backtrace:
0: rust_begin_unwind
1: core::panicking::panic_fmt
2: core::result::unwrap_failed
3: rustc_smir::rustc_smir::alloc::new_allocation
4: <rustc_middle::mir::consts::Const as rustc_smir::rustc_smir::Stable>::stable
5: <rustc_middle::mir::syntax::Operand as rustc_smir::rustc_smir::Stable>::stable
6: <rustc_middle::mir::syntax::TerminatorKind as rustc_smir::rustc_smir::Stable>::stable
7: <rustc_middle::mir::terminator::Terminator as rustc_smir::rustc_smir::Stable>::stable
8: <rustc_middle::mir::Body as rustc_smir::rustc_smir::Stable>::stable
9: <rustc_smir::rustc_smir::context::TablesWrapper as stable_mir::compiler_interface::Context>::mir_body
10: <stable_mir::CrateItem>::body
11: mirv::config::config::Config::new
12: <mirv::main::StableMir<B,C,F> as rustc_driver_impl::Callbacks>::after_analysis
13: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
14: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
Then, I follow the code of rustc_smir
. I found that the definition of Table
is
pub struct Tables<'tcx> {
...,
pub(crate) def_ids: IndexMap<DefId, stable_mir::DefId>,
...
}
However, the function of mir_body
is
fn mir_body(&self, item: stable_mir::DefId) -> stable_mir::mir::Body {
let mut tables = self.0.borrow_mut();
let def_id = tables[item];
tables.tcx.instance_mir(rustc_middle::ty::InstanceKind::Item(def_id)).stable(&mut tables)
}
table[item]
will enventually call self.def_ids[item]
. Then, the index of table[item]
is stable_mir::DefId
while the key of def_ids
has type DefId
. Is there a bug?
Metadata
Metadata
Assignees
Labels
No labels