Skip to content

Commit fb5615a

Browse files
committed
Auto merge of #71292 - marmeladema:queries-local-def-id, r=eddyb
Convert more queries to use `LocalDefId` This PR is based on commits in #71215 and should partially solve #70853
2 parents 6db2094 + 1349272 commit fb5615a

File tree

43 files changed

+288
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+288
-239
lines changed

src/librustc_codegen_llvm/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
290290
spflags |= DISPFlags::SPFlagOptimized;
291291
}
292292
if let Some((id, _)) = self.tcx.entry_fn(LOCAL_CRATE) {
293-
if id == def_id {
293+
if id.to_def_id() == def_id {
294294
spflags |= DISPFlags::SPFlagMainSubprogram;
295295
}
296296
}

src/librustc_codegen_ssa/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_data_structures::fx::FxHashMap;
3030
use rustc_data_structures::profiling::print_time_passes_entry;
3131
use rustc_data_structures::sync::{par_iter, Lock, ParallelIterator};
3232
use rustc_hir as hir;
33-
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
33+
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
3434
use rustc_hir::lang_items::StartFnLangItem;
3535
use rustc_index::vec::Idx;
3636
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
@@ -397,7 +397,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
397397
None => return None,
398398
};
399399

400-
let instance = Instance::mono(cx.tcx(), main_def_id);
400+
let instance = Instance::mono(cx.tcx(), main_def_id.to_def_id());
401401

402402
if !cx.codegen_unit().contains_item(&MonoItem::Fn(instance)) {
403403
// We want to create the wrapper in the same codegen unit as Rust's main
@@ -416,7 +416,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
416416
cx: &'a Bx::CodegenCx,
417417
sp: Span,
418418
rust_main: Bx::Value,
419-
rust_main_def_id: DefId,
419+
rust_main_def_id: LocalDefId,
420420
use_start_lang_item: bool,
421421
) -> Bx::Function {
422422
// The entry function is either `int main(void)` or `int main(int argc, char **argv)`,

src/librustc_interface/passes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
835835
});
836836

837837
sess.time("MIR_borrow_checking", || {
838-
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id.to_def_id()));
838+
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
839839
});
840840

841841
sess.time("dumping_chalk_like_clauses", || {

src/librustc_interface/queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<'tcx> Queries<'tcx> {
293293
_ => return,
294294
};
295295

296-
let attrs = &*tcx.get_attrs(def_id);
296+
let attrs = &*tcx.get_attrs(def_id.to_def_id());
297297
let attrs = attrs.iter().filter(|attr| attr.check_name(sym::rustc_error));
298298
for attr in attrs {
299299
match attr.meta_item_list() {

src/librustc_lint/lib.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mod unused;
5656

5757
use rustc_ast::ast;
5858
use rustc_hir as hir;
59-
use rustc_hir::def_id::DefId;
59+
use rustc_hir::def_id::LocalDefId;
6060
use rustc_middle::ty::query::Providers;
6161
use rustc_middle::ty::TyCtxt;
6262
use rustc_session::lint::builtin::{
@@ -90,12 +90,8 @@ pub fn provide(providers: &mut Providers<'_>) {
9090
*providers = Providers { lint_mod, ..*providers };
9191
}
9292

93-
fn lint_mod(tcx: TyCtxt<'_>, module_def_id: DefId) {
94-
late::late_lint_mod(
95-
tcx,
96-
module_def_id.expect_local(),
97-
BuiltinCombinedModuleLateLintPass::new(),
98-
);
93+
fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
94+
late::late_lint_mod(tcx, module_def_id, BuiltinCombinedModuleLateLintPass::new());
9995
}
10096

10197
macro_rules! pre_expansion_lint_passes {

src/librustc_metadata/rmeta/encoder.rs

+31-35
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

+2-1
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/mir/mono.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::base_n;
77
use rustc_data_structures::fingerprint::Fingerprint;
88
use rustc_data_structures::fx::FxHashMap;
99
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
10-
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
10+
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
1111
use rustc_hir::HirId;
1212
use rustc_session::config::OptLevel;
1313
use rustc_span::source_map::Span;
@@ -95,7 +95,7 @@ impl<'tcx> MonoItem<'tcx> {
9595
// linkage, then we'll be creating a globally shared version.
9696
if self.explicit_linkage(tcx).is_some()
9797
|| !instance.def.generates_cgu_internal_copy(tcx)
98-
|| Some(instance.def_id()) == entry_def_id
98+
|| Some(instance.def_id()) == entry_def_id.map(LocalDefId::to_def_id)
9999
{
100100
return InstantiationMode::GloballyShared { may_conflict: false };
101101
}

0 commit comments

Comments
 (0)