Skip to content

Commit 62fc1e7

Browse files
Make iteration order of shallow_lint_levels_on query stable
1 parent 45c93e3 commit 62fc1e7

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
55
};
66
use rustc_data_structures::fx::FxHashMap;
7+
use rustc_data_structures::unord::UnordMap;
78
use rustc_error_messages::fluent_value_from_str_list_sep_by_and;
89
use rustc_error_messages::FluentValue;
910
use rustc_lint_defs::{Applicability, LintExpectationId};
@@ -280,7 +281,7 @@ impl Diagnostic {
280281

281282
pub(crate) fn update_unstable_expectation_id(
282283
&mut self,
283-
unstable_to_stable: &FxHashMap<LintExpectationId, LintExpectationId>,
284+
unstable_to_stable: &UnordMap<LintExpectationId, LintExpectationId>,
284285
) {
285286
if let Level::Expect(expectation_id) | Level::Warning(Some(expectation_id)) =
286287
&mut self.level

compiler/rustc_errors/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ extern crate self as rustc_errors;
2828

2929
pub use emitter::ColorConfig;
3030

31+
use rustc_data_structures::unord::UnordMap;
3132
use rustc_lint_defs::LintExpectationId;
3233
use Level::*;
3334

3435
use emitter::{is_case_difference, DynEmitter, Emitter, EmitterWriter};
3536
use registry::Registry;
36-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
37+
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
3738
use rustc_data_structures::stable_hasher::{Hash128, StableHasher};
3839
use rustc_data_structures::sync::{Lock, Lrc};
3940
use rustc_data_structures::AtomicRef;
@@ -1367,7 +1368,7 @@ impl DiagCtxt {
13671368

13681369
pub fn update_unstable_expectation_id(
13691370
&self,
1370-
unstable_to_stable: &FxHashMap<LintExpectationId, LintExpectationId>,
1371+
unstable_to_stable: &UnordMap<LintExpectationId, LintExpectationId>,
13711372
) {
13721373
let mut inner = self.inner.borrow_mut();
13731374
let diags = std::mem::take(&mut inner.unstable_expect_diagnostics);

compiler/rustc_lint/src/levels.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
};
1616
use rustc_ast as ast;
1717
use rustc_ast_pretty::pprust;
18-
use rustc_data_structures::fx::FxHashMap;
18+
use rustc_data_structures::unord::UnordMap;
1919
use rustc_errors::{DecorateLint, DiagnosticBuilder, DiagnosticMessage, MultiSpan};
2020
use rustc_feature::{Features, GateIssue};
2121
use rustc_hir as hir;
@@ -73,7 +73,7 @@ rustc_index::newtype_index! {
7373
struct LintSet {
7474
// -A,-W,-D flags, a `Symbol` for the flag itself and `Level` for which
7575
// flag.
76-
specs: FxHashMap<LintId, LevelAndSource>,
76+
specs: UnordMap<LintId, LevelAndSource>,
7777
parent: LintStackIndex,
7878
}
7979

@@ -86,7 +86,7 @@ impl LintLevelSets {
8686
&self,
8787
lint: &'static Lint,
8888
idx: LintStackIndex,
89-
aux: Option<&FxHashMap<LintId, LevelAndSource>>,
89+
aux: Option<&UnordMap<LintId, LevelAndSource>>,
9090
sess: &Session,
9191
) -> LevelAndSource {
9292
let lint = LintId::of(lint);
@@ -101,7 +101,7 @@ impl LintLevelSets {
101101
&self,
102102
id: LintId,
103103
mut idx: LintStackIndex,
104-
aux: Option<&FxHashMap<LintId, LevelAndSource>>,
104+
aux: Option<&UnordMap<LintId, LevelAndSource>>,
105105
) -> (Option<Level>, LintLevelSource) {
106106
if let Some(specs) = aux {
107107
if let Some(&(level, src)) = specs.get(&id) {
@@ -132,8 +132,8 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
132132
cur: hir::CRATE_HIR_ID,
133133
specs: ShallowLintLevelMap::default(),
134134
expectations: Vec::new(),
135-
unstable_to_stable_ids: FxHashMap::default(),
136-
empty: FxHashMap::default(),
135+
unstable_to_stable_ids: Default::default(),
136+
empty: Default::default(),
137137
},
138138
warn_about_weird_lints: false,
139139
store,
@@ -161,7 +161,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe
161161
tcx,
162162
cur: owner.into(),
163163
specs: ShallowLintLevelMap::default(),
164-
empty: FxHashMap::default(),
164+
empty: Default::default(),
165165
attrs,
166166
},
167167
warn_about_weird_lints: false,
@@ -209,14 +209,14 @@ pub struct TopDown {
209209
}
210210

211211
pub trait LintLevelsProvider {
212-
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource>;
212+
fn current_specs(&self) -> &UnordMap<LintId, LevelAndSource>;
213213
fn insert(&mut self, id: LintId, lvl: LevelAndSource);
214214
fn get_lint_level(&self, lint: &'static Lint, sess: &Session) -> LevelAndSource;
215215
fn push_expectation(&mut self, _id: LintExpectationId, _expectation: LintExpectation) {}
216216
}
217217

218218
impl LintLevelsProvider for TopDown {
219-
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
219+
fn current_specs(&self) -> &UnordMap<LintId, LevelAndSource> {
220220
&self.sets.list[self.cur].specs
221221
}
222222

@@ -234,12 +234,12 @@ struct LintLevelQueryMap<'tcx> {
234234
cur: HirId,
235235
specs: ShallowLintLevelMap,
236236
/// Empty hash map to simplify code.
237-
empty: FxHashMap<LintId, LevelAndSource>,
237+
empty: UnordMap<LintId, LevelAndSource>,
238238
attrs: &'tcx hir::AttributeMap<'tcx>,
239239
}
240240

241241
impl LintLevelsProvider for LintLevelQueryMap<'_> {
242-
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
242+
fn current_specs(&self) -> &UnordMap<LintId, LevelAndSource> {
243243
self.specs.specs.get(&self.cur.local_id).unwrap_or(&self.empty)
244244
}
245245
fn insert(&mut self, id: LintId, lvl: LevelAndSource) {
@@ -257,13 +257,13 @@ struct QueryMapExpectationsWrapper<'tcx> {
257257
/// Level map for `cur`.
258258
specs: ShallowLintLevelMap,
259259
expectations: Vec<(LintExpectationId, LintExpectation)>,
260-
unstable_to_stable_ids: FxHashMap<LintExpectationId, LintExpectationId>,
260+
unstable_to_stable_ids: UnordMap<LintExpectationId, LintExpectationId>,
261261
/// Empty hash map to simplify code.
262-
empty: FxHashMap<LintId, LevelAndSource>,
262+
empty: UnordMap<LintId, LevelAndSource>,
263263
}
264264

265265
impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> {
266-
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
266+
fn current_specs(&self) -> &UnordMap<LintId, LevelAndSource> {
267267
self.specs.specs.get(&self.cur.local_id).unwrap_or(&self.empty)
268268
}
269269
fn insert(&mut self, id: LintId, lvl: LevelAndSource) {
@@ -486,7 +486,7 @@ impl<'s> LintLevelsBuilder<'s, TopDown> {
486486
.provider
487487
.sets
488488
.list
489-
.push(LintSet { specs: FxHashMap::default(), parent: COMMAND_LINE });
489+
.push(LintSet { specs: Default::default(), parent: COMMAND_LINE });
490490
self.add_command_line();
491491
}
492492

@@ -512,7 +512,7 @@ impl<'s> LintLevelsBuilder<'s, TopDown> {
512512
) -> BuilderPush {
513513
let prev = self.provider.cur;
514514
self.provider.cur =
515-
self.provider.sets.list.push(LintSet { specs: FxHashMap::default(), parent: prev });
515+
self.provider.sets.list.push(LintSet { specs: Default::default(), parent: prev });
516516

517517
self.add(attrs, is_crate_node, source_hir_id);
518518

@@ -547,7 +547,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
547547
self.features
548548
}
549549

550-
fn current_specs(&self) -> &FxHashMap<LintId, LevelAndSource> {
550+
fn current_specs(&self) -> &UnordMap<LintId, LevelAndSource> {
551551
self.provider.current_specs()
552552
}
553553

@@ -1028,7 +1028,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10281028
}
10291029

10301030
if !is_crate_node {
1031-
for (id, &(level, ref src)) in self.current_specs().iter() {
1031+
for (id, &(level, ref src)) in self.current_specs().to_sorted_stable_ord() {
10321032
if !id.lint.crate_level_only {
10331033
continue;
10341034
}

compiler/rustc_middle/src/lint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::cmp;
22

3-
use rustc_data_structures::fx::FxHashMap;
43
use rustc_data_structures::sorted_map::SortedMap;
4+
use rustc_data_structures::unord::UnordMap;
55
use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, MultiSpan};
66
use rustc_hir::{HirId, ItemLocalId};
77
use rustc_session::lint::{
@@ -61,7 +61,7 @@ pub type LevelAndSource = (Level, LintLevelSource);
6161
/// by the attributes for *a single HirId*.
6262
#[derive(Default, Debug, HashStable)]
6363
pub struct ShallowLintLevelMap {
64-
pub specs: SortedMap<ItemLocalId, FxHashMap<LintId, LevelAndSource>>,
64+
pub specs: SortedMap<ItemLocalId, UnordMap<LintId, LevelAndSource>>,
6565
}
6666

6767
/// From an initial level and source, verify the effect of special annotations:

0 commit comments

Comments
 (0)