Skip to content

Commit a315aef

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 eaa31b4 commit a315aef

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
// The values here are chosen to optimize `DepNodeColorMap::get`. All values below
@@ -1323,10 +1323,7 @@ const COMPRESSED_RED: u32 = u32::MAX;
13231323
impl DepNodeColorMap {
13241324
fn new(size: usize) -> DepNodeColorMap {
13251325
debug_assert!(COMPRESSED_RED > DepNodeIndex::MAX_AS_U32);
1326-
DepNodeColorMap {
1327-
values: (0..size).map(|_| AtomicU32::new(COMPRESSED_UNKNOWN)).collect(),
1328-
sync: is_dyn_thread_safe(),
1329-
}
1326+
DepNodeColorMap { values: (0..size).map(|_| AtomicU32::new(COMPRESSED_UNKNOWN)).collect() }
13301327
}
13311328

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

0 commit comments

Comments
 (0)