Replace some instances of FxHashMap/FxHashSet with stable alternatives (mostly in rustc_hir and rustc_ast_lowering)
Part of https://github.com/rust-lang/compiler-team/issues/533
This commit is contained in:
parent
2a7634047a
commit
115885ba7e
@ -1,7 +1,6 @@
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sorted_map::SortedMap;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap};
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_hir::*;
|
||||
use rustc_index::{Idx, IndexVec};
|
||||
@ -17,7 +16,7 @@ struct NodeCollector<'a, 'hir> {
|
||||
|
||||
/// Outputs
|
||||
nodes: IndexVec<ItemLocalId, Option<ParentedNode<'hir>>>,
|
||||
parenting: FxHashMap<LocalDefId, ItemLocalId>,
|
||||
parenting: LocalDefIdMap<ItemLocalId>,
|
||||
|
||||
/// The parent of this node
|
||||
parent_node: hir::ItemLocalId,
|
||||
@ -30,7 +29,7 @@ pub(super) fn index_hir<'hir>(
|
||||
tcx: TyCtxt<'hir>,
|
||||
item: hir::OwnerNode<'hir>,
|
||||
bodies: &SortedMap<ItemLocalId, &'hir Body<'hir>>,
|
||||
) -> (IndexVec<ItemLocalId, Option<ParentedNode<'hir>>>, FxHashMap<LocalDefId, ItemLocalId>) {
|
||||
) -> (IndexVec<ItemLocalId, Option<ParentedNode<'hir>>>, LocalDefIdMap<ItemLocalId>) {
|
||||
let mut nodes = IndexVec::new();
|
||||
// This node's parent should never be accessed: the owner's parent is computed by the
|
||||
// hir_owner_parent query. Make it invalid (= ItemLocalId::MAX) to force an ICE whenever it is
|
||||
@ -42,7 +41,7 @@ pub(super) fn index_hir<'hir>(
|
||||
parent_node: ItemLocalId::new(0),
|
||||
nodes,
|
||||
bodies,
|
||||
parenting: FxHashMap::default(),
|
||||
parenting: Default::default(),
|
||||
};
|
||||
|
||||
match item {
|
||||
|
@ -44,20 +44,20 @@
|
||||
|
||||
use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait};
|
||||
|
||||
use rustc_ast::node_id::NodeMap;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::{self as ast, *};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sorted_map::SortedMap;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::{DiagnosticArgFromDisplay, StashKey};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
|
||||
use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate};
|
||||
use rustc_hir::def_id::{LocalDefId, LocalDefIdMap, CRATE_DEF_ID, LOCAL_CRATE};
|
||||
use rustc_hir::{ConstArg, GenericArg, ItemLocalMap, ParamName, TraitCandidate};
|
||||
use rustc_index::{Idx, IndexSlice, IndexVec};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{ResolverAstLowering, TyCtxt, Visibility};
|
||||
@ -119,13 +119,13 @@ struct LoweringContext<'a, 'hir> {
|
||||
|
||||
current_hir_id_owner: hir::OwnerId,
|
||||
item_local_id_counter: hir::ItemLocalId,
|
||||
trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>,
|
||||
trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
|
||||
|
||||
impl_trait_defs: Vec<hir::GenericParam<'hir>>,
|
||||
impl_trait_bounds: Vec<hir::WherePredicate<'hir>>,
|
||||
|
||||
/// NodeIds that are lowered inside the current HIR owner.
|
||||
node_id_to_local_id: FxHashMap<NodeId, hir::ItemLocalId>,
|
||||
node_id_to_local_id: NodeMap<hir::ItemLocalId>,
|
||||
|
||||
allow_try_trait: Lrc<[Symbol]>,
|
||||
allow_gen_future: Lrc<[Symbol]>,
|
||||
@ -135,7 +135,7 @@ struct LoweringContext<'a, 'hir> {
|
||||
/// For each captured lifetime (e.g., 'a), we create a new lifetime parameter that is a generic
|
||||
/// defined on the TAIT, so we have type Foo<'a1> = ... and we establish a mapping in this
|
||||
/// field from the original parameter 'a to the new parameter 'a1.
|
||||
generics_def_id_map: Vec<FxHashMap<LocalDefId, LocalDefId>>,
|
||||
generics_def_id_map: Vec<LocalDefIdMap<LocalDefId>>,
|
||||
|
||||
host_param_id: Option<LocalDefId>,
|
||||
}
|
||||
@ -380,7 +380,7 @@ enum AstOwner<'a> {
|
||||
}
|
||||
|
||||
fn index_crate<'a>(
|
||||
node_id_to_def_id: &FxHashMap<NodeId, LocalDefId>,
|
||||
node_id_to_def_id: &NodeMap<LocalDefId>,
|
||||
krate: &'a Crate,
|
||||
) -> IndexVec<LocalDefId, AstOwner<'a>> {
|
||||
let mut indexer = Indexer { node_id_to_def_id, index: IndexVec::new() };
|
||||
@ -390,7 +390,7 @@ fn index_crate<'a>(
|
||||
return indexer.index;
|
||||
|
||||
struct Indexer<'s, 'a> {
|
||||
node_id_to_def_id: &'s FxHashMap<NodeId, LocalDefId>,
|
||||
node_id_to_def_id: &'s NodeMap<LocalDefId>,
|
||||
index: IndexVec<LocalDefId, AstOwner<'a>>,
|
||||
}
|
||||
|
||||
@ -642,7 +642,7 @@ fn with_hir_id_owner(
|
||||
/// `'a` declared on the TAIT, instead of the function.
|
||||
fn with_remapping<R>(
|
||||
&mut self,
|
||||
remap: FxHashMap<LocalDefId, LocalDefId>,
|
||||
remap: LocalDefIdMap<LocalDefId>,
|
||||
f: impl FnOnce(&mut Self) -> R,
|
||||
) -> R {
|
||||
self.generics_def_id_map.push(remap);
|
||||
@ -1657,7 +1657,7 @@ fn lower_opaque_inner(
|
||||
|
||||
// Map from captured (old) lifetime to synthetic (new) lifetime.
|
||||
// Used to resolve lifetimes in the bounds of the opaque.
|
||||
let mut captured_to_synthesized_mapping = FxHashMap::default();
|
||||
let mut captured_to_synthesized_mapping = LocalDefIdMap::default();
|
||||
// List of (early-bound) synthetic lifetimes that are owned by the opaque.
|
||||
// This is used to create the `hir::Generics` owned by the opaque.
|
||||
let mut synthesized_lifetime_definitions = vec![];
|
||||
|
@ -3,8 +3,8 @@
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::NodeId;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::ToStableHashKey;
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_macros::HashStable_Generic;
|
||||
use rustc_span::def_id::{DefId, LocalDefId};
|
||||
use rustc_span::hygiene::MacroKind;
|
||||
@ -806,4 +806,4 @@ pub enum LifetimeRes {
|
||||
ElidedAnchor { start: NodeId, end: NodeId },
|
||||
}
|
||||
|
||||
pub type DocLinkResMap = FxHashMap<(Symbol, Namespace), Option<Res<NodeId>>>;
|
||||
pub type DocLinkResMap = UnordMap<(Symbol, Namespace), Option<Res<NodeId>>>;
|
||||
|
@ -8,8 +8,8 @@
|
||||
use crate::def_id::{CrateNum, DefIndex, LocalDefId, StableCrateId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use crate::def_path_hash_map::DefPathHashMap;
|
||||
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::stable_hasher::{Hash64, StableHasher};
|
||||
use rustc_data_structures::unord::UnordMap;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
|
||||
@ -95,7 +95,7 @@ pub fn enumerated_keys_and_path_hashes(
|
||||
#[derive(Debug)]
|
||||
pub struct Definitions {
|
||||
table: DefPathTable,
|
||||
next_disambiguator: FxHashMap<(LocalDefId, DefPathData), u32>,
|
||||
next_disambiguator: UnordMap<(LocalDefId, DefPathData), u32>,
|
||||
|
||||
/// The [StableCrateId] of the local crate.
|
||||
stable_crate_id: StableCrateId,
|
||||
|
@ -1,12 +1,13 @@
|
||||
use crate::def_id::DefId;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_span::def_id::DefIdMap;
|
||||
use rustc_span::Symbol;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct DiagnosticItems {
|
||||
pub id_to_name: FxHashMap<DefId, Symbol>,
|
||||
pub name_to_id: FxHashMap<Symbol, DefId>,
|
||||
pub id_to_name: DefIdMap<Symbol>,
|
||||
pub name_to_id: FxIndexMap<Symbol, DefId>,
|
||||
}
|
||||
|
||||
impl<CTX: crate::HashStableContext> HashStable<CTX> for DiagnosticItems {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::def::{CtorKind, DefKind, Res};
|
||||
use crate::def_id::DefId;
|
||||
pub(crate) use crate::hir_id::{HirId, ItemLocalId, OwnerId};
|
||||
use crate::def_id::{DefId, LocalDefIdMap};
|
||||
pub(crate) use crate::hir_id::{HirId, ItemLocalId, ItemLocalMap, OwnerId};
|
||||
use crate::intravisit::FnKind;
|
||||
use crate::LangItem;
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
pub use rustc_ast::{ImplPolarity, IsAuto, Movability, Mutability, UnOp};
|
||||
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sorted_map::SortedMap;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_macros::HashStable_Generic;
|
||||
@ -874,12 +873,12 @@ pub struct OwnerInfo<'hir> {
|
||||
/// Contents of the HIR.
|
||||
pub nodes: OwnerNodes<'hir>,
|
||||
/// Map from each nested owner to its parent's local id.
|
||||
pub parenting: FxHashMap<LocalDefId, ItemLocalId>,
|
||||
pub parenting: LocalDefIdMap<ItemLocalId>,
|
||||
/// Collected attributes of the HIR nodes.
|
||||
pub attrs: AttributeMap<'hir>,
|
||||
/// Map indicating what traits are in scope for places where this
|
||||
/// is relevant; generated by resolve.
|
||||
pub trait_map: FxHashMap<ItemLocalId, Box<[TraitCandidate]>>,
|
||||
pub trait_map: ItemLocalMap<Box<[TraitCandidate]>>,
|
||||
}
|
||||
|
||||
impl<'tcx> OwnerInfo<'tcx> {
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::def::{CtorOf, DefKind, Res};
|
||||
use crate::def_id::DefId;
|
||||
use crate::def_id::{DefId, DefIdSet};
|
||||
use crate::hir::{self, BindingAnnotation, ByRef, HirId, PatKind};
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::Span;
|
||||
|
||||
@ -114,9 +113,9 @@ pub fn necessary_variants(&self) -> Vec<DefId> {
|
||||
}
|
||||
_ => true,
|
||||
});
|
||||
// We remove duplicates by inserting into a `FxHashSet` to avoid re-ordering
|
||||
// We remove duplicates by inserting into a hash set to avoid re-ordering
|
||||
// the bounds
|
||||
let mut duplicates = FxHashSet::default();
|
||||
let mut duplicates = DefIdSet::default();
|
||||
variants.retain(|def_id| duplicates.insert(*def_id));
|
||||
variants
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
|
||||
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, DeriveProcMacro};
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::def_id::{DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::{DefPath, DefPathData};
|
||||
use rustc_hir::diagnostic_items::DiagnosticItems;
|
||||
use rustc_index::Idx;
|
||||
@ -1200,7 +1200,7 @@ fn get_stripped_cfg_items(self, cnum: CrateNum, tcx: TyCtxt<'tcx>) -> &'tcx [Str
|
||||
|
||||
/// Iterates over the diagnostic items in the given crate.
|
||||
fn get_diagnostic_items(self) -> DiagnosticItems {
|
||||
let mut id_to_name = FxHashMap::default();
|
||||
let mut id_to_name = DefIdMap::default();
|
||||
let name_to_id = self
|
||||
.root
|
||||
.diagnostic_items
|
||||
|
@ -69,7 +69,7 @@
|
||||
CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LocalDefIdMap, LocalDefIdSet, LocalModDefId,
|
||||
};
|
||||
use rustc_hir::lang_items::{LangItem, LanguageItems};
|
||||
use rustc_hir::{Crate, ItemLocalId, TraitCandidate};
|
||||
use rustc_hir::{Crate, ItemLocalId, ItemLocalMap, TraitCandidate};
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_query_system::ich::StableHashingContext;
|
||||
use rustc_query_system::query::{try_get_cached, CacheSelector, QueryCache, QueryMode, QueryState};
|
||||
@ -1490,7 +1490,7 @@
|
||||
desc { "computing whether impls specialize one another" }
|
||||
}
|
||||
query in_scope_traits_map(_: hir::OwnerId)
|
||||
-> Option<&'tcx FxHashMap<ItemLocalId, Box<[TraitCandidate]>>> {
|
||||
-> Option<&'tcx ItemLocalMap<Box<[TraitCandidate]>>> {
|
||||
desc { "getting traits in scope at a block" }
|
||||
}
|
||||
|
||||
|
@ -192,7 +192,7 @@ pub struct ResolverAstLowering {
|
||||
|
||||
pub next_node_id: ast::NodeId,
|
||||
|
||||
pub node_id_to_def_id: FxHashMap<ast::NodeId, LocalDefId>,
|
||||
pub node_id_to_def_id: NodeMap<LocalDefId>,
|
||||
pub def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
|
||||
|
||||
pub trait_map: NodeMap<Vec<hir::TraitCandidate>>,
|
||||
|
@ -83,9 +83,6 @@ fn all_diagnostic_items(tcx: TyCtxt<'_>, (): ()) -> DiagnosticItems {
|
||||
|
||||
// Collect diagnostic items in other crates.
|
||||
for &cnum in tcx.crates(()).iter().chain(std::iter::once(&LOCAL_CRATE)) {
|
||||
// We are collecting many DiagnosticItems hash maps into one
|
||||
// DiagnosticItems hash map. The iteration order does not matter.
|
||||
#[allow(rustc::potential_query_instability)]
|
||||
for (&name, &def_id) in &tcx.diagnostic_items(cnum).name_to_id {
|
||||
collect_item(tcx, &mut items, name, def_id);
|
||||
}
|
||||
|
@ -1084,7 +1084,7 @@ pub struct Resolver<'a, 'tcx> {
|
||||
|
||||
next_node_id: NodeId,
|
||||
|
||||
node_id_to_def_id: FxHashMap<ast::NodeId, LocalDefId>,
|
||||
node_id_to_def_id: NodeMap<LocalDefId>,
|
||||
def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
|
||||
|
||||
/// Indices of unnamed struct or variant fields with unresolved attributes.
|
||||
@ -1296,7 +1296,7 @@ pub fn new(
|
||||
|
||||
let mut def_id_to_node_id = IndexVec::default();
|
||||
assert_eq!(def_id_to_node_id.push(CRATE_NODE_ID), CRATE_DEF_ID);
|
||||
let mut node_id_to_def_id = FxHashMap::default();
|
||||
let mut node_id_to_def_id = NodeMap::default();
|
||||
node_id_to_def_id.insert(CRATE_NODE_ID, CRATE_DEF_ID);
|
||||
|
||||
let mut invocation_parents = FxHashMap::default();
|
||||
|
Loading…
Reference in New Issue
Block a user