From cebbba081e4609099df3921de8a1422b7ea52599 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 30 Jan 2021 17:47:51 +0100 Subject: Only store a LocalDefId in hir::Item. Items are guaranteed to be HIR owner. --- compiler/rustc_interface/src/proc_macro_decls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler/rustc_interface') diff --git a/compiler/rustc_interface/src/proc_macro_decls.rs b/compiler/rustc_interface/src/proc_macro_decls.rs index de08a4c8242..d0262935c89 100644 --- a/compiler/rustc_interface/src/proc_macro_decls.rs +++ b/compiler/rustc_interface/src/proc_macro_decls.rs @@ -26,7 +26,7 @@ struct Finder<'tcx> { impl<'v> ItemLikeVisitor<'v> for Finder<'_> { fn visit_item(&mut self, item: &hir::Item<'_>) { if self.tcx.sess.contains_name(&item.attrs, sym::rustc_proc_macro_decls) { - self.decls = Some(item.hir_id); + self.decls = Some(item.hir_id()); } } -- cgit 1.4.1-3-g733a5 From ff14cac621ce63d848abf615e45acd86fec32f50 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 31 Jan 2021 17:58:57 +0100 Subject: Index Modules using their LocalDefId. --- compiler/rustc_ast_lowering/src/item.rs | 6 +++--- compiler/rustc_ast_lowering/src/lib.rs | 10 +++++----- compiler/rustc_hir/src/hir.rs | 2 +- compiler/rustc_interface/src/passes.rs | 19 ++++++++----------- compiler/rustc_lint/src/late.rs | 2 +- compiler/rustc_middle/src/hir/mod.rs | 6 +----- compiler/rustc_passes/src/hir_id_validator.rs | 9 +++------ compiler/rustc_typeck/src/impl_wf_check.rs | 2 +- compiler/rustc_typeck/src/lib.rs | 4 ++-- src/librustdoc/core.rs | 5 ++--- 10 files changed, 27 insertions(+), 38 deletions(-) (limited to 'compiler/rustc_interface') diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index f88c73aee53..4a0c4459905 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -35,10 +35,10 @@ impl ItemLowerer<'_, '_, '_> { impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> { fn visit_mod(&mut self, m: &'a Mod, _s: Span, _attrs: &[Attribute], n: NodeId) { - let hir_id = self.lctx.lower_node_id(n); + let def_id = self.lctx.lower_node_id(n).expect_owner(); self.lctx.modules.insert( - hir_id, + def_id, hir::ModuleItems { items: BTreeSet::new(), trait_items: BTreeSet::new(), @@ -48,7 +48,7 @@ impl<'a> Visitor<'a> for ItemLowerer<'a, '_, '_> { ); let old = self.lctx.current_module; - self.lctx.current_module = hir_id; + self.lctx.current_module = def_id; visit::walk_mod(self, m); self.lctx.current_module = old; } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 3cb214464c0..8a12206a4c2 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -48,7 +48,7 @@ use rustc_data_structures::sync::Lrc; use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res}; -use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX}; +use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, CRATE_DEF_ID}; use rustc_hir::definitions::{DefKey, DefPathData, Definitions}; use rustc_hir::intravisit; use rustc_hir::{ConstArg, GenericArg, ParamName}; @@ -110,7 +110,7 @@ struct LoweringContext<'a, 'hir: 'a> { trait_impls: BTreeMap>, - modules: BTreeMap, + modules: BTreeMap, generator_kind: Option, @@ -158,7 +158,7 @@ struct LoweringContext<'a, 'hir: 'a> { /// vector. in_scope_lifetimes: Vec, - current_module: hir::HirId, + current_module: LocalDefId, type_def_lifetime_params: DefIdMap, @@ -314,8 +314,8 @@ pub fn lower_crate<'a, 'hir>( is_in_dyn_type: false, anonymous_lifetime_mode: AnonymousLifetimeMode::PassThrough, type_def_lifetime_params: Default::default(), - current_module: hir::CRATE_HIR_ID, - current_hir_id_owner: vec![(LocalDefId { local_def_index: CRATE_DEF_INDEX }, 0)], + current_module: CRATE_DEF_ID, + current_hir_id_owner: vec![(CRATE_DEF_ID, 0)], item_local_id_counters: Default::default(), node_id_to_hir_id: IndexVec::new(), generator_kind: None, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index a0950958455..c9c670fdd44 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -668,7 +668,7 @@ pub struct Crate<'hir> { /// A list of modules written out in the order in which they /// appear in the crate. This includes the main crate module. - pub modules: BTreeMap, + pub modules: BTreeMap, /// A list of proc macro HirIds, written out in the order in which /// they are declared in the static array generated by proc_macro_harness. pub proc_macros: Vec, diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 56aa3939b22..544da4cd9aa 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -831,12 +831,11 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> { }, { par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| { - let local_def_id = tcx.hir().local_def_id(module); - tcx.ensure().check_mod_loops(local_def_id); - tcx.ensure().check_mod_attrs(local_def_id); - tcx.ensure().check_mod_naked_functions(local_def_id); - tcx.ensure().check_mod_unstable_api_usage(local_def_id); - tcx.ensure().check_mod_const_bodies(local_def_id); + tcx.ensure().check_mod_loops(module); + tcx.ensure().check_mod_attrs(module); + tcx.ensure().check_mod_naked_functions(module); + tcx.ensure().check_mod_unstable_api_usage(module); + tcx.ensure().check_mod_const_bodies(module); }); } ); @@ -861,10 +860,8 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> { // "not all control paths return a value" is reported here. // // maybe move the check to a MIR pass? - let local_def_id = tcx.hir().local_def_id(module); - - tcx.ensure().check_mod_liveness(local_def_id); - tcx.ensure().check_mod_intrinsics(local_def_id); + tcx.ensure().check_mod_liveness(module); + tcx.ensure().check_mod_intrinsics(module); }); }); } @@ -926,7 +923,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> { { sess.time("privacy_checking_modules", || { par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| { - tcx.ensure().check_mod_privacy(tcx.hir().local_def_id(module)); + tcx.ensure().check_mod_privacy(module); }); }); } diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index c76f8eea201..e019b621aa3 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -496,7 +496,7 @@ pub fn check_crate<'tcx, T: LateLintPass<'tcx>>( tcx.sess.time("module_lints", || { // Run per-module lints par_iter(&tcx.hir().krate().modules).for_each(|(&module, _)| { - tcx.ensure().lint_mod(tcx.hir().local_def_id(module)); + tcx.ensure().lint_mod(module); }); }); }, diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index 6934e06d4c2..5f9cf8771ea 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -73,11 +73,7 @@ pub fn provide(providers: &mut Providers) { }; providers.hir_crate = |tcx, _| tcx.untracked_crate; providers.index_hir = map::index_hir; - providers.hir_module_items = |tcx, id| { - let hir = tcx.hir(); - let module = hir.local_def_id_to_hir_id(id); - &tcx.untracked_crate.modules[&module] - }; + providers.hir_module_items = |tcx, id| &tcx.untracked_crate.modules[&id]; providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature; providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref(); providers.def_span = |tcx, def_id| tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP); diff --git a/compiler/rustc_passes/src/hir_id_validator.rs b/compiler/rustc_passes/src/hir_id_validator.rs index 0f1ff71cc2f..79e3b5952ac 100644 --- a/compiler/rustc_passes/src/hir_id_validator.rs +++ b/compiler/rustc_passes/src/hir_id_validator.rs @@ -14,12 +14,9 @@ pub fn check_crate(tcx: TyCtxt<'_>) { let errors = Lock::new(Vec::new()); let hir_map = tcx.hir(); - par_iter(&hir_map.krate().modules).for_each(|(module_id, _)| { - let local_def_id = hir_map.local_def_id(*module_id); - hir_map.visit_item_likes_in_module( - local_def_id, - &mut OuterVisitor { hir_map, errors: &errors }, - ); + par_iter(&hir_map.krate().modules).for_each(|(&module_id, _)| { + hir_map + .visit_item_likes_in_module(module_id, &mut OuterVisitor { hir_map, errors: &errors }); }); let errors = errors.into_inner(); diff --git a/compiler/rustc_typeck/src/impl_wf_check.rs b/compiler/rustc_typeck/src/impl_wf_check.rs index d8ae0e42546..7713381e62e 100644 --- a/compiler/rustc_typeck/src/impl_wf_check.rs +++ b/compiler/rustc_typeck/src/impl_wf_check.rs @@ -59,7 +59,7 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) { // but it's one that we must perform earlier than the rest of // WfCheck. for &module in tcx.hir().krate().modules.keys() { - tcx.ensure().check_mod_impl_wf(tcx.hir().local_def_id(module)); + tcx.ensure().check_mod_impl_wf(module); } } diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index 22d95b8bcc0..6ddc26efeae 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -369,7 +369,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> { tcx.sess.track_errors(|| { tcx.sess.time("type_collecting", || { for &module in tcx.hir().krate().modules.keys() { - tcx.ensure().collect_mod_item_types(tcx.hir().local_def_id(module)); + tcx.ensure().collect_mod_item_types(module); } }); })?; @@ -401,7 +401,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> { // NOTE: This is copy/pasted in librustdoc/core.rs and should be kept in sync. tcx.sess.time("item_types_checking", || { for &module in tcx.hir().krate().modules.keys() { - tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module)); + tcx.ensure().check_mod_item_types(module); } }); diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index a20e9dec33b..d79c47bbe3d 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -479,7 +479,7 @@ crate fn run_global_ctxt( // NOTE: This is copy/pasted from typeck/lib.rs and should be kept in sync with those changes. tcx.sess.time("item_types_checking", || { for &module in tcx.hir().krate().modules.keys() { - tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module)); + tcx.ensure().check_mod_item_types(module); } }); tcx.sess.abort_if_errors(); @@ -488,8 +488,7 @@ crate fn run_global_ctxt( }); tcx.sess.time("check_mod_attrs", || { for &module in tcx.hir().krate().modules.keys() { - let local_def_id = tcx.hir().local_def_id(module); - tcx.ensure().check_mod_attrs(local_def_id); + tcx.ensure().check_mod_attrs(module); } }); -- cgit 1.4.1-3-g733a5