Skip to content

Commit

Permalink
more replace FxHashMap with FxIndexMap
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Feb 12, 2024
1 parent 5f16827 commit 2d054d0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
6 changes: 1 addition & 5 deletions compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) {

// Gate identifiers containing invalid Unicode codepoints that were recovered during lexing.
sess.parse_sess.bad_unicode_identifiers.with_lock(|identifiers| {
// We will soon sort, so the initial order does not matter.
#[allow(rustc::potential_query_instability)]
let mut identifiers: Vec<_> = identifiers.drain().collect();
identifiers.sort_by_key(|&(key, _)| key);
let identifiers: Vec<_> = identifiers.drain(..).collect();
for (ident, mut spans) in identifiers.into_iter() {
spans.sort();
if ident == sym::ferris {
Expand Down Expand Up @@ -435,7 +432,6 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P

// The entries will be used to declare dependencies beween files in a
// Makefile-like output, so the iteration order does not matter.
#[allow(rustc::potential_query_instability)]
let extra_tracked_files =
file_depinfo.iter().map(|path_sym| normalize_path(PathBuf::from(path_sym.as_str())));
files.extend(extra_tracked_files);
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,6 @@ impl LintStore {
// Note: find_best_match_for_name depends on the sort order of its input vector.
// To ensure deterministic output, sort elements of the lint_groups hash map.
// Also, never suggest deprecated lint groups.
// We will soon sort, so the initial order does not matter.
#[allow(rustc::potential_query_instability)]
let mut groups: Vec<_> = self
.lint_groups
.iter()
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_lint/src/non_ascii_idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,8 @@ impl EarlyLintPass for NonAsciiIdents {

// Sort by `Span` so that error messages make sense with respect to the
// order of identifier locations in the code.
// We will soon sort, so the initial order does not matter.
#[allow(rustc::potential_query_instability)]
let mut symbols: Vec<_> = symbols.iter().collect();
symbols.sort_by_key(|k| k.1);

for (symbol, &sp) in symbols.iter() {
let symbol_str = symbol.as_str();
if symbol_str.is_ascii() {
Expand Down Expand Up @@ -300,8 +297,6 @@ impl EarlyLintPass for NonAsciiIdents {
}

if has_suspicious {
// The end result is put in `lint_reports` which is sorted.
#[allow(rustc::potential_query_instability)]
let verified_augmented_script_sets = script_states
.iter()
.flat_map(|(k, v)| match v {
Expand All @@ -314,8 +309,6 @@ impl EarlyLintPass for NonAsciiIdents {
let mut lint_reports: BTreeMap<(Span, Vec<char>), AugmentedScriptSet> =
BTreeMap::new();

// The end result is put in `lint_reports` which is sorted.
#[allow(rustc::potential_query_instability)]
'outerloop: for (augment_script_set, usage) in script_states {
let ScriptSetUsage::Suspicious(mut ch_list, sp) = usage else { continue };

Expand Down
23 changes: 10 additions & 13 deletions compiler/rustc_session/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::lint::{
};
use crate::Session;
use rustc_ast::node_id::NodeId;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_data_structures::sync::{AppendOnlyVec, Lock, Lrc};
use rustc_errors::{emitter::SilentEmitter, DiagCtxt};
use rustc_errors::{
Expand All @@ -30,7 +30,7 @@ use std::str;
/// used and should be feature gated accordingly in `check_crate`.
#[derive(Default)]
pub struct GatedSpans {
pub spans: Lock<FxHashMap<Symbol, Vec<Span>>>,
pub spans: Lock<FxIndexMap<Symbol, Vec<Span>>>,
}

impl GatedSpans {
Expand All @@ -50,12 +50,9 @@ impl GatedSpans {
}

/// Prepend the given set of `spans` onto the set in `self`.
pub fn merge(&self, mut spans: FxHashMap<Symbol, Vec<Span>>) {
pub fn merge(&self, mut spans: FxIndexMap<Symbol, Vec<Span>>) {
let mut inner = self.spans.borrow_mut();
// The entries will be moved to another map so the drain order does not
// matter.
#[allow(rustc::potential_query_instability)]
for (gate, mut gate_spans) in inner.drain() {
for (gate, mut gate_spans) in inner.drain(..) {
spans.entry(gate).or_default().append(&mut gate_spans);
}
*inner = spans;
Expand All @@ -65,7 +62,7 @@ impl GatedSpans {
#[derive(Default)]
pub struct SymbolGallery {
/// All symbols occurred and their first occurrence span.
pub symbols: Lock<FxHashMap<Symbol, Span>>,
pub symbols: Lock<FxIndexMap<Symbol, Span>>,
}

impl SymbolGallery {
Expand Down Expand Up @@ -205,19 +202,19 @@ pub struct ParseSess {
/// Places where identifiers that contain invalid Unicode codepoints but that look like they
/// should be. Useful to avoid bad tokenization when encountering emoji. We group them to
/// provide a single error per unique incorrect identifier.
pub bad_unicode_identifiers: Lock<FxHashMap<Symbol, Vec<Span>>>,
pub bad_unicode_identifiers: Lock<FxIndexMap<Symbol, Vec<Span>>>,
source_map: Lrc<SourceMap>,
pub buffered_lints: Lock<Vec<BufferedEarlyLint>>,
/// Contains the spans of block expressions that could have been incomplete based on the
/// operation token that followed it, but that the parser cannot identify without further
/// analysis.
pub ambiguous_block_expr_parse: Lock<FxHashMap<Span, Span>>,
pub ambiguous_block_expr_parse: Lock<FxIndexMap<Span, Span>>,
pub gated_spans: GatedSpans,
pub symbol_gallery: SymbolGallery,
/// Environment variables accessed during the build and their values when they exist.
pub env_depinfo: Lock<FxHashSet<(Symbol, Option<Symbol>)>>,
pub env_depinfo: Lock<FxIndexSet<(Symbol, Option<Symbol>)>>,
/// File paths accessed during the build.
pub file_depinfo: Lock<FxHashSet<Symbol>>,
pub file_depinfo: Lock<FxIndexSet<Symbol>>,
/// Whether cfg(version) should treat the current release as incomplete
pub assume_incomplete_release: bool,
/// Spans passed to `proc_macro::quote_span`. Each span has a numerical
Expand Down Expand Up @@ -247,7 +244,7 @@ impl ParseSess {
bad_unicode_identifiers: Lock::new(Default::default()),
source_map,
buffered_lints: Lock::new(vec![]),
ambiguous_block_expr_parse: Lock::new(FxHashMap::default()),
ambiguous_block_expr_parse: Lock::new(Default::default()),
gated_spans: GatedSpans::default(),
symbol_gallery: SymbolGallery::default(),
env_depinfo: Default::default(),
Expand Down

0 comments on commit 2d054d0

Please sign in to comment.