Skip to content

Commit 4b9a76c

Browse files
authored
Rollup merge of #119401 - Zalathar:query-stability, r=Nilstrieb
coverage: Avoid a possible query stability hazard in `CoverageCounters` #119252 revealed a possible query stability hazard in `CoverageCounters`: we iterate over the entries of an `FxHashMap` in a way that allows the iteration order to potentially affect the relative creation order of MIR blocks. I'm not sure whether there's an actual stability problem or not in practice, but it's certainly a hazard, and I don't see any reason not to switch over to `FxIndexMap` to avoid potential issues. --- This can either be merged on its own, or incorporated into #119252. cc `@Enselic` r? `@cjgillot`
2 parents 12ad777 + 8529b63 commit 4b9a76c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler/rustc_mir_transform/src/coverage/counters.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_data_structures::fx::FxHashMap;
1+
use rustc_data_structures::fx::FxIndexMap;
22
use rustc_data_structures::graph::WithNumNodes;
33
use rustc_index::bit_set::BitSet;
44
use rustc_index::IndexVec;
@@ -47,7 +47,10 @@ pub(super) struct CoverageCounters {
4747
bcb_counters: IndexVec<BasicCoverageBlock, Option<BcbCounter>>,
4848
/// Coverage counters/expressions that are associated with the control-flow
4949
/// edge between two BCBs.
50-
bcb_edge_counters: FxHashMap<(BasicCoverageBlock, BasicCoverageBlock), BcbCounter>,
50+
///
51+
/// The iteration order of this map can affect the precise contents of MIR,
52+
/// so we use `FxIndexMap` to avoid query stability hazards.
53+
bcb_edge_counters: FxIndexMap<(BasicCoverageBlock, BasicCoverageBlock), BcbCounter>,
5154
/// Tracks which BCBs have a counter associated with some incoming edge.
5255
/// Only used by assertions, to verify that BCBs with incoming edge
5356
/// counters do not have their own physical counters (expressions are allowed).
@@ -64,7 +67,7 @@ impl CoverageCounters {
6467
Self {
6568
next_counter_id: CounterId::START,
6669
bcb_counters: IndexVec::from_elem_n(None, num_bcbs),
67-
bcb_edge_counters: FxHashMap::default(),
70+
bcb_edge_counters: FxIndexMap::default(),
6871
bcb_has_incoming_edge_counters: BitSet::new_empty(num_bcbs),
6972
expressions: IndexVec::new(),
7073
}

0 commit comments

Comments
 (0)