Skip to content

Commit 6a5b281

Browse files
committed
Return a FxHashSet<LocalDefId> from mir_keys query
1 parent efe30de commit 6a5b281

File tree

5 files changed

+47
-45
lines changed

5 files changed

+47
-45
lines changed

src/librustc_metadata/rmeta/encoder.rs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ use log::{debug, trace};
55
use rustc_ast::ast::{self, Ident};
66
use rustc_ast::attr;
77
use rustc_data_structures::fingerprint::Fingerprint;
8-
use rustc_data_structures::fx::FxHashMap;
8+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
99
use rustc_data_structures::stable_hasher::StableHasher;
1010
use rustc_data_structures::sync::{join, Lrc};
1111
use rustc_hir as hir;
1212
use rustc_hir::def::CtorKind;
13-
use rustc_hir::def_id::DefIdSet;
1413
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
1514
use rustc_hir::definitions::DefPathTable;
1615
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
@@ -644,8 +643,8 @@ impl EncodeContext<'tcx> {
644643
self.encode_generics(def_id);
645644
self.encode_explicit_predicates(def_id);
646645
self.encode_inferred_outlives(def_id);
647-
self.encode_optimized_mir(def_id);
648-
self.encode_promoted_mir(def_id);
646+
self.encode_optimized_mir(def_id.expect_local());
647+
self.encode_promoted_mir(def_id.expect_local());
649648
}
650649

651650
fn encode_enum_variant_ctor(&mut self, def: &ty::AdtDef, index: VariantIdx) {
@@ -683,8 +682,8 @@ impl EncodeContext<'tcx> {
683682
self.encode_generics(def_id);
684683
self.encode_explicit_predicates(def_id);
685684
self.encode_inferred_outlives(def_id);
686-
self.encode_optimized_mir(def_id);
687-
self.encode_promoted_mir(def_id);
685+
self.encode_optimized_mir(def_id.expect_local());
686+
self.encode_promoted_mir(def_id.expect_local());
688687
}
689688

690689
fn encode_info_for_mod(
@@ -786,8 +785,8 @@ impl EncodeContext<'tcx> {
786785
self.encode_generics(def_id);
787786
self.encode_explicit_predicates(def_id);
788787
self.encode_inferred_outlives(def_id);
789-
self.encode_optimized_mir(def_id);
790-
self.encode_promoted_mir(def_id);
788+
self.encode_optimized_mir(def_id.expect_local());
789+
self.encode_promoted_mir(def_id.expect_local());
791790
}
792791

793792
fn encode_generics(&mut self, def_id: DefId) {
@@ -896,8 +895,8 @@ impl EncodeContext<'tcx> {
896895
self.encode_inferred_outlives(def_id);
897896

898897
// This should be kept in sync with `PrefetchVisitor.visit_trait_item`.
899-
self.encode_optimized_mir(def_id);
900-
self.encode_promoted_mir(def_id);
898+
self.encode_optimized_mir(def_id.expect_local());
899+
self.encode_promoted_mir(def_id.expect_local());
901900
}
902901

903902
fn metadata_output_only(&self) -> bool {
@@ -985,8 +984,8 @@ impl EncodeContext<'tcx> {
985984
hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::TyAlias(..) => false,
986985
};
987986
if mir {
988-
self.encode_optimized_mir(def_id);
989-
self.encode_promoted_mir(def_id);
987+
self.encode_optimized_mir(def_id.expect_local());
988+
self.encode_promoted_mir(def_id.expect_local());
990989
}
991990
}
992991

@@ -1004,17 +1003,17 @@ impl EncodeContext<'tcx> {
10041003
self.lazy(param_names.iter().map(|ident| ident.name))
10051004
}
10061005

1007-
fn encode_optimized_mir(&mut self, def_id: DefId) {
1006+
fn encode_optimized_mir(&mut self, def_id: LocalDefId) {
10081007
debug!("EntryBuilder::encode_mir({:?})", def_id);
10091008
if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) {
1010-
record!(self.tables.mir[def_id] <- self.tcx.optimized_mir(def_id));
1009+
record!(self.tables.mir[def_id.to_def_id()] <- self.tcx.optimized_mir(def_id));
10111010
}
10121011
}
10131012

1014-
fn encode_promoted_mir(&mut self, def_id: DefId) {
1013+
fn encode_promoted_mir(&mut self, def_id: LocalDefId) {
10151014
debug!("EncodeContext::encode_promoted_mir({:?})", def_id);
10161015
if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) {
1017-
record!(self.tables.promoted_mir[def_id] <- self.tcx.promoted_mir(def_id));
1016+
record!(self.tables.promoted_mir[def_id.to_def_id()] <- self.tcx.promoted_mir(def_id));
10181017
}
10191018
}
10201019

@@ -1282,8 +1281,8 @@ impl EncodeContext<'tcx> {
12821281
_ => false,
12831282
};
12841283
if mir {
1285-
self.encode_optimized_mir(def_id);
1286-
self.encode_promoted_mir(def_id);
1284+
self.encode_optimized_mir(def_id.expect_local());
1285+
self.encode_promoted_mir(def_id.expect_local());
12871286
}
12881287
}
12891288

@@ -1316,8 +1315,7 @@ impl EncodeContext<'tcx> {
13161315
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
13171316
let ty = self.tcx.typeck_tables_of(def_id).node_type(hir_id);
13181317

1319-
let def_id = def_id.to_def_id();
1320-
record!(self.tables.kind[def_id] <- match ty.kind {
1318+
record!(self.tables.kind[def_id.to_def_id()] <- match ty.kind {
13211319
ty::Generator(..) => {
13221320
let data = self.tcx.generator_kind(def_id).unwrap();
13231321
EntryKind::Generator(data)
@@ -1327,14 +1325,14 @@ impl EncodeContext<'tcx> {
13271325

13281326
_ => bug!("closure that is neither generator nor closure"),
13291327
});
1330-
record!(self.tables.visibility[def_id] <- ty::Visibility::Public);
1331-
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
1332-
record!(self.tables.attributes[def_id] <- &self.tcx.get_attrs(def_id)[..]);
1333-
self.encode_item_type(def_id);
1328+
record!(self.tables.visibility[def_id.to_def_id()] <- ty::Visibility::Public);
1329+
record!(self.tables.span[def_id.to_def_id()] <- self.tcx.def_span(def_id));
1330+
record!(self.tables.attributes[def_id.to_def_id()] <- &self.tcx.get_attrs(def_id.to_def_id())[..]);
1331+
self.encode_item_type(def_id.to_def_id());
13341332
if let ty::Closure(def_id, substs) = ty.kind {
13351333
record!(self.tables.fn_sig[def_id] <- substs.as_closure().sig());
13361334
}
1337-
self.encode_generics(def_id);
1335+
self.encode_generics(def_id.to_def_id());
13381336
self.encode_optimized_mir(def_id);
13391337
self.encode_promoted_mir(def_id);
13401338
}
@@ -1344,16 +1342,15 @@ impl EncodeContext<'tcx> {
13441342
let id = self.tcx.hir().as_local_hir_id(def_id);
13451343
let body_id = self.tcx.hir().body_owned_by(id);
13461344
let const_data = self.encode_rendered_const_for_body(body_id);
1347-
let def_id = def_id.to_def_id();
13481345
let qualifs = self.tcx.mir_const_qualif(def_id);
13491346

1350-
record!(self.tables.kind[def_id] <- EntryKind::Const(qualifs, const_data));
1351-
record!(self.tables.visibility[def_id] <- ty::Visibility::Public);
1352-
record!(self.tables.span[def_id] <- self.tcx.def_span(def_id));
1353-
self.encode_item_type(def_id);
1354-
self.encode_generics(def_id);
1355-
self.encode_explicit_predicates(def_id);
1356-
self.encode_inferred_outlives(def_id);
1347+
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::Const(qualifs, const_data));
1348+
record!(self.tables.visibility[def_id.to_def_id()] <- ty::Visibility::Public);
1349+
record!(self.tables.span[def_id.to_def_id()] <- self.tcx.def_span(def_id));
1350+
self.encode_item_type(def_id.to_def_id());
1351+
self.encode_generics(def_id.to_def_id());
1352+
self.encode_explicit_predicates(def_id.to_def_id());
1353+
self.encode_inferred_outlives(def_id.to_def_id());
13571354
self.encode_optimized_mir(def_id);
13581355
self.encode_promoted_mir(def_id);
13591356
}
@@ -1726,12 +1723,11 @@ impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'tcx> {
17261723
/// Only a subset of the queries are actually prefetched to keep this code smaller.
17271724
struct PrefetchVisitor<'tcx> {
17281725
tcx: TyCtxt<'tcx>,
1729-
mir_keys: &'tcx DefIdSet,
1726+
mir_keys: &'tcx FxHashSet<LocalDefId>,
17301727
}
17311728

17321729
impl<'tcx> PrefetchVisitor<'tcx> {
17331730
fn prefetch_mir(&self, def_id: LocalDefId) {
1734-
let def_id = def_id.to_def_id();
17351731
if self.mir_keys.contains(&def_id) {
17361732
self.tcx.optimized_mir(def_id);
17371733
self.tcx.promoted_mir(def_id);

src/librustc_middle/arena.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ macro_rules! arena_types {
3434
rustc_hir::def_id::DefId,
3535
rustc_middle::ty::subst::SubstsRef<$tcx>
3636
)>,
37-
[few, decode] mir_keys: rustc_hir::def_id::DefIdSet,
37+
[few, decode] collect_and_partition_mono_items: rustc_hir::def_id::DefIdSet,
38+
[few, decode] mir_keys: rustc_data_structures::fx::FxHashSet<rustc_hir::def_id::LocalDefId>,
3839
[decode] specialization_graph: rustc_middle::traits::specialization_graph::Graph,
3940
[] region_scope_tree: rustc_middle::middle::region::ScopeTree,
4041
[] item_local_set: rustc_hir::ItemLocalSet,

src/librustc_middle/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ rustc_queries! {
156156
/// Set of all the `DefId`s in this crate that have MIR associated with
157157
/// them. This includes all the body owners, but also things like struct
158158
/// constructors.
159-
query mir_keys(_: CrateNum) -> &'tcx DefIdSet {
159+
query mir_keys(_: CrateNum) -> &'tcx FxHashSet<LocalDefId> {
160160
desc { "getting a list of all mir_keys" }
161161
}
162162

src/librustc_mir/transform/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::{shim, util};
22
use required_consts::RequiredConstsVisitor;
33
use rustc_ast::ast;
4+
use rustc_data_structures::fx::FxHashSet;
45
use rustc_hir as hir;
5-
use rustc_hir::def_id::{CrateNum, DefId, DefIdSet, LocalDefId, LOCAL_CRATE};
6+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
67
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
78
use rustc_index::vec::IndexVec;
89
use rustc_middle::mir::visit::Visitor as _;
@@ -54,24 +55,24 @@ pub(crate) fn provide(providers: &mut Providers<'_>) {
5455
}
5556

5657
fn is_mir_available(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
57-
tcx.mir_keys(def_id.krate).contains(&def_id)
58+
tcx.mir_keys(def_id.krate).contains(&def_id.expect_local())
5859
}
5960

6061
/// Finds the full set of `DefId`s within the current crate that have
6162
/// MIR associated with them.
62-
fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet {
63+
fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &FxHashSet<LocalDefId> {
6364
assert_eq!(krate, LOCAL_CRATE);
6465

65-
let mut set = DefIdSet::default();
66+
let mut set = FxHashSet::default();
6667

6768
// All body-owners have MIR associated with them.
68-
set.extend(tcx.body_owners().map(LocalDefId::to_def_id));
69+
set.extend(tcx.body_owners());
6970

7071
// Additionally, tuple struct/variant constructors have MIR, but
7172
// they don't have a BodyId, so we need to build them separately.
7273
struct GatherCtors<'a, 'tcx> {
7374
tcx: TyCtxt<'tcx>,
74-
set: &'a mut DefIdSet,
75+
set: &'a mut FxHashSet<LocalDefId>,
7576
}
7677
impl<'a, 'tcx> Visitor<'tcx> for GatherCtors<'a, 'tcx> {
7778
fn visit_variant_data(
@@ -83,7 +84,7 @@ fn mir_keys(tcx: TyCtxt<'_>, krate: CrateNum) -> &DefIdSet {
8384
_: Span,
8485
) {
8586
if let hir::VariantData::Tuple(_, hir_id) = *v {
86-
self.set.insert(self.tcx.hir().local_def_id(hir_id).to_def_id());
87+
self.set.insert(self.tcx.hir().local_def_id(hir_id));
8788
}
8889
intravisit::walk_struct_def(self, v)
8990
}

src/librustc_mir/util/pretty.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,5 +868,9 @@ fn write_user_type_annotations(body: &Body<'_>, w: &mut dyn Write) -> io::Result
868868
}
869869

870870
pub fn dump_mir_def_ids(tcx: TyCtxt<'_>, single: Option<DefId>) -> Vec<DefId> {
871-
if let Some(i) = single { vec![i] } else { tcx.mir_keys(LOCAL_CRATE).iter().cloned().collect() }
871+
if let Some(i) = single {
872+
vec![i]
873+
} else {
874+
tcx.mir_keys(LOCAL_CRATE).iter().map(|def_id| def_id.to_def_id()).collect()
875+
}
872876
}

0 commit comments

Comments
 (0)