Skip to content

Commit 19423b7

Browse files
committed
Simplify DepNodeColorMap::try_mark_green.
It uses a different implementation depending on whether the compiler front-end is running single-threaded or multi-threaded. The two implementations are equivalent and I think the multi-threaded one expresses the intent more clearly, and I imagine the perf is similar. So this commit removes the single-threaded code.
1 parent ed6a137 commit 19423b7

File tree

1 file changed

+11
-24
lines changed
  • compiler/rustc_query_system/src/dep_graph

1 file changed

+11
-24
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_data_structures::outline;
1111
use rustc_data_structures::profiling::QueryInvocationId;
1212
use rustc_data_structures::sharded::{self, ShardedHashMap};
1313
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
14-
use rustc_data_structures::sync::{AtomicU64, Lock, is_dyn_thread_safe};
14+
use rustc_data_structures::sync::{AtomicU64, Lock};
1515
use rustc_data_structures::unord::UnordMap;
1616
use rustc_errors::DiagInner;
1717
use rustc_index::IndexVec;
@@ -1308,11 +1308,11 @@ impl Default for TaskDeps {
13081308
}
13091309
}
13101310
}
1311+
13111312
// A data structure that stores Option<DepNodeColor> values as a contiguous
13121313
// array, using one u32 per entry.
13131314
pub(super) struct DepNodeColorMap {
13141315
values: IndexVec<SerializedDepNodeIndex, AtomicU32>,
1315-
sync: bool,
13161316
}
13171317

13181318
// All values below `COMPRESSED_RED` are green.
@@ -1322,10 +1322,7 @@ const COMPRESSED_UNKNOWN: u32 = u32::MAX;
13221322
impl DepNodeColorMap {
13231323
fn new(size: usize) -> DepNodeColorMap {
13241324
debug_assert!(COMPRESSED_RED > DepNodeIndex::MAX_AS_U32);
1325-
DepNodeColorMap {
1326-
values: (0..size).map(|_| AtomicU32::new(COMPRESSED_UNKNOWN)).collect(),
1327-
sync: is_dyn_thread_safe(),
1328-
}
1325+
DepNodeColorMap { values: (0..size).map(|_| AtomicU32::new(COMPRESSED_UNKNOWN)).collect() }
13291326
}
13301327

13311328
#[inline]
@@ -1344,24 +1341,14 @@ impl DepNodeColorMap {
13441341
index: DepNodeIndex,
13451342
) -> Result<(), DepNodeIndex> {
13461343
let value = &self.values[prev_index];
1347-
if self.sync {
1348-
match value.compare_exchange(
1349-
COMPRESSED_UNKNOWN,
1350-
index.as_u32(),
1351-
Ordering::Relaxed,
1352-
Ordering::Relaxed,
1353-
) {
1354-
Ok(_) => Ok(()),
1355-
Err(v) => Err(DepNodeIndex::from_u32(v)),
1356-
}
1357-
} else {
1358-
let v = value.load(Ordering::Relaxed);
1359-
if v == COMPRESSED_UNKNOWN {
1360-
value.store(index.as_u32(), Ordering::Relaxed);
1361-
Ok(())
1362-
} else {
1363-
Err(DepNodeIndex::from_u32(v))
1364-
}
1344+
match value.compare_exchange(
1345+
COMPRESSED_UNKNOWN,
1346+
index.as_u32(),
1347+
Ordering::Relaxed,
1348+
Ordering::Relaxed,
1349+
) {
1350+
Ok(_) => Ok(()),
1351+
Err(v) => Err(DepNodeIndex::from_u32(v)),
13651352
}
13661353
}
13671354

0 commit comments

Comments
 (0)