Skip to content
Draft
Show file tree
Hide file tree
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
17 changes: 14 additions & 3 deletions compiler/rustc_hir_id/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use std::fmt::{self, Write};
use std::hash::Hash;
use std::sync::OnceLock;

use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sorted_map::SortedMap;
Expand Down Expand Up @@ -95,6 +96,7 @@ pub struct Definitions {
def_id_to_key: IndexVec<LocalDefId, DefKey>,
// We do only store the local hash, as all the definitions are from the current crate.
def_path_hashes: IndexVec<LocalDefId, Hash64>,
last_deterministic_index: OnceLock<DefIndex>,
def_path_hash_to_index: DefPathToIndexMap,
}

Expand Down Expand Up @@ -292,13 +294,21 @@ pub enum DefPathData {
}

impl Definitions {
/// This function indicates that the order of def id allocations
/// may be non-deterministic after it was called.
pub fn commit_end_of_determinism(&mut self) {
assert!(
self.def_path_hash_to_index.after_parallel_alloc.replace(Default::default()).is_none(),
"this function should be called only once"
)
);

self.last_deterministic_index
.set(
if self.def_id_to_key.is_empty() { 0 } else { self.def_id_to_key.len() - 1 }.into(),

@oli-obk oli-obk Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

will this ever be empty? shouldn't the first entry always be the crate root?

View changes since the review

)
.expect("must be called once");
}

pub fn last_deterministic_index(&self) -> DefIndex {
self.last_deterministic_index.get().copied().expect("must contain index")
}

#[inline(always)]
Expand Down Expand Up @@ -352,6 +362,7 @@ impl Definitions {
def_path_hashes: Default::default(),
def_id_to_key: Default::default(),
def_path_hash_to_index: Default::default(),
last_deterministic_index: Default::default(),
};

// Create the root definition.
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,9 @@ impl CrateMetadata {

fn get_proc_macro_quoted_span(&self, tcx: TyCtxt<'_>, index: usize) -> Span {
self.root
.tables
.proc_macro_data
.as_ref()
.unwrap()
.proc_macro_quoted_spans
.get(self, index)
.unwrap_or_else(|| panic!("Missing proc macro quoted span: {index:?}"))
Expand Down Expand Up @@ -1965,8 +1967,12 @@ impl CrateMetadata {
let trait_impls = root
.impls
.decode(&blob)
.map(|trait_impls| (trait_impls.trait_id, trait_impls.impls))
.map(|trait_impls| {
let (krate, index) = trait_impls.trait_id;
((krate, DefIndex::from_u32(index)), trait_impls.impls)
})
.collect();

let alloc_decoding_state =
AllocDecodingState::new(root.interpret_alloc_index.decode(&blob).collect());

Expand Down
Loading
Loading