Skip to content

Commit 1d844fe

Browse files
committed
safe transmute: use FxIndex{Map,Set} instead of FxHash{Map,Set}
resolves query instability issues, and probably better for performance
1 parent f46fffc commit 1d844fe

File tree

4 files changed

+2
-14
lines changed

4 files changed

+2
-14
lines changed

compiler/rustc_transmute/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77

88
[dependencies]
99
tracing = "0.1"
10-
rustc_data_structures = { path = "../rustc_data_structures", optional = true}
10+
rustc_data_structures = { path = "../rustc_data_structures"}
1111
rustc_hir = { path = "../rustc_hir", optional = true}
1212
rustc_infer = { path = "../rustc_infer", optional = true}
1313
rustc_macros = { path = "../rustc_macros", optional = true}
@@ -18,7 +18,6 @@ rustc_target = { path = "../rustc_target", optional = true}
1818
[features]
1919
rustc = [
2020
"rustc_middle",
21-
"rustc_data_structures",
2221
"rustc_hir",
2322
"rustc_infer",
2423
"rustc_macros",

compiler/rustc_transmute/src/layout/dfa.rs

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ where
104104
}
105105

106106
#[instrument(level = "debug")]
107-
#[cfg_attr(feature = "rustc", allow(rustc::potential_query_instability))]
108107
pub(crate) fn from_nfa(nfa: Nfa<R>) -> Self {
109108
let Nfa { transitions: nfa_transitions, start: nfa_start, accepting: nfa_accepting } = nfa;
110109

compiler/rustc_transmute/src/layout/nfa.rs

-6
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ where
119119

120120
let mut transitions: Map<State, Map<Transition<R>, Set<State>>> = self.transitions;
121121

122-
// the iteration order doesn't matter
123-
#[cfg_attr(feature = "rustc", allow(rustc::potential_query_instability))]
124122
for (source, transition) in other.transitions {
125123
let fix_state = |state| if state == other.start { self.accepting } else { state };
126124
let entry = transitions.entry(fix_state(source)).or_default();
@@ -142,8 +140,6 @@ where
142140

143141
let mut transitions: Map<State, Map<Transition<R>, Set<State>>> = self.transitions.clone();
144142

145-
// the iteration order doesn't matter
146-
#[cfg_attr(feature = "rustc", allow(rustc::potential_query_instability))]
147143
for (&(mut source), transition) in other.transitions.iter() {
148144
// if source is starting state of `other`, replace with starting state of `self`
149145
if source == other.start {
@@ -152,8 +148,6 @@ where
152148
let entry = transitions.entry(source).or_default();
153149
for (edge, destinations) in transition {
154150
let entry = entry.entry(edge.clone()).or_default();
155-
// the iteration order doesn't matter
156-
#[cfg_attr(feature = "rustc", allow(rustc::potential_query_instability))]
157151
for &(mut destination) in destinations {
158152
// if dest is accepting state of `other`, replace with accepting state of `self`
159153
if destination == other.accepting {

compiler/rustc_transmute/src/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
#[macro_use]
1414
extern crate tracing;
1515

16-
#[cfg(feature = "rustc")]
17-
pub(crate) use rustc_data_structures::fx::{FxHashMap as Map, FxHashSet as Set};
18-
19-
#[cfg(not(feature = "rustc"))]
20-
pub(crate) use std::collections::{HashMap as Map, HashSet as Set};
16+
pub(crate) use rustc_data_structures::fx::{FxIndexMap as Map, FxIndexSet as Set};
2117

2218
pub(crate) mod layout;
2319
pub(crate) mod maybe_transmutable;

0 commit comments

Comments
 (0)