Skip to content

TyKind in GlobalAllocs #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ pub enum AllocInfo {
Memory(stable_mir::ty::Allocation), // TODO include stable_mir::ty::TyKind?
}
type LinkMap<'tcx> = HashMap<LinkMapKey<'tcx>, (ItemSource, FnSymType)>;
type AllocMap = HashMap<stable_mir::mir::alloc::AllocId, AllocInfo>;
type AllocMap = HashMap<stable_mir::mir::alloc::AllocId, (TyKind, AllocInfo)>;
type TyMap =
HashMap<stable_mir::ty::Ty, (stable_mir::ty::TyKind, Option<stable_mir::abi::LayoutShape>)>;
type SpanMap = HashMap<usize, (String, usize, usize, usize, usize)>;
Expand Down Expand Up @@ -656,14 +656,14 @@ fn collect_alloc(
let global_alloc = GlobalAlloc::from(val);
match global_alloc {
GlobalAlloc::Memory(ref alloc) => {
let pointed_kind = get_prov_type(kind);
let pointed_kind = get_prov_type(kind.clone());
if debug_enabled() {
println!(
"DEBUG: called collect_alloc: {:?}:{:?}:{:?}",
val, pointed_kind, global_alloc
);
}
entry.or_insert(AllocInfo::Memory(alloc.clone())); // TODO: include pointed_kind.clone().unwrap() ?
entry.or_insert((kind.unwrap(), AllocInfo::Memory(alloc.clone()))); // TODO: include pointed_kind.clone().unwrap() ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
entry.or_insert((kind.unwrap(), AllocInfo::Memory(alloc.clone()))); // TODO: include pointed_kind.clone().unwrap() ?
entry.or_insert((kind.unwrap(), AllocInfo::Memory(alloc.clone())));

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree! Amending now!

alloc.provenance.ptrs.iter().for_each(|(_, prov)| {
collect_alloc(val_collector, pointed_kind.clone(), prov.0);
});
Expand All @@ -674,19 +674,19 @@ fn collect_alloc(
"Allocated pointer is not a built-in pointer type: {:?}",
kind
);
entry.or_insert(AllocInfo::Static(def));
entry.or_insert((kind.unwrap(), AllocInfo::Static(def)));
}
GlobalAlloc::VTable(ty, traitref) => {
assert!(
kind.clone().unwrap().builtin_deref(true).is_some(),
"Allocated pointer is not a built-in pointer type: {:?}",
kind
);
entry.or_insert(AllocInfo::VTable(ty, traitref));
entry.or_insert((kind.unwrap(), AllocInfo::VTable(ty, traitref)));
}
GlobalAlloc::Function(inst) => {
assert!(kind.unwrap().is_fn_ptr());
entry.or_insert(AllocInfo::Function(inst));
assert!(kind.as_ref().unwrap().is_fn_ptr());
entry.or_insert((kind.unwrap(), AllocInfo::Function(inst)));
}
};
}
Expand Down Expand Up @@ -1082,7 +1082,7 @@ type SourceData = (String, usize, usize, usize, usize);
pub struct SmirJson<'t> {
pub name: String,
pub crate_id: u64,
pub allocs: Vec<(AllocId, AllocInfo)>,
pub allocs: Vec<(AllocId, (TyKind, AllocInfo))>,
pub functions: Vec<(LinkMapKey<'t>, FnSymType)>,
pub uneval_consts: Vec<(ConstDef, String)>,
pub items: Vec<Item>,
Expand Down Expand Up @@ -1112,7 +1112,7 @@ pub fn collect_smir(tcx: TyCtxt<'_>) -> SmirJson {

// FIXME: We dump extra static items here --- this should be handled better
for (_, alloc) in visited_allocs.iter() {
if let AllocInfo::Static(def) = alloc {
if let (_, AllocInfo::Static(def)) = alloc {
let mono_item =
stable_mir::mir::mono::MonoItem::Fn(stable_mir::mir::mono::Instance::from(*def));
let item_name = &mono_item_name(tcx, &mono_item);
Expand Down
Loading
Loading