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
|
@ -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(
|
||||
|
@ -1050,10 +1052,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
|||
tcx.dcx().emit_err(errors::UnknownFeature { span, feature: *feature });
|
||||
}
|
||||
|
||||
// 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
Add a link
Reference in a new issue