Skip to content

Commit bd3cd5d

Browse files
committed
Use an ItemId inside mir::GlobalAsm.
1 parent c676e35 commit bd3cd5d

File tree

7 files changed

+32
-21
lines changed

7 files changed

+32
-21
lines changed

compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ fn module_codegen(tcx: TyCtxt<'_>, cgu_name: rustc_span::Symbol) -> ModuleCodege
164164
MonoItem::Static(def_id) => {
165165
crate::constant::codegen_static(&mut cx.constants_cx, def_id)
166166
}
167-
MonoItem::GlobalAsm(hir_id) => {
168-
let item = cx.tcx.hir().expect_item(hir_id);
167+
MonoItem::GlobalAsm(item_id) => {
168+
let item = cx.tcx.hir().item(item_id);
169169
if let rustc_hir::ItemKind::GlobalAsm(rustc_hir::GlobalAsm { asm }) = item.kind {
170170
cx.global_asm.push_str(&*asm.as_str());
171171
cx.global_asm.push_str("\n\n");

compiler/rustc_codegen_cranelift/src/driver/jit.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,9 @@ pub(super) fn run_jit(tcx: TyCtxt<'_>, codegen_mode: CodegenMode) -> ! {
9393
MonoItem::Static(def_id) => {
9494
crate::constant::codegen_static(&mut cx.constants_cx, def_id);
9595
}
96-
MonoItem::GlobalAsm(hir_id) => {
97-
let item = cx.tcx.hir().expect_item(hir_id);
98-
tcx.sess
99-
.span_fatal(item.span, "Global asm is not supported in JIT mode");
96+
MonoItem::GlobalAsm(item_id) => {
97+
let item = cx.tcx.hir().item(item_id);
98+
tcx.sess.span_fatal(item.span, "Global asm is not supported in JIT mode");
10099
}
101100
}
102101
}

compiler/rustc_codegen_ssa/src/mono_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
3030
MonoItem::Static(def_id) => {
3131
cx.codegen_static(def_id, cx.tcx().is_mutable_static(def_id));
3232
}
33-
MonoItem::GlobalAsm(hir_id) => {
34-
let item = cx.tcx().hir().expect_item(hir_id);
33+
MonoItem::GlobalAsm(item_id) => {
34+
let item = cx.tcx().hir().item(item_id);
3535
if let hir::ItemKind::GlobalAsm(ref ga) = item.kind {
3636
cx.codegen_global_asm(ga);
3737
} else {

compiler/rustc_hir/src/hir.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2541,11 +2541,17 @@ impl VariantData<'hir> {
25412541
// The bodies for items are stored "out of line", in a separate
25422542
// hashmap in the `Crate`. Here we just record the hir-id of the item
25432543
// so it can fetched later.
2544-
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug)]
2544+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Encodable, Debug, Hash)]
25452545
pub struct ItemId {
25462546
pub id: HirId,
25472547
}
25482548

2549+
impl ItemId {
2550+
pub fn hir_id(&self) -> HirId {
2551+
self.id
2552+
}
2553+
}
2554+
25492555
/// An item
25502556
///
25512557
/// The name might be a dummy name in case of anonymous items
@@ -2559,6 +2565,12 @@ pub struct Item<'hir> {
25592565
pub span: Span,
25602566
}
25612567

2568+
impl Item<'_> {
2569+
pub fn item_id(&self) -> ItemId {
2570+
ItemId { id: self.hir_id }
2571+
}
2572+
}
2573+
25622574
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
25632575
#[derive(Encodable, Decodable, HashStable_Generic)]
25642576
pub enum Unsafety {

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
77
use rustc_data_structures::fx::FxHashMap;
88
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
99
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
10-
use rustc_hir::HirId;
10+
use rustc_hir::{HirId, ItemId};
1111
use rustc_session::config::OptLevel;
1212
use rustc_span::source_map::Span;
1313
use rustc_span::symbol::Symbol;
@@ -43,7 +43,7 @@ pub enum InstantiationMode {
4343
pub enum MonoItem<'tcx> {
4444
Fn(Instance<'tcx>),
4545
Static(DefId),
46-
GlobalAsm(HirId),
46+
GlobalAsm(ItemId),
4747
}
4848

4949
impl<'tcx> MonoItem<'tcx> {
@@ -71,8 +71,8 @@ impl<'tcx> MonoItem<'tcx> {
7171
match *self {
7272
MonoItem::Fn(instance) => tcx.symbol_name(instance),
7373
MonoItem::Static(def_id) => tcx.symbol_name(Instance::mono(tcx, def_id)),
74-
MonoItem::GlobalAsm(hir_id) => {
75-
let def_id = tcx.hir().local_def_id(hir_id);
74+
MonoItem::GlobalAsm(item_id) => {
75+
let def_id = tcx.hir().local_def_id(item_id.hir_id());
7676
SymbolName::new(tcx, &format!("global_asm_{:?}", def_id))
7777
}
7878
}
@@ -178,7 +178,7 @@ impl<'tcx> MonoItem<'tcx> {
178178
MonoItem::Static(def_id) => {
179179
def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
180180
}
181-
MonoItem::GlobalAsm(hir_id) => Some(hir_id),
181+
MonoItem::GlobalAsm(item_id) => Some(item_id.hir_id()),
182182
}
183183
.map(|hir_id| tcx.hir().span(hir_id))
184184
}
@@ -195,9 +195,9 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for MonoItem<'tcx> {
195195
MonoItem::Static(def_id) => {
196196
def_id.hash_stable(hcx, hasher);
197197
}
198-
MonoItem::GlobalAsm(node_id) => {
198+
MonoItem::GlobalAsm(item_id) => {
199199
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
200-
node_id.hash_stable(hcx, hasher);
200+
item_id.hash_stable(hcx, hasher);
201201
})
202202
}
203203
}
@@ -351,7 +351,7 @@ impl<'tcx> CodegenUnit<'tcx> {
351351
MonoItem::Static(def_id) => {
352352
def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
353353
}
354-
MonoItem::GlobalAsm(hir_id) => Some(hir_id),
354+
MonoItem::GlobalAsm(item_id) => Some(item_id.hir_id()),
355355
},
356356
item.symbol_name(tcx),
357357
)

compiler/rustc_mir/src/monomorphize/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> {
10301030
"RootCollector: ItemKind::GlobalAsm({})",
10311031
self.tcx.def_path_str(self.tcx.hir().local_def_id(item.hir_id).to_def_id())
10321032
);
1033-
self.output.push(dummy_spanned(MonoItem::GlobalAsm(item.hir_id)));
1033+
self.output.push(dummy_spanned(MonoItem::GlobalAsm(item.item_id())));
10341034
}
10351035
hir::ItemKind::Static(..) => {
10361036
let def_id = self.tcx.hir().local_def_id(item.hir_id).to_def_id();

compiler/rustc_mir/src/monomorphize/partitioning/default.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ fn characteristic_def_id_of_mono_item<'tcx>(
314314
Some(def_id)
315315
}
316316
MonoItem::Static(def_id) => Some(def_id),
317-
MonoItem::GlobalAsm(hir_id) => Some(tcx.hir().local_def_id(hir_id).to_def_id()),
317+
MonoItem::GlobalAsm(item_id) => Some(tcx.hir().local_def_id(item_id.hir_id()).to_def_id()),
318318
}
319319
}
320320

@@ -405,8 +405,8 @@ fn mono_item_visibility(
405405
Visibility::Hidden
406406
};
407407
}
408-
MonoItem::GlobalAsm(hir_id) => {
409-
let def_id = tcx.hir().local_def_id(*hir_id);
408+
MonoItem::GlobalAsm(item_id) => {
409+
let def_id = tcx.hir().local_def_id(item_id.hir_id());
410410
return if tcx.is_reachable_non_generic(def_id) {
411411
*can_be_internalized = false;
412412
default_visibility(tcx, def_id.to_def_id(), false)

0 commit comments

Comments
 (0)