Skip to content

Commit 72c9dd7

Browse files
committed
Attempt at replacing all occurrences.
1 parent 609f649 commit 72c9dd7

File tree

17 files changed

+85
-32
lines changed

17 files changed

+85
-32
lines changed

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ pub fn provide(providers: &mut Providers) {
910910
};
911911

912912
let (defids, _) = tcx.collect_and_partition_mono_items(cratenum);
913-
for id in &*defids {
913+
for id in defids.sorted_vector() {
914914
let CodegenFnAttrs { optimize, .. } = tcx.codegen_fn_attrs(*id);
915915
match optimize {
916916
attr::OptimizeAttr::None => continue,

compiler/rustc_data_structures/src/fx.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ pub type FxIndexSet<V> = indexmap::IndexSet<V, BuildHasherDefault<FxHasher>>;
99
macro_rules! define_id_collections {
1010
($map_name:ident, $set_name:ident, $key:ty) => {
1111
pub type $map_name<T> = $crate::fx::FxHashMap<$key, T>;
12-
pub type $set_name = $crate::fx::FxHashSet<$key>;
12+
pub type $set_name = $crate::stable_set::StableSet<$key>;
1313
};
1414
}

compiler/rustc_data_structures/src/stable_set.rs

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ use crate::stable_hasher::{stable_hash_reduce, HashStable, StableHasher, ToStabl
99
///
1010
/// It supports insert, remove, get functions from FxHashSet.
1111
/// It also allows to convert hashset to a sorted vector with the method `into_sorted_vector()`.
12-
#[derive(Clone)]
13-
pub struct StableSet<T> {
12+
#[derive(Clone, Encodable, Decodable)]
13+
pub struct StableSet<T>
14+
where
15+
T: Eq + Hash,
16+
{
1417
base: FxHashSet<T>,
1518
}
1619

@@ -62,6 +65,16 @@ impl<T: Hash + Eq> StableSet<T> {
6265
vector
6366
}
6467

68+
#[inline]
69+
pub fn sorted_vector<HCX>(&self, hcx: &HCX) -> Vec<&T>
70+
where
71+
T: ToStableHashKey<HCX>,
72+
{
73+
let mut vector = self.base.iter().collect::<Vec<_>>();
74+
vector.sort_by_cached_key(|x| x.to_stable_hash_key(hcx));
75+
vector
76+
}
77+
6578
#[inline]
6679
pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T>
6780
where
@@ -93,7 +106,7 @@ impl<T: Hash + Eq> StableSet<T> {
93106

94107
impl<T, HCX> HashStable<HCX> for StableSet<T>
95108
where
96-
T: ToStableHashKey<HCX> + Eq,
109+
T: ToStableHashKey<HCX> + Eq + Hash,
97110
{
98111
#[inline]
99112
fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
@@ -103,3 +116,23 @@ where
103116
});
104117
}
105118
}
119+
120+
impl<T> FromIterator<T> for StableSet<T>
121+
where
122+
T: Eq + Hash,
123+
{
124+
#[inline]
125+
fn from_iter<Collection: IntoIterator<Item = T>>(iter: Collection) -> Self {
126+
Self { base: iter.into_iter().collect() }
127+
}
128+
}
129+
130+
impl<T> Extend<T> for StableSet<T>
131+
where
132+
T: Eq + Hash,
133+
{
134+
#[inline]
135+
fn extend<Iter: IntoIterator<Item = T>>(&mut self, iter: Iter) {
136+
self.base.extend(iter)
137+
}
138+
}

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1742,7 +1742,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
17421742
empty_proc_macro!(self);
17431743
let tcx = self.tcx;
17441744
let lib_features = tcx.lib_features(());
1745-
self.lazy(lib_features.to_vec())
1745+
self.lazy(lib_features.to_vec(tcx))
17461746
}
17471747

17481748
fn encode_diagnostic_items(&mut self) -> Lazy<[(Symbol, DefIndex)]> {

compiler/rustc_middle/src/middle/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@ pub mod dependency_format;
33
pub mod exported_symbols;
44
pub mod lang_items;
55
pub mod lib_features {
6-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
6+
use rustc_data_structures::{fx::FxHashMap, stable_set::StableSet};
77
use rustc_span::symbol::Symbol;
88

9+
use crate::ty::TyCtxt;
10+
911
#[derive(HashStable, Debug)]
1012
pub struct LibFeatures {
1113
// A map from feature to stabilisation version.
1214
pub stable: FxHashMap<Symbol, Symbol>,
13-
pub unstable: FxHashSet<Symbol>,
15+
pub unstable: StableSet<Symbol>,
1416
}
1517

1618
impl LibFeatures {
17-
pub fn to_vec(&self) -> Vec<(Symbol, Option<Symbol>)> {
19+
pub fn to_vec(&self, tcx: TyCtxt<'_>) -> Vec<(Symbol, Option<Symbol>)> {
20+
let hcx = tcx.create_stable_hashing_context();
1821
let mut all_features: Vec<_> = self
1922
.stable
2023
.iter()
2124
.map(|(f, s)| (*f, Some(*s)))
22-
.chain(self.unstable.iter().map(|f| (*f, None)))
25+
.chain(self.unstable.sorted_vector(&hcx).into_iter().map(|f| (*f, None)))
2326
.collect();
2427
all_features.sort_unstable_by(|a, b| a.0.as_str().partial_cmp(b.0.as_str()).unwrap());
2528
all_features

compiler/rustc_middle/src/middle/resolve_lifetime.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
33
use crate::ty;
44

5-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
5+
use rustc_data_structures::fx::FxHashMap;
6+
use rustc_data_structures::stable_set::StableSet;
67
use rustc_hir::def_id::{DefId, LocalDefId};
78
use rustc_hir::ItemLocalId;
89
use rustc_macros::HashStable;
@@ -63,7 +64,7 @@ pub struct ResolveLifetimes {
6364
/// Set of lifetime def ids that are late-bound; a region can
6465
/// be late-bound if (a) it does NOT appear in a where-clause and
6566
/// (b) it DOES appear in the arguments.
66-
pub late_bound: FxHashMap<LocalDefId, FxHashSet<ItemLocalId>>,
67+
pub late_bound: FxHashMap<LocalDefId, StableSet<ItemLocalId>>,
6768

6869
pub late_bound_vars: FxHashMap<LocalDefId, FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>>,
6970
}

compiler/rustc_middle/src/middle/stability.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ use crate::ty::{self, DefIdTree, TyCtxt};
77
use rustc_ast::NodeId;
88
use rustc_attr::{self as attr, ConstStability, Deprecation, Stability};
99
use rustc_data_structures::fx::FxHashMap;
10+
use rustc_data_structures::stable_set::StableSet;
1011
use rustc_errors::{Applicability, Diagnostic};
1112
use rustc_feature::GateIssue;
1213
use rustc_hir as hir;
1314
use rustc_hir::def::DefKind;
1415
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_INDEX};
15-
use rustc_hir::{self, HirId};
16+
use rustc_hir::{self, def_id::CrateNum, HirId};
1617
use rustc_middle::ty::print::with_no_trimmed_paths;
1718
use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE};
1819
use rustc_session::lint::{BuiltinLintDiagnostics, Level, Lint, LintBuffer};
@@ -63,6 +64,12 @@ pub struct Index {
6364
pub stab_map: FxHashMap<LocalDefId, Stability>,
6465
pub const_stab_map: FxHashMap<LocalDefId, ConstStability>,
6566
pub depr_map: FxHashMap<LocalDefId, DeprecationEntry>,
67+
68+
/// Maps for each crate whether it is part of the staged API.
69+
pub staged_api: FxHashMap<CrateNum, bool>,
70+
71+
/// Features enabled for this crate.
72+
pub active_features: StableSet<Symbol>,
6673
}
6774

6875
impl Index {

compiler/rustc_middle/src/query/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ rustc_queries! {
775775
/// The second return value maps from ADTs to ignored derived traits (e.g. Debug and Clone) and
776776
/// their respective impl (i.e., part of the derive macro)
777777
query live_symbols_and_ignored_derived_traits(_: ()) -> (
778-
FxHashSet<LocalDefId>,
778+
StableSet<LocalDefId>,
779779
FxHashMap<LocalDefId, Vec<(DefId, DefId)>>
780780
) {
781781
storage(ArenaCacheSelector<'tcx>)
@@ -828,7 +828,7 @@ rustc_queries! {
828828
}
829829
}
830830

831-
query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
831+
query used_trait_imports(key: LocalDefId) -> &'tcx StableSet<LocalDefId> {
832832
desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
833833
cache_on_disk_if { true }
834834
}
@@ -978,7 +978,7 @@ rustc_queries! {
978978
desc { "checking for private elements in public interfaces" }
979979
}
980980

981-
query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
981+
query reachable_set(_: ()) -> StableSet<LocalDefId> {
982982
storage(ArenaCacheSelector<'tcx>)
983983
desc { "reachability" }
984984
}
@@ -1055,7 +1055,7 @@ rustc_queries! {
10551055
cache_on_disk_if { true }
10561056
}
10571057

1058-
query asm_target_features(def_id: DefId) -> &'tcx FxHashSet<Symbol> {
1058+
query asm_target_features(def_id: DefId) -> &'tcx StableSet<Symbol> {
10591059
desc { |tcx| "computing target features for inline asm of `{}`", tcx.def_path_str(def_id) }
10601060
}
10611061

@@ -1506,7 +1506,7 @@ rustc_queries! {
15061506
desc { "looking up a named region" }
15071507
}
15081508
query is_late_bound_map(_: LocalDefId) ->
1509-
Option<(LocalDefId, &'tcx FxHashSet<ItemLocalId>)> {
1509+
Option<(LocalDefId, &'tcx StableSet<ItemLocalId>)> {
15101510
desc { "testing if a region is late bound" }
15111511
}
15121512
/// For a given item (like a struct), gets the default lifetimes to be used
@@ -1645,7 +1645,7 @@ rustc_queries! {
16451645
query maybe_unused_extern_crates(_: ()) -> &'tcx [(LocalDefId, Span)] {
16461646
desc { "looking up all possibly unused extern crates" }
16471647
}
1648-
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx FxHashSet<Symbol> {
1648+
query names_imported_by_glob_use(def_id: LocalDefId) -> &'tcx StableSet<Symbol> {
16491649
desc { |tcx| "names_imported_by_glob_use for `{}`", tcx.def_path_str(def_id.to_def_id()) }
16501650
}
16511651

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ use crate::ty::{
2525
};
2626
use rustc_ast as ast;
2727
use rustc_data_structures::fingerprint::Fingerprint;
28-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
28+
use rustc_data_structures::fx::FxHashMap;
2929
use rustc_data_structures::intern::Interned;
3030
use rustc_data_structures::memmap::Mmap;
3131
use rustc_data_structures::profiling::SelfProfilerRef;
3232
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
3333
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
34+
use rustc_data_structures::stable_set::StableSet;
3435
use rustc_data_structures::steal::Steal;
3536
use rustc_data_structures::sync::{self, Lock, Lrc, WorkerLocal};
3637
use rustc_data_structures::vec_map::VecMap;
@@ -480,7 +481,7 @@ pub struct TypeckResults<'tcx> {
480481
/// This is used for warning unused imports. During type
481482
/// checking, this `Lrc` should not be cloned: it must have a ref-count
482483
/// of 1 so that we can insert things into the set mutably.
483-
pub used_trait_imports: Lrc<FxHashSet<LocalDefId>>,
484+
pub used_trait_imports: Lrc<StableSet<LocalDefId>>,
484485

485486
/// If any errors occurred while type-checking this body,
486487
/// this field will be set to `Some(ErrorGuaranteed)`.
@@ -2208,7 +2209,7 @@ impl<'tcx> TyCtxt<'tcx> {
22082209
/// to identify which traits may define a given associated type to help avoid cycle errors.
22092210
/// Returns a `DefId` iterator.
22102211
fn super_traits_of(self, trait_def_id: DefId) -> impl Iterator<Item = DefId> + 'tcx {
2211-
let mut set = FxHashSet::default();
2212+
let mut set = StableSet::default();
22122213
let mut stack = vec![trait_def_id];
22132214

22142215
set.insert(trait_def_id);

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub use adt::*;
1818
pub use assoc::*;
1919
pub use generics::*;
2020
use rustc_data_structures::fingerprint::Fingerprint;
21+
use rustc_data_structures::stable_set::StableSet;
2122
pub use vtable::*;
2223

2324
use crate::metadata::ModChild;
@@ -135,7 +136,7 @@ pub struct ResolverOutputs {
135136
pub maybe_unused_trait_imports: FxHashSet<LocalDefId>,
136137
pub maybe_unused_extern_crates: Vec<(LocalDefId, Span)>,
137138
pub reexport_map: FxHashMap<LocalDefId, Vec<ModChild>>,
138-
pub glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
139+
pub glob_map: FxHashMap<LocalDefId, StableSet<Symbol>>,
139140
/// Extern prelude entries. The value is `true` if the entry was introduced
140141
/// via `extern crate` item and not `--extern` option or compiler built-in.
141142
pub extern_prelude: FxHashMap<Symbol, bool>,

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2763,8 +2763,9 @@ fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> FxHashMap<DefId, Symbol> {
27632763
let unique_symbols_rev: &mut FxHashMap<(Namespace, Symbol), Option<DefId>> =
27642764
&mut FxHashMap::default();
27652765

2766+
let hcx = tcx.create_stable_hashing_context();
27662767
for symbol_set in tcx.resolutions(()).glob_map.values() {
2767-
for symbol in symbol_set {
2768+
for symbol in symbol_set.sorted_vector(&hcx) {
27682769
unique_symbols_rev.insert((Namespace::TypeNS, *symbol), None);
27692770
unique_symbols_rev.insert((Namespace::ValueNS, *symbol), None);
27702771
unique_symbols_rev.insert((Namespace::MacroNS, *symbol), None);

compiler/rustc_middle/src/ty/query.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,13 @@ use crate::ty::subst::{GenericArg, SubstsRef};
3333
use crate::ty::util::AlwaysRequiresDrop;
3434
use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
3535
use rustc_ast::expand::allocator::AllocatorKind;
36-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
3736
use rustc_data_structures::steal::Steal;
3837
use rustc_data_structures::svh::Svh;
3938
use rustc_data_structures::sync::Lrc;
39+
use rustc_data_structures::{
40+
fx::{FxHashMap, FxIndexMap},
41+
stable_set::StableSet,
42+
};
4043
use rustc_errors::ErrorGuaranteed;
4144
use rustc_hir as hir;
4245
use rustc_hir::def::DefKind;

compiler/rustc_passes/src/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
898898

899899
// We always collect the lib features declared in the current crate, even if there are
900900
// no unknown features, because the collection also does feature attribute validation.
901-
let local_defined_features = tcx.lib_features(()).to_vec();
901+
let local_defined_features = tcx.lib_features(()).to_vec(tcx);
902902
if !remaining_lib_features.is_empty() {
903903
check_features(&mut remaining_lib_features, &local_defined_features);
904904

compiler/rustc_resolve/src/late/lifetimes.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
use crate::late::diagnostics::{ForLifetimeSpanType, MissingLifetimeSpot};
1010
use rustc_ast::walk_list;
11+
use rustc_ast_lowering::ResolverAstLowering;
1112
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
1213
use rustc_errors::{struct_span_err, Applicability, Diagnostic};
1314
use rustc_hir as hir;
@@ -468,14 +469,14 @@ fn do_resolve(
468469
named_region_map
469470
}
470471

471-
fn convert_named_region_map(named_region_map: NamedRegionMap) -> ResolveLifetimes {
472+
fn convert_named_region_map(named_region_map: NamedRegionMap, tcx: TyCtxt<'_>) -> ResolveLifetimes {
472473
let mut rl = ResolveLifetimes::default();
473-
474+
let hcx = tcx.create_stable_hashing_context();
474475
for (hir_id, v) in named_region_map.defs {
475476
let map = rl.defs.entry(hir_id.owner).or_default();
476477
map.insert(hir_id.local_id, v);
477478
}
478-
for hir_id in named_region_map.late_bound {
479+
for hir_id in named_region_map.late_bound.sorted_vector(&hcx) {
479480
let map = rl.late_bound.entry(hir_id.owner).or_default();
480481
map.insert(hir_id.local_id);
481482
}

compiler/rustc_resolve/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#[macro_use]
2525
extern crate tracing;
2626

27+
use rustc_data_structures::stable_set::StableSet;
2728
pub use rustc_hir::def::{Namespace, PerNS};
2829

2930
use Determinacy::*;
@@ -975,7 +976,7 @@ pub struct Resolver<'a> {
975976
underscore_disambiguator: u32,
976977

977978
/// Maps glob imports to the names of items actually imported.
978-
glob_map: FxHashMap<LocalDefId, FxHashSet<Symbol>>,
979+
glob_map: FxHashMap<LocalDefId, StableSet<Symbol>>,
979980
/// Visibilities in "lowered" form, for all entities that have them.
980981
visibilities: FxHashMap<LocalDefId, ty::Visibility>,
981982
used_imports: FxHashSet<NodeId>,

compiler/rustc_typeck/src/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ fn has_typeck_results(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
312312
}
313313
}
314314

315-
fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &FxHashSet<LocalDefId> {
315+
fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &StableSet<LocalDefId> {
316316
&*tcx.typeck(def_id).used_trait_imports
317317
}
318318

compiler/rustc_typeck/src/check/writeback.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
425425
let fcx_typeck_results = self.fcx.typeck_results.borrow();
426426
let fcx_coercion_casts = fcx_typeck_results.coercion_casts();
427427
assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
428+
let hcx = self.tcx().create_stable_hashing_context();
428429

429-
for local_id in fcx_coercion_casts {
430+
for local_id in fcx_coercion_casts.sorted_vector(&hcx) {
430431
self.typeck_results.set_coercion_cast(*local_id);
431432
}
432433
}

0 commit comments

Comments
 (0)