Skip to content

Commit f0eadba

Browse files
Use LocalDefIdSet instead of FxHashSet for reachable_set query.
1 parent 5ff00f9 commit f0eadba

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
5858

5959
let mut reachable_non_generics: DefIdMap<_> = tcx
6060
.reachable_set(())
61-
.iter()
61+
.items()
6262
.filter_map(|&def_id| {
6363
// We want to ignore some FFI functions that are not exposed from
6464
// this crate. Reachable FFI functions can be lumped into two
@@ -136,7 +136,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
136136
};
137137
(def_id.to_def_id(), info)
138138
})
139-
.collect();
139+
.into();
140140

141141
if let Some(id) = tcx.proc_macro_decls_static(()) {
142142
reachable_non_generics.insert(

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ rustc_queries! {
11131113
desc { "checking for private elements in public interfaces" }
11141114
}
11151115

1116-
query reachable_set(_: ()) -> &'tcx FxHashSet<LocalDefId> {
1116+
query reachable_set(_: ()) -> &'tcx LocalDefIdSet {
11171117
arena_cache
11181118
desc { "reachability" }
11191119
}

compiler/rustc_middle/src/ty/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use rustc_data_structures::unord::UnordSet;
5050
use rustc_errors::ErrorGuaranteed;
5151
use rustc_hir as hir;
5252
use rustc_hir::def::{DefKind, DocLinkResMap};
53-
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId};
53+
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, DefIdSet, LocalDefId, LocalDefIdSet};
5454
use rustc_hir::hir_id::OwnerId;
5555
use rustc_hir::lang_items::{LangItem, LanguageItems};
5656
use rustc_hir::{Crate, ItemLocalId, TraitCandidate};

compiler/rustc_passes/src/reachable.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// makes all other generics or inline functions that it references
66
// reachable as well.
77

8-
use rustc_data_structures::fx::FxHashSet;
8+
use hir::def_id::LocalDefIdSet;
99
use rustc_hir as hir;
1010
use rustc_hir::def::{DefKind, Res};
1111
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -63,7 +63,7 @@ struct ReachableContext<'tcx> {
6363
tcx: TyCtxt<'tcx>,
6464
maybe_typeck_results: Option<&'tcx ty::TypeckResults<'tcx>>,
6565
// The set of items which must be exported in the linkage sense.
66-
reachable_symbols: FxHashSet<LocalDefId>,
66+
reachable_symbols: LocalDefIdSet,
6767
// A worklist of item IDs. Each item ID in this worklist will be inlined
6868
// and will be scanned for further references.
6969
// FIXME(eddyb) benchmark if this would be faster as a `VecDeque`.
@@ -175,7 +175,7 @@ impl<'tcx> ReachableContext<'tcx> {
175175

176176
// Step 2: Mark all symbols that the symbols on the worklist touch.
177177
fn propagate(&mut self) {
178-
let mut scanned = FxHashSet::default();
178+
let mut scanned = LocalDefIdSet::default();
179179
while let Some(search_item) = self.worklist.pop() {
180180
if !scanned.insert(search_item) {
181181
continue;
@@ -361,7 +361,7 @@ fn has_custom_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
361361
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
362362
}
363363

364-
fn reachable_set(tcx: TyCtxt<'_>, (): ()) -> FxHashSet<LocalDefId> {
364+
fn reachable_set(tcx: TyCtxt<'_>, (): ()) -> LocalDefIdSet {
365365
let effective_visibilities = &tcx.effective_visibilities(());
366366

367367
let any_library =

src/tools/miri/src/bin/miri.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,14 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
109109
// an empty result if `tcx.sess.opts.output_types.should_codegen()` is false.
110110
local_providers.exported_symbols = |tcx, cnum| {
111111
assert_eq!(cnum, LOCAL_CRATE);
112+
let reachable_set = tcx.with_stable_hashing_context(|hcx| {
113+
tcx.reachable_set(()).to_sorted(&hcx, true)
114+
});
112115
tcx.arena.alloc_from_iter(
113116
// This is based on:
114117
// https://github.com/rust-lang/rust/blob/2962e7c0089d5c136f4e9600b7abccfbbde4973d/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L62-L63
115118
// https://github.com/rust-lang/rust/blob/2962e7c0089d5c136f4e9600b7abccfbbde4973d/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L174
116-
tcx.reachable_set(()).iter().filter_map(|&local_def_id| {
119+
reachable_set.into_iter().filter_map(|&local_def_id| {
117120
// Do the same filtering that rustc does:
118121
// https://github.com/rust-lang/rust/blob/2962e7c0089d5c136f4e9600b7abccfbbde4973d/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L84-L102
119122
// Otherwise it may cause unexpected behaviours and ICEs

0 commit comments

Comments
 (0)