Auto merge of #119192 - michaelwoerister:mcp533-push, r=cjgillot
Replace a number of FxHashMaps/Sets with stable-iteration-order alternatives This PR replaces almost all of the remaining `FxHashMap`s in query results with either `FxIndexMap` or `UnordMap`. The only case that is missing is the `EffectiveVisibilities` struct which turned out to not be straightforward to transform. Once that is done too, we can remove the `HashStable` implementation from `HashMap`. The first commit adds the `StableCompare` trait which is a companion trait to `StableOrd`. Some types like `Symbol` can be compared in a cross-session stable way, but their `Ord` implementation is not stable. In such cases, a `StableCompare` implementation can be provided to offer a lightweight way for stable sorting. The more heavyweight option is to sort via `ToStableHashKey`, but then sorting needs to have access to a stable hashing context and `ToStableHashKey` can also be expensive as in the case of `Symbol` where it has to allocate a `String`. The rest of the commits are rather mechanical and don't overlap, so they are best reviewed individually. Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).
This commit is contained in:
commit
b8c207435c
30 changed files with 256 additions and 147 deletions
|
@ -57,11 +57,11 @@ use rustc_ast as ast;
|
|||
use rustc_ast::expand::{allocator::AllocatorKind, StrippedCfgItem};
|
||||
use rustc_attr as attr;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, FxIndexSet};
|
||||
use rustc_data_structures::fx::{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};
|
||||
|
@ -264,7 +264,7 @@ rustc_queries! {
|
|||
}
|
||||
|
||||
query collect_return_position_impl_trait_in_trait_tys(key: DefId)
|
||||
-> Result<&'tcx FxHashMap<DefId, ty::EarlyBinder<Ty<'tcx>>>, ErrorGuaranteed>
|
||||
-> Result<&'tcx DefIdMap<ty::EarlyBinder<Ty<'tcx>>>, ErrorGuaranteed>
|
||||
{
|
||||
desc { "comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process" }
|
||||
cache_on_disk_if { key.is_local() }
|
||||
|
@ -611,7 +611,7 @@ rustc_queries! {
|
|||
desc { "erasing regions from `{}`", ty }
|
||||
}
|
||||
|
||||
query wasm_import_module_map(_: CrateNum) -> &'tcx FxHashMap<DefId, String> {
|
||||
query wasm_import_module_map(_: CrateNum) -> &'tcx DefIdMap<String> {
|
||||
arena_cache
|
||||
desc { "getting wasm import module map" }
|
||||
}
|
||||
|
@ -1537,7 +1537,7 @@ rustc_queries! {
|
|||
/// added or removed in any upstream crate. Instead use the narrower
|
||||
/// `upstream_monomorphizations_for`, `upstream_drop_glue_for`, or, even
|
||||
/// better, `Instance::upstream_monomorphization()`.
|
||||
query upstream_monomorphizations(_: ()) -> &'tcx DefIdMap<FxHashMap<GenericArgsRef<'tcx>, CrateNum>> {
|
||||
query upstream_monomorphizations(_: ()) -> &'tcx DefIdMap<UnordMap<GenericArgsRef<'tcx>, CrateNum>> {
|
||||
arena_cache
|
||||
desc { "collecting available upstream monomorphizations" }
|
||||
}
|
||||
|
@ -1550,7 +1550,7 @@ rustc_queries! {
|
|||
/// You likely want to call `Instance::upstream_monomorphization()`
|
||||
/// instead of invoking this query directly.
|
||||
query upstream_monomorphizations_for(def_id: DefId)
|
||||
-> Option<&'tcx FxHashMap<GenericArgsRef<'tcx>, CrateNum>>
|
||||
-> Option<&'tcx UnordMap<GenericArgsRef<'tcx>, CrateNum>>
|
||||
{
|
||||
desc { |tcx|
|
||||
"collecting available upstream monomorphizations for `{}`",
|
||||
|
@ -1662,7 +1662,7 @@ rustc_queries! {
|
|||
desc { "resolving lifetimes" }
|
||||
}
|
||||
query named_variable_map(_: hir::OwnerId) ->
|
||||
Option<&'tcx FxHashMap<ItemLocalId, ResolvedArg>> {
|
||||
Option<&'tcx FxIndexMap<ItemLocalId, ResolvedArg>> {
|
||||
desc { "looking up a named region" }
|
||||
}
|
||||
query is_late_bound_map(_: hir::OwnerId) -> Option<&'tcx FxIndexSet<ItemLocalId>> {
|
||||
|
@ -1678,7 +1678,7 @@ rustc_queries! {
|
|||
separate_provide_extern
|
||||
}
|
||||
query late_bound_vars_map(_: hir::OwnerId)
|
||||
-> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
|
||||
-> Option<&'tcx FxIndexMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {
|
||||
desc { "looking up late bound vars" }
|
||||
}
|
||||
|
||||
|
@ -1734,7 +1734,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
|
||||
|
@ -1786,7 +1786,7 @@ rustc_queries! {
|
|||
}
|
||||
/// Collects the "trimmed", shortest accessible paths to all items for diagnostics.
|
||||
/// See the [provider docs](`rustc_middle::ty::print::trimmed_def_paths`) for more info.
|
||||
query trimmed_def_paths(_: ()) -> &'tcx FxHashMap<DefId, Symbol> {
|
||||
query trimmed_def_paths(_: ()) -> &'tcx DefIdMap<Symbol> {
|
||||
arena_cache
|
||||
desc { "calculating trimmed def paths" }
|
||||
}
|
||||
|
@ -2077,7 +2077,7 @@ rustc_queries! {
|
|||
desc { "computing autoderef types for `{}`", goal.value.value }
|
||||
}
|
||||
|
||||
query supported_target_features(_: CrateNum) -> &'tcx FxHashMap<String, Option<Symbol>> {
|
||||
query supported_target_features(_: CrateNum) -> &'tcx UnordMap<String, Option<Symbol>> {
|
||||
arena_cache
|
||||
eval_always
|
||||
desc { "looking up supported target features" }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue