Skip to content

Commit 8529b63

Browse files
committed
coverage: Avoid a possible query stability hazard in CoverageCounters
The iteration order of this hashmap can potentially affect the relative creation order of MIR blocks.
1 parent fb5ed72 commit 8529b63

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)