Skip to content

Commit f7f913c

Browse files
committed
most of this is broken
mentioning rust-lang#84446
1 parent d66e861 commit f7f913c

File tree

17 files changed

+66
-61
lines changed

17 files changed

+66
-61
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
266266

267267
let all_def_ids: DefIdSet = tcx
268268
.mir_keys(LOCAL_CRATE)
269-
.iter()
269+
.to_sorted_vec()
270+
.into_iter()
270271
.filter_map(|local_def_id| {
271272
let def_id = local_def_id.to_def_id();
272273
if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) {
@@ -309,13 +310,8 @@ fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
309310
// Add a new `FunctionCoverage` to the `function_coverage_map`, with unreachable code regions
310311
// for each region in it's MIR.
311312

312-
// Convert the `HashSet` of `codegenned_def_ids` to a sortable vector, and sort them.
313-
let mut sorted_codegenned_def_ids: Vec<DefId> =
314-
codegenned_def_ids.iter().map(|def_id| *def_id).collect();
315-
sorted_codegenned_def_ids.sort_unstable();
316-
317313
let mut first_covered_def_id_by_file: FxHashMap<Symbol, DefId> = FxHashMap::default();
318-
for &def_id in sorted_codegenned_def_ids.iter() {
314+
for &def_id in codegenned_def_ids.to_sorted_vec() {
319315
if let Some(covered_file_name) = tcx.covered_file_name(def_id) {
320316
// Only add files known to have unused functions
321317
if unused_def_ids_by_file.contains_key(covered_file_name) {

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
5959
let special_runtime_crate =
6060
tcx.is_panic_runtime(LOCAL_CRATE) || tcx.is_compiler_builtins(LOCAL_CRATE);
6161

62-
let mut reachable_non_generics: DefIdMap<_> = tcx
62+
let mut reachable_non_generics = tcx
6363
.reachable_set(LOCAL_CRATE)
64-
.iter()
65-
.filter_map(|&def_id| {
64+
.to_sorted_vec();
65+
reachable_non_generics.retain(|&&def_id| {
6666
// We want to ignore some FFI functions that are not exposed from
6767
// this crate. Reachable FFI functions can be lumped into two
6868
// categories:
@@ -78,7 +78,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
7878
// let it through if it's included statically.
7979
match tcx.hir().get(tcx.hir().local_def_id_to_hir_id(def_id)) {
8080
Node::ForeignItem(..) => {
81-
tcx.is_statically_included_foreign_item(def_id).then_some(def_id)
81+
tcx.is_statically_included_foreign_item(def_id)
8282
}
8383

8484
// Only consider nodes that actually have exported symbols.
@@ -88,22 +88,19 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
8888
})
8989
| Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }) => {
9090
let generics = tcx.generics_of(def_id);
91-
if !generics.requires_monomorphization(tcx)
91+
!generics.requires_monomorphization(tcx)
9292
// Functions marked with #[inline] are codegened with "internal"
9393
// linkage and are not exported unless marked with an extern
94-
// inidicator
94+
// indicator
9595
&& (!Instance::mono(tcx, def_id.to_def_id()).def.generates_cgu_internal_copy(tcx)
9696
|| tcx.codegen_fn_attrs(def_id.to_def_id()).contains_extern_indicator())
97-
{
98-
Some(def_id)
99-
} else {
100-
None
101-
}
10297
}
10398

104-
_ => None,
99+
_ => false,
105100
}
106-
})
101+
});
102+
let mut reachable_non_generics: DefIdMap<_> = reachable_non_generics
103+
.into_iter()
107104
.map(|def_id| {
108105
let export_level = if special_runtime_crate {
109106
let name = tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())).name;

compiler/rustc_codegen_ssa/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ pub fn provide(providers: &mut Providers) {
827827
};
828828

829829
let (defids, _) = tcx.collect_and_partition_mono_items(cratenum);
830-
for id in &*defids {
830+
for id in defids.to_sorted_vec() {
831831
let CodegenFnAttrs { optimize, .. } = tcx.codegen_fn_attrs(*id);
832832
match optimize {
833833
attr::OptimizeAttr::None => continue,

compiler/rustc_data_structures/src/fx.rs

+1-1
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

+9
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,13 @@ impl<T: Eq + Hash> StableSet<T> {
103103
{
104104
self.base.contains(value)
105105
}
106+
107+
pub fn difference<'a>(
108+
&'a self,
109+
other: &'a Self
110+
) -> Vec<&'a T> where T: Ord {
111+
let mut vec: Vec<_> = self.base.difference(&other.base).collect();
112+
vec.sort_unstable();
113+
vec
114+
}
106115
}

compiler/rustc_metadata/src/rmeta/encoder.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -1236,39 +1236,37 @@ impl EncodeContext<'a, 'tcx> {
12361236
return;
12371237
}
12381238

1239-
let mut keys_and_jobs = self
1240-
.tcx
1239+
let tcx = self.tcx;
1240+
let keys_and_jobs = tcx
12411241
.mir_keys(LOCAL_CRATE)
1242-
.iter()
1242+
.to_sorted_vec()
1243+
.into_iter()
12431244
.filter_map(|&def_id| {
1244-
let (encode_const, encode_opt) = should_encode_mir(self.tcx, def_id);
1245-
if encode_const || encode_opt {
1246-
Some((def_id, encode_const, encode_opt))
1247-
} else {
1248-
None
1249-
}
1250-
})
1251-
.collect::<Vec<_>>();
1252-
// Sort everything to ensure a stable order for diagnotics.
1253-
keys_and_jobs.sort_by_key(|&(def_id, _, _)| def_id);
1254-
for (def_id, encode_const, encode_opt) in keys_and_jobs.into_iter() {
1245+
let (encode_const, encode_opt) = should_encode_mir(tcx, def_id);
1246+
if encode_const || encode_opt {
1247+
Some((def_id, encode_const, encode_opt))
1248+
} else {
1249+
None
1250+
}
1251+
});
1252+
for (def_id, encode_const, encode_opt) in keys_and_jobs {
12551253
debug_assert!(encode_const || encode_opt);
12561254

12571255
debug!("EntryBuilder::encode_mir({:?})", def_id);
12581256
if encode_opt {
1259-
record!(self.tables.mir[def_id.to_def_id()] <- self.tcx.optimized_mir(def_id));
1257+
record!(self.tables.mir[def_id.to_def_id()] <- tcx.optimized_mir(def_id));
12601258
}
12611259
if encode_const {
1262-
record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- self.tcx.mir_for_ctfe(def_id));
1260+
record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- tcx.mir_for_ctfe(def_id));
12631261

1264-
let abstract_const = self.tcx.mir_abstract_const(def_id);
1262+
let abstract_const = tcx.mir_abstract_const(def_id);
12651263
if let Ok(Some(abstract_const)) = abstract_const {
12661264
record!(self.tables.mir_abstract_consts[def_id.to_def_id()] <- abstract_const);
12671265
}
12681266
}
1269-
record!(self.tables.promoted_mir[def_id.to_def_id()] <- self.tcx.promoted_mir(def_id));
1267+
record!(self.tables.promoted_mir[def_id.to_def_id()] <- tcx.promoted_mir(def_id));
12701268

1271-
let unused = self.tcx.unused_generic_params(def_id);
1269+
let unused = tcx.unused_generic_params(def_id);
12721270
if !unused.is_empty() {
12731271
record!(self.tables.unused_generic_params[def_id.to_def_id()] <- unused);
12741272
}
@@ -1997,7 +1995,7 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
19971995
return;
19981996
}
19991997

2000-
par_iter(tcx.mir_keys(LOCAL_CRATE)).for_each(|&def_id| {
1998+
par_iter(tcx.mir_keys(LOCAL_CRATE).to_sorted_vec()).for_each(|&def_id| {
20011999
let (encode_const, encode_opt) = should_encode_mir(tcx, def_id);
20022000

20032001
if encode_const {

compiler/rustc_middle/src/query/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ rustc_queries! {
214214
/// Set of all the `DefId`s in this crate that have MIR associated with
215215
/// them. This includes all the body owners, but also things like struct
216216
/// constructors.
217-
query mir_keys(_: CrateNum) -> FxHashSet<LocalDefId> {
217+
query mir_keys(_: CrateNum) -> StableSet<LocalDefId> {
218218
storage(ArenaCacheSelector<'tcx>)
219219
desc { "getting a list of all mir_keys" }
220220
}
@@ -701,7 +701,7 @@ rustc_queries! {
701701
}
702702
}
703703

704-
query used_trait_imports(key: LocalDefId) -> &'tcx FxHashSet<LocalDefId> {
704+
query used_trait_imports(key: LocalDefId) -> &'tcx StableSet<LocalDefId> {
705705
desc { |tcx| "used_trait_imports `{}`", tcx.def_path_str(key.to_def_id()) }
706706
cache_on_disk_if { true }
707707
}
@@ -846,7 +846,7 @@ rustc_queries! {
846846
desc { "checking for private elements in public interfaces" }
847847
}
848848

849-
query reachable_set(_: CrateNum) -> FxHashSet<LocalDefId> {
849+
query reachable_set(_: CrateNum) -> StableSet<LocalDefId> {
850850
storage(ArenaCacheSelector<'tcx>)
851851
desc { "reachability" }
852852
}

compiler/rustc_middle/src/ty/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,10 @@ impl<'tcx> TypeckResults<'tcx> {
703703
pub fn set_coercion_cast(&mut self, id: ItemLocalId) {
704704
self.coercion_casts.insert(id);
705705
}
706+
707+
pub fn add_coercion_casts(&mut self, iter: impl IntoIterator<Item = ItemLocalId>) {
708+
self.coercion_casts.extend(iter)
709+
}
706710

707711
pub fn coercion_casts(&self) -> &ItemLocalSet {
708712
&self.coercion_casts

compiler/rustc_middle/src/ty/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use crate::ty::subst::{GenericArg, SubstsRef};
3232
use crate::ty::util::AlwaysRequiresDrop;
3333
use crate::ty::{self, AdtSizedConstraint, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt};
3434
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
35-
use rustc_data_structures::stable_hasher::StableVec;
3635
use rustc_data_structures::stable_set::StableSet;
36+
use rustc_data_structures::stable_hasher::StableVec;
3737
use rustc_data_structures::steal::Steal;
3838
use rustc_data_structures::svh::Svh;
3939
use rustc_data_structures::sync::Lrc;

compiler/rustc_mir/src/borrow_check/universal_regions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ fn for_each_late_bound_region_defined_on<'tcx>(
803803
mut f: impl FnMut(ty::Region<'tcx>),
804804
) {
805805
if let Some((owner, late_bounds)) = tcx.is_late_bound_map(fn_def_id.expect_local()) {
806-
for &late_bound in late_bounds.iter() {
806+
for &late_bound in late_bounds.to_sorted_vec() {
807807
let hir_id = HirId { owner, local_id: late_bound };
808808
let name = tcx.hir().name(hir_id);
809809
let region_def_id = tcx.hir().local_def_id(hir_id);

compiler/rustc_mir/src/transform/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::{shim, util};
22
use required_consts::RequiredConstsVisitor;
33
use rustc_data_structures::fx::FxHashSet;
4+
use rustc_data_structures::stable_set::StableSet;
45
use rustc_data_structures::steal::Steal;
56
use rustc_hir as hir;
67
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
@@ -103,10 +104,10 @@ fn is_mir_available(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
103104

104105
/// Finds the full set of `DefId`s within the current crate that have
105106
/// MIR associated with them.
106-
fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> FxHashSet<LocalDefId> {
107+
fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> StableSet<LocalDefId> {
107108
assert_eq!(krate, LOCAL_CRATE);
108109

109-
let mut set = FxHashSet::default();
110+
let mut set = StableSet::default();
110111

111112
// All body-owners have MIR associated with them.
112113
set.extend(tcx.body_owners());
@@ -115,7 +116,7 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> FxHashSet<LocalDefId> {
115116
// they don't have a BodyId, so we need to build them separately.
116117
struct GatherCtors<'a, 'tcx> {
117118
tcx: TyCtxt<'tcx>,
118-
set: &'a mut FxHashSet<LocalDefId>,
119+
set: &'a mut StableSet<LocalDefId>,
119120
}
120121
impl<'a, 'tcx> Visitor<'tcx> for GatherCtors<'a, 'tcx> {
121122
fn visit_variant_data(

compiler/rustc_mir/src/util/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,6 @@ pub fn dump_mir_def_ids(tcx: TyCtxt<'_>, single: Option<DefId>) -> Vec<DefId> {
10171017
if let Some(i) = single {
10181018
vec![i]
10191019
} else {
1020-
tcx.mir_keys(LOCAL_CRATE).iter().map(|def_id| def_id.to_def_id()).collect()
1020+
tcx.mir_keys(LOCAL_CRATE).to_sorted_vec().into_iter().map(|def_id| def_id.to_def_id()).collect()
10211021
}
10221022
}

compiler/rustc_passes/src/reachable.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// reachable as well.
77

88
use rustc_data_structures::fx::FxHashSet;
9+
use rustc_data_structures::stable_set::StableSet;
910
use rustc_hir as hir;
1011
use rustc_hir::def::{DefKind, Res};
1112
use rustc_hir::def_id::LOCAL_CRATE;
@@ -65,7 +66,7 @@ struct ReachableContext<'tcx> {
6566
tcx: TyCtxt<'tcx>,
6667
maybe_typeck_results: Option<&'tcx ty::TypeckResults<'tcx>>,
6768
// The set of items which must be exported in the linkage sense.
68-
reachable_symbols: FxHashSet<LocalDefId>,
69+
reachable_symbols: StableSet<LocalDefId>,
6970
// A worklist of item IDs. Each item ID in this worklist will be inlined
7071
// and will be scanned for further references.
7172
// FIXME(eddyb) benchmark if this would be faster as a `VecDeque`.
@@ -386,7 +387,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
386387
}
387388
}
388389

389-
fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, crate_num: CrateNum) -> FxHashSet<LocalDefId> {
390+
fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, crate_num: CrateNum) -> StableSet<LocalDefId> {
390391
debug_assert!(crate_num == LOCAL_CRATE);
391392

392393
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);

compiler/rustc_resolve/src/late/lifetimes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ fn do_resolve(
513513
let map = rl.defs.entry(hir_id.owner).or_default();
514514
map.insert(hir_id.local_id, v);
515515
}
516-
for hir_id in named_region_map.late_bound {
516+
for hir_id in named_region_map.late_bound.to_sorted_vec() {
517517
let map = rl.late_bound.entry(hir_id.owner).or_default();
518518
map.insert(hir_id.local_id);
519519
}
@@ -741,9 +741,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
741741
});
742742
}
743743
for (&owner, late_bound) in resolved_lifetimes.late_bound.iter() {
744-
for &local_id in late_bound.to_sorted_vec() {
744+
late_bound.to_sorted_vec().into_iter().for_each(|&local_id| {
745745
self.map.late_bound.insert(hir::HirId { owner, local_id });
746-
}
746+
});
747747
}
748748
for (&owner, late_bound_vars) in
749749
resolved_lifetimes.late_bound_vars.iter()

compiler/rustc_typeck/src/check/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ pub use inherited::{Inherited, InheritedBuilder};
102102
use crate::astconv::AstConv;
103103
use crate::check::gather_locals::GatherLocalsVisitor;
104104
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
105+
use rustc_data_structures::stable_set::StableSet;
105106
use rustc_errors::{pluralize, struct_span_err, Applicability};
106107
use rustc_hir as hir;
107108
use rustc_hir::def::Res;
@@ -327,7 +328,7 @@ fn has_typeck_results(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
327328
}
328329
}
329330

330-
fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &FxHashSet<LocalDefId> {
331+
fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &StableSet<LocalDefId> {
331332
&*tcx.typeck(def_id).used_trait_imports
332333
}
333334

compiler/rustc_typeck/src/check/writeback.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
403403
let fcx_coercion_casts = fcx_typeck_results.coercion_casts();
404404
assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
405405

406-
for local_id in fcx_coercion_casts {
407-
self.typeck_results.set_coercion_cast(*local_id);
408-
}
406+
self.typeck_results.add_coercion_casts(fcx_coercion_casts.to_sorted_vec().into_iter().copied());
409407
}
410408

411409
fn visit_user_provided_tys(&mut self) {

compiler/rustc_typeck/src/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
1313
let item_def_id = tcx.hir().body_owner_def_id(body_id);
1414
let imports = tcx.used_trait_imports(item_def_id);
1515
debug!("GatherVisitor: item_def_id={:?} with imports {:#?}", item_def_id, imports);
16-
used_trait_imports.extend(imports.iter());
16+
used_trait_imports.extend(imports.to_sorted_vec());
1717
}
1818

1919
let mut visitor = CheckVisitor { tcx, used_trait_imports };

0 commit comments

Comments
 (0)