diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2021-01-30 19:18:48 +0100 | 
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2021-02-15 19:24:58 +0100 | 
| commit | bd3cd5dbed5f56fb44a14a20dd2113e3049d2565 (patch) | |
| tree | 83063aac7f1834f2bb10070fdfc42fa3787f4d31 | |
| parent | c676e358a506af3f97025fa248343552bddc57d9 (diff) | |
| download | rust-bd3cd5dbed5f56fb44a14a20dd2113e3049d2565.tar.gz rust-bd3cd5dbed5f56fb44a14a20dd2113e3049d2565.zip | |
Use an ItemId inside mir::GlobalAsm.
| -rw-r--r-- | compiler/rustc_codegen_cranelift/src/driver/aot.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_codegen_cranelift/src/driver/jit.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mono_item.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_hir/src/hir.rs | 14 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/mono.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/monomorphize/collector.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_mir/src/monomorphize/partitioning/default.rs | 6 | 
7 files changed, 32 insertions, 21 deletions
| diff --git a/compiler/rustc_codegen_cranelift/src/driver/aot.rs b/compiler/rustc_codegen_cranelift/src/driver/aot.rs index df89883f0bb..c9e503a43b9 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/aot.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/aot.rs @@ -164,8 +164,8 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege MonoItem::Static(def_id) => { crate::constant::codegen_static(&mut cx.constants_cx, def_id) } - MonoItem::GlobalAsm(hir_id) => { - let item = cx.tcx.hir().expect_item(hir_id); + MonoItem::GlobalAsm(item_id) => { + let item = cx.tcx.hir().item(item_id); if let rustc_hir::ItemKind::GlobalAsm(rustc_hir::GlobalAsm { asm }) = item.kind { cx.global_asm.push_str(&*asm.as_str()); cx.global_asm.push_str("\n\n"); diff --git a/compiler/rustc_codegen_cranelift/src/driver/jit.rs b/compiler/rustc_codegen_cranelift/src/driver/jit.rs index 2d14ff2c022..f784d8d27cc 100644 --- a/compiler/rustc_codegen_cranelift/src/driver/jit.rs +++ b/compiler/rustc_codegen_cranelift/src/driver/jit.rs @@ -93,10 +93,9 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, codegen_mode: CodegenMode) -> ! { MonoItem::Static(def_id) => { crate::constant::codegen_static(&mut cx.constants_cx, def_id); } - MonoItem::GlobalAsm(hir_id) => { - let item = cx.tcx.hir().expect_item(hir_id); - tcx.sess - .span_fatal(item.span, "Global asm is not supported in JIT mode"); + MonoItem::GlobalAsm(item_id) => { + let item = cx.tcx.hir().item(item_id); + tcx.sess.span_fatal(item.span, "Global asm is not supported in JIT mode"); } } } diff --git a/compiler/rustc_codegen_ssa/src/mono_item.rs b/compiler/rustc_codegen_ssa/src/mono_item.rs index 607b5459673..8e79193759e 100644 --- a/compiler/rustc_codegen_ssa/src/mono_item.rs +++ b/compiler/rustc_codegen_ssa/src/mono_item.rs @@ -30,8 +30,8 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> { MonoItem::Static(def_id) => { cx.codegen_static(def_id, cx.tcx().is_mutable_static(def_id)); } - MonoItem::GlobalAsm(hir_id) => { - let item = cx.tcx().hir().expect_item(hir_id); + MonoItem::GlobalAsm(item_id) => { + let item = cx.tcx().hir().item(item_id); if let hir::ItemKind::GlobalAsm(ref ga) = item.kind { cx.codegen_global_asm(ga); } else { diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 58dd3109b34..5329444a5e0 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2541,11 +2541,17 @@ impl VariantData<'hir> { // The bodies for items are stored "out of line", in a separate // hashmap in the `Crate`. Here we just record the hir-id of the item // so it can fetched later. -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug, Hash)] pub struct ItemId { pub id: HirId, } +impl ItemId { + pub fn hir_id(&self) -> HirId { + self.id + } +} + /// An item /// /// The name might be a dummy name in case of anonymous items @@ -2559,6 +2565,12 @@ pub struct Item<'hir> { pub span: Span, } +impl Item<'_> { + pub fn item_id(&self) -> ItemId { + ItemId { id: self.hir_id } + } +} + #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[derive(Encodable, Decodable, HashStable_Generic)] pub enum Unsafety { diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index eb13c89544c..a4b641ef83a 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,8 +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); + MonoItem::GlobalAsm(item_id) => { + let def_id = tcx.hir().local_def_id(item_id.hir_id()); SymbolName::new(tcx, &format!("global_asm_{:?}", def_id)) } } @@ -178,7 +178,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 +195,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 +351,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), ) diff --git a/compiler/rustc_mir/src/monomorphize/collector.rs b/compiler/rustc_mir/src/monomorphize/collector.rs index 75f80f69bea..1cf809bef45 100644 --- a/compiler/rustc_mir/src/monomorphize/collector.rs +++ b/compiler/rustc_mir/src/monomorphize/collector.rs @@ -1030,7 +1030,7 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> { "RootCollector: ItemKind::GlobalAsm({})", self.tcx.def_path_str(self.tcx.hir().local_def_id(item.hir_id).to_def_id()) ); - self.output.push(dummy_spanned(MonoItem::GlobalAsm(item.hir_id))); + self.output.push(dummy_spanned(MonoItem::GlobalAsm(item.item_id()))); } hir::ItemKind::Static(..) => { let def_id = self.tcx.hir().local_def_id(item.hir_id).to_def_id(); diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs index d5a845dd76f..f814da786e5 100644 --- a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs +++ b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs @@ -314,7 +314,7 @@ fn characteristic_def_id_of_mono_item<'tcx>( Some(def_id) } MonoItem::Static(def_id) => Some(def_id), - MonoItem::GlobalAsm(hir_id) => Some(tcx.hir().local_def_id(hir_id).to_def_id()), + MonoItem::GlobalAsm(item_id) => Some(tcx.hir().local_def_id(item_id.hir_id()).to_def_id()), } } @@ -405,8 +405,8 @@ fn mono_item_visibility( Visibility::Hidden }; } - MonoItem::GlobalAsm(hir_id) => { - let def_id = tcx.hir().local_def_id(*hir_id); + MonoItem::GlobalAsm(item_id) => { + let def_id = tcx.hir().local_def_id(item_id.hir_id()); return if tcx.is_reachable_non_generic(def_id) { *can_be_internalized = false; default_visibility(tcx, def_id.to_def_id(), false) | 
