Skip to content

Account for gaps in def path table during decoding #79810

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

Merged
merged 1 commit into from
Dec 10, 2020
Merged
Changes from all 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
11 changes: 8 additions & 3 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
return Some(DefId { krate, index: def_index_guess });
}

let is_proc_macro = self.is_proc_macro_crate();

// Slow path: We need to find out the new `DefIndex` of the provided
// `DefPathHash`, if its still exists. This requires decoding every `DefPathHash`
// stored in this crate.
Expand All @@ -1561,9 +1563,12 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
let mut map = FxHashMap::with_capacity_and_hasher(end_id as usize, Default::default());
for i in 0..end_id {
Copy link
Contributor

Choose a reason for hiding this comment

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

Late to the party... but if there are gaps, rather than stopping at end_id, do we need to keep iterating until we've processed self.root.tables.def_path_hashes.size() elements?

(Or maybe something more efficient. I'm not familiar with how these tables work.)

Copy link
Member Author

Choose a reason for hiding this comment

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

The size() method on Lazy<Table> has a somewhat misleading name - it returns the maximum possible value. So, iterating up to end_id guarnatees that we visit all present entries.

let def_index = DefIndex::from_u32(i);
let hash =
self.root.tables.def_path_hashes.get(self, def_index).unwrap().decode(self);
map.insert(hash, def_index);
// There may be gaps in the encoded table if we're decoding a proc-macro crate
if let Some(hash) = self.root.tables.def_path_hashes.get(self, def_index) {
map.insert(hash.decode(self), def_index);
} else if !is_proc_macro {
panic!("Missing def_path_hashes entry for {:?}", def_index);
}
}
map
});
Expand Down