Replace a number of FxHashMaps/Sets with stable-iteration-order alternatives.
This commit is contained in:
parent
739e5ef49e
commit
db132c575d
9 changed files with 40 additions and 33 deletions
|
@ -6,6 +6,7 @@ use crate::errors::{
|
|||
use crate::fluent_generated as fluent;
|
||||
use crate::traits::error_reporting::report_object_safety_error;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_errors::{pluralize, struct_span_err, Applicability, Diagnostic, ErrorGuaranteed};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
|
@ -673,7 +674,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
}))
|
||||
})
|
||||
.flatten()
|
||||
.collect::<FxHashMap<Symbol, &ty::AssocItem>>();
|
||||
.collect::<UnordMap<Symbol, &ty::AssocItem>>();
|
||||
|
||||
let mut names = names
|
||||
.into_iter()
|
||||
|
@ -709,7 +710,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let mut where_constraints = vec![];
|
||||
let mut already_has_generics_args_suggestion = false;
|
||||
for (span, assoc_items) in &associated_types {
|
||||
let mut names: FxHashMap<_, usize> = FxHashMap::default();
|
||||
let mut names: UnordMap<_, usize> = Default::default();
|
||||
for item in assoc_items {
|
||||
types_count += 1;
|
||||
*names.entry(item.name).or_insert(0) += 1;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed, StashKey};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
|
@ -979,7 +980,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
|
|||
})
|
||||
// Check for duplicates
|
||||
.and_then(|list| {
|
||||
let mut set: FxHashMap<Symbol, Span> = FxHashMap::default();
|
||||
let mut set: UnordMap<Symbol, Span> = Default::default();
|
||||
let mut no_dups = true;
|
||||
|
||||
for ident in &*list {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_data_structures::unord::{UnordMap, UnordSet};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_middle::query::Providers;
|
||||
|
@ -72,7 +72,7 @@ struct ClashingExternDeclarations {
|
|||
/// the symbol should be reported as a clashing declaration.
|
||||
// FIXME: Technically, we could just store a &'tcx str here without issue; however, the
|
||||
// `impl_lint_pass` macro doesn't currently support lints parametric over a lifetime.
|
||||
seen_decls: FxHashMap<Symbol, hir::OwnerId>,
|
||||
seen_decls: UnordMap<Symbol, hir::OwnerId>,
|
||||
}
|
||||
|
||||
/// Differentiate between whether the name for an extern decl came from the link_name attribute or
|
||||
|
@ -96,7 +96,7 @@ impl SymbolName {
|
|||
|
||||
impl ClashingExternDeclarations {
|
||||
pub(crate) fn new() -> Self {
|
||||
ClashingExternDeclarations { seen_decls: FxHashMap::default() }
|
||||
ClashingExternDeclarations { seen_decls: Default::default() }
|
||||
}
|
||||
|
||||
/// Insert a new foreign item into the seen set. If a symbol with the same name already exists
|
||||
|
@ -209,12 +209,12 @@ fn structurally_same_type<'tcx>(
|
|||
b: Ty<'tcx>,
|
||||
ckind: types::CItemKind,
|
||||
) -> bool {
|
||||
let mut seen_types = FxHashSet::default();
|
||||
let mut seen_types = UnordSet::default();
|
||||
structurally_same_type_impl(&mut seen_types, tcx, param_env, a, b, ckind)
|
||||
}
|
||||
|
||||
fn structurally_same_type_impl<'tcx>(
|
||||
seen_types: &mut FxHashSet<(Ty<'tcx>, Ty<'tcx>)>,
|
||||
seen_types: &mut UnordSet<(Ty<'tcx>, Ty<'tcx>)>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ty::ParamEnv<'tcx>,
|
||||
a: Ty<'tcx>,
|
||||
|
|
|
@ -4,7 +4,8 @@ use crate::lints::{
|
|||
};
|
||||
use crate::{EarlyContext, EarlyLintPass, LintContext};
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_span::symbol::Symbol;
|
||||
|
||||
declare_lint! {
|
||||
|
@ -194,8 +195,8 @@ impl EarlyLintPass for NonAsciiIdents {
|
|||
}
|
||||
|
||||
if has_non_ascii_idents && check_confusable_idents {
|
||||
let mut skeleton_map: FxHashMap<Symbol, (Symbol, Span, bool)> =
|
||||
FxHashMap::with_capacity_and_hasher(symbols.len(), Default::default());
|
||||
let mut skeleton_map: UnordMap<Symbol, (Symbol, Span, bool)> =
|
||||
UnordMap::with_capacity(symbols.len());
|
||||
let mut skeleton_buf = String::new();
|
||||
|
||||
for (&symbol, &sp) in symbols.iter() {
|
||||
|
@ -248,8 +249,8 @@ impl EarlyLintPass for NonAsciiIdents {
|
|||
Verified,
|
||||
}
|
||||
|
||||
let mut script_states: FxHashMap<AugmentedScriptSet, ScriptSetUsage> =
|
||||
FxHashMap::default();
|
||||
let mut script_states: FxIndexMap<AugmentedScriptSet, ScriptSetUsage> =
|
||||
Default::default();
|
||||
let latin_augmented_script_set = AugmentedScriptSet::for_char('A');
|
||||
script_states.insert(latin_augmented_script_set, ScriptSetUsage::Verified);
|
||||
|
||||
|
|
|
@ -1914,14 +1914,15 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
empty_proc_macro!(self);
|
||||
let tcx = self.tcx;
|
||||
let lib_features = tcx.lib_features(LOCAL_CRATE);
|
||||
self.lazy_array(lib_features.to_vec())
|
||||
self.lazy_array(lib_features.to_sorted_vec())
|
||||
}
|
||||
|
||||
fn encode_stability_implications(&mut self) -> LazyArray<(Symbol, Symbol)> {
|
||||
empty_proc_macro!(self);
|
||||
let tcx = self.tcx;
|
||||
let implications = tcx.stability_implications(LOCAL_CRATE);
|
||||
self.lazy_array(implications.iter().map(|(k, v)| (*k, *v)))
|
||||
let sorted = implications.to_sorted_stable_ord();
|
||||
self.lazy_array(sorted.into_iter().map(|(k, v)| (*k, *v)))
|
||||
}
|
||||
|
||||
fn encode_diagnostic_items(&mut self) -> LazyArray<(Symbol, DefIndex)> {
|
||||
|
|
|
@ -4,7 +4,7 @@ pub mod dependency_format;
|
|||
pub mod exported_symbols;
|
||||
pub mod lang_items;
|
||||
pub mod lib_features {
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_span::{symbol::Symbol, Span};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
|
@ -16,15 +16,16 @@ pub mod lib_features {
|
|||
|
||||
#[derive(HashStable, Debug, Default)]
|
||||
pub struct LibFeatures {
|
||||
pub stability: FxHashMap<Symbol, (FeatureStability, Span)>,
|
||||
pub stability: UnordMap<Symbol, (FeatureStability, Span)>,
|
||||
}
|
||||
|
||||
impl LibFeatures {
|
||||
pub fn to_vec(&self) -> Vec<(Symbol, FeatureStability)> {
|
||||
let mut all_features: Vec<_> =
|
||||
self.stability.iter().map(|(&sym, &(stab, _))| (sym, stab)).collect();
|
||||
all_features.sort_unstable_by(|(a, _), (b, _)| a.as_str().cmp(b.as_str()));
|
||||
all_features
|
||||
pub fn to_sorted_vec(&self) -> Vec<(Symbol, FeatureStability)> {
|
||||
self.stability
|
||||
.to_sorted_stable_ord()
|
||||
.iter()
|
||||
.map(|(&sym, &(stab, _))| (sym, stab))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ use rustc_attr::{
|
|||
self as attr, ConstStability, DefaultBodyStability, DeprecatedSince, Deprecation, Stability,
|
||||
};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_errors::{Applicability, Diagnostic};
|
||||
use rustc_feature::GateIssue;
|
||||
use rustc_hir::def::DefKind;
|
||||
|
@ -77,7 +78,7 @@ pub struct Index {
|
|||
/// to know that the feature implies another feature. If it were reversed, and the `#[stable]`
|
||||
/// attribute had an `implies` meta item, then a map would be necessary when avoiding a "use of
|
||||
/// unstable feature" error for a feature that was implied.
|
||||
pub implications: FxHashMap<Symbol, Symbol>,
|
||||
pub implications: UnordMap<Symbol, Symbol>,
|
||||
}
|
||||
|
||||
impl Index {
|
||||
|
|
|
@ -61,7 +61,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
|
|||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_data_structures::svh::Svh;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_data_structures::unord::UnordSet;
|
||||
use rustc_data_structures::unord::{UnordMap, UnordSet};
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, DocLinkResMap};
|
||||
|
@ -1739,7 +1739,7 @@ rustc_queries! {
|
|||
separate_provide_extern
|
||||
arena_cache
|
||||
}
|
||||
query stability_implications(_: CrateNum) -> &'tcx FxHashMap<Symbol, Symbol> {
|
||||
query stability_implications(_: CrateNum) -> &'tcx UnordMap<Symbol, Symbol> {
|
||||
arena_cache
|
||||
desc { "calculating the implications between `#[unstable]` features defined in a crate" }
|
||||
separate_provide_extern
|
||||
|
|
|
@ -6,7 +6,8 @@ use rustc_attr::{
|
|||
self as attr, ConstStability, DeprecatedSince, Stability, StabilityLevel, StableSince,
|
||||
Unstable, UnstableReason, VERSION_PLACEHOLDER,
|
||||
};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::unord::{ExtendUnord, UnordMap, UnordSet};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{LocalDefId, LocalModDefId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
|
@ -923,7 +924,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
|||
}
|
||||
|
||||
let declared_lang_features = &tcx.features().declared_lang_features;
|
||||
let mut lang_features = FxHashSet::default();
|
||||
let mut lang_features = UnordSet::default();
|
||||
for &(feature, span, since) in declared_lang_features {
|
||||
if let Some(since) = since {
|
||||
// Warn if the user has enabled an already-stable lang feature.
|
||||
|
@ -980,11 +981,11 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
|||
fn check_features<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
remaining_lib_features: &mut FxIndexMap<&Symbol, Span>,
|
||||
remaining_implications: &mut FxHashMap<Symbol, Symbol>,
|
||||
remaining_implications: &mut UnordMap<Symbol, Symbol>,
|
||||
defined_features: &LibFeatures,
|
||||
all_implications: &FxHashMap<Symbol, Symbol>,
|
||||
all_implications: &UnordMap<Symbol, Symbol>,
|
||||
) {
|
||||
for (feature, since) in defined_features.to_vec() {
|
||||
for (feature, since) in defined_features.to_sorted_vec() {
|
||||
if let FeatureStability::AcceptedSince(since) = since
|
||||
&& let Some(span) = remaining_lib_features.get(&feature)
|
||||
{
|
||||
|
@ -1021,7 +1022,8 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
|||
// `remaining_lib_features`.
|
||||
let mut all_implications = remaining_implications.clone();
|
||||
for &cnum in tcx.crates(()) {
|
||||
all_implications.extend(tcx.stability_implications(cnum));
|
||||
all_implications
|
||||
.extend_unord(tcx.stability_implications(cnum).items().map(|(k, v)| (*k, *v)));
|
||||
}
|
||||
|
||||
check_features(
|
||||
|
@ -1052,8 +1054,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
|||
|
||||
// We only use the hash map contents to emit errors, and the order of
|
||||
// emitted errors do not affect query stability.
|
||||
#[allow(rustc::potential_query_instability)]
|
||||
for (implied_by, feature) in remaining_implications {
|
||||
for (&implied_by, &feature) in remaining_implications.to_sorted_stable_ord() {
|
||||
let local_defined_features = tcx.lib_features(LOCAL_CRATE);
|
||||
let span = local_defined_features
|
||||
.stability
|
||||
|
|
Loading…
Add table
Reference in a new issue