Skip to content

Commit 027251f

Browse files
committed
Use a session counter to make anon dep nodes unique
1 parent 70dab5a commit 027251f

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

Diff for: compiler/rustc_query_system/src/dep_graph/graph.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,7 @@ pub(super) struct CurrentDepGraph<D: Deps> {
11671167
/// ID from the previous session. In order to side-step this problem, we make
11681168
/// sure that anonymous `NodeId`s allocated in different sessions don't overlap.
11691169
/// This is implemented by mixing a session-key into the ID fingerprint of
1170-
/// each anon node. The session-key is just a random number generated when
1171-
/// the `DepGraph` is created.
1170+
/// each anon node. The session-key is a hash of the number of previous sessions.
11721171
anon_id_seed: Fingerprint,
11731172

11741173
/// These are simple counters that are for profiling and
@@ -1186,12 +1185,8 @@ impl<D: Deps> CurrentDepGraph<D> {
11861185
record_stats: bool,
11871186
previous: Arc<SerializedDepGraph>,
11881187
) -> Self {
1189-
use std::time::{SystemTime, UNIX_EPOCH};
1190-
1191-
let duration = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
1192-
let nanos = duration.as_nanos();
11931188
let mut stable_hasher = StableHasher::new();
1194-
nanos.hash(&mut stable_hasher);
1189+
previous.session_count().hash(&mut stable_hasher);
11951190
let anon_id_seed = stable_hasher.finish();
11961191

11971192
#[cfg(debug_assertions)]

Diff for: compiler/rustc_query_system/src/dep_graph/serialized.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ pub struct SerializedDepGraph {
9292
/// Stores a map from fingerprints to nodes per dep node kind.
9393
/// This is the reciprocal of `nodes`.
9494
index: Vec<UnhashMap<PackedFingerprint, SerializedDepNodeIndex>>,
95+
/// The number of previous compilation sessions. This is used to generate
96+
/// unique anon dep nodes per session.
97+
session_count: u64,
9598
}
9699

97100
impl SerializedDepGraph {
@@ -146,6 +149,11 @@ impl SerializedDepGraph {
146149
pub fn node_count(&self) -> usize {
147150
self.nodes.len()
148151
}
152+
153+
#[inline]
154+
pub fn session_count(&self) -> u64 {
155+
self.session_count
156+
}
149157
}
150158

151159
/// A packed representation of an edge's start index and byte width.
@@ -252,6 +260,8 @@ impl SerializedDepGraph {
252260
.map(|_| UnhashMap::with_capacity_and_hasher(d.read_u32() as usize, Default::default()))
253261
.collect();
254262

263+
let session_count = d.read_u64();
264+
255265
for (idx, node) in nodes.iter_enumerated() {
256266
if index[node.kind.as_usize()].insert(node.hash, idx).is_some() {
257267
// Side effect nodes can have duplicates
@@ -273,6 +283,7 @@ impl SerializedDepGraph {
273283
edge_list_indices,
274284
edge_list_data,
275285
index,
286+
session_count,
276287
})
277288
}
278289
}
@@ -601,7 +612,7 @@ impl<D: Deps> EncoderState<D> {
601612
stats: _,
602613
kind_stats,
603614
marker: _,
604-
previous: _,
615+
previous,
605616
} = self;
606617

607618
let node_count = total_node_count.try_into().unwrap();
@@ -612,6 +623,8 @@ impl<D: Deps> EncoderState<D> {
612623
count.encode(&mut encoder);
613624
}
614625

626+
previous.session_count.checked_add(1).unwrap().encode(&mut encoder);
627+
615628
debug!(?node_count, ?edge_count);
616629
debug!("position: {:?}", encoder.position());
617630
IntEncodedWithFixedSize(node_count).encode(&mut encoder);

0 commit comments

Comments
 (0)