diff options
| author | bors <bors@rust-lang.org> | 2021-02-16 22:14:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-02-16 22:14:32 +0000 |
| commit | 8fe989dd768f5dfdb0fc90933f3f74fa4579fefd (patch) | |
| tree | b343f190d8e1bca405fba9548778befb1986087a /compiler/rustc_middle/src/mir | |
| parent | a143517d44cac50b20cbd3a0b579addab40dd399 (diff) | |
| parent | 91d8e59ccaacf7df2af847037d30871ed0bd90b6 (diff) | |
| download | rust-8fe989dd768f5dfdb0fc90933f3f74fa4579fefd.tar.gz rust-8fe989dd768f5dfdb0fc90933f3f74fa4579fefd.zip | |
Auto merge of #81611 - cjgillot:meowner, r=estebank
Only store a LocalDefId in some HIR nodes Some HIR nodes are guaranteed to be HIR owners: Item, TraitItem, ImplItem, ForeignItem and MacroDef. As a consequence, we do not need to store the `HirId`'s `local_id`, and we can directly store a `LocalDefId`. This allows to avoid a bit of the dance with `tcx.hir().local_def_id` and `tcx.hir().local_def_id_to_hir_id` mappings.
Diffstat (limited to 'compiler/rustc_middle/src/mir')
| -rw-r--r-- | compiler/rustc_middle/src/mir/mono.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index eb13c89544c..6c2468b9ffe 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -7,7 +7,7 @@ use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; -use rustc_hir::HirId; +use rustc_hir::{HirId, ItemId}; use rustc_session::config::OptLevel; use rustc_span::source_map::Span; use rustc_span::symbol::Symbol; @@ -43,7 +43,7 @@ pub enum InstantiationMode { pub enum MonoItem<'tcx> { Fn(Instance<'tcx>), Static(DefId), - GlobalAsm(HirId), + GlobalAsm(ItemId), } impl<'tcx> MonoItem<'tcx> { @@ -71,9 +71,8 @@ impl<'tcx> MonoItem<'tcx> { match *self { MonoItem::Fn(instance) => tcx.symbol_name(instance), MonoItem::Static(def_id) => tcx.symbol_name(Instance::mono(tcx, def_id)), - MonoItem::GlobalAsm(hir_id) => { - let def_id = tcx.hir().local_def_id(hir_id); - SymbolName::new(tcx, &format!("global_asm_{:?}", def_id)) + MonoItem::GlobalAsm(item_id) => { + SymbolName::new(tcx, &format!("global_asm_{:?}", item_id.def_id)) } } } @@ -178,7 +177,7 @@ impl<'tcx> MonoItem<'tcx> { MonoItem::Static(def_id) => { def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) } - MonoItem::GlobalAsm(hir_id) => Some(hir_id), + MonoItem::GlobalAsm(item_id) => Some(item_id.hir_id()), } .map(|hir_id| tcx.hir().span(hir_id)) } @@ -195,9 +194,9 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for MonoItem<'tcx> { MonoItem::Static(def_id) => { def_id.hash_stable(hcx, hasher); } - MonoItem::GlobalAsm(node_id) => { + MonoItem::GlobalAsm(item_id) => { hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| { - node_id.hash_stable(hcx, hasher); + item_id.hash_stable(hcx, hasher); }) } } @@ -351,7 +350,7 @@ impl<'tcx> CodegenUnit<'tcx> { MonoItem::Static(def_id) => { def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id)) } - MonoItem::GlobalAsm(hir_id) => Some(hir_id), + MonoItem::GlobalAsm(item_id) => Some(item_id.hir_id()), }, item.symbol_name(tcx), ) |
