Skip to content

Commit 8876ca3

Browse files
committedMar 6, 2022
Auto merge of #94597 - nnethercote:ConstAllocation, r=fee1-dead
Introduce `ConstAllocation`. Currently some `Allocation`s are interned, some are not, and it's very hard to tell at a use point which is which. This commit introduces `ConstAllocation` for the known-interned ones, which makes the division much clearer. `ConstAllocation::inner()` is used to get the underlying `Allocation`. In some places it's natural to use an `Allocation`, in some it's natural to use a `ConstAllocation`, and in some places there's no clear choice. I've tried to make things look as nice as possible, while generally favouring `ConstAllocation`, which is the type that embodies more information. This does require quite a few calls to `inner()`. The commit also tweaks how `PartialOrd` works for `Interned`. The previous code was too clever by half, building on `T: Ord` to make the code shorter. That caused problems with deriving `PartialOrd` and `Ord` for `ConstAllocation`, so I changed it to build on `T: PartialOrd`, which is slightly more verbose but much more standard and avoided the problems. r? `@fee1-dead`
2 parents 38a0b81 + 4852291 commit 8876ca3

File tree

30 files changed

+166
-119
lines changed

30 files changed

+166
-119
lines changed
 

‎compiler/rustc_codegen_cranelift/src/constant.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
44
use rustc_errors::ErrorGuaranteed;
55
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
66
use rustc_middle::mir::interpret::{
7-
read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
7+
read_target_uint, AllocId, ConstAllocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
88
};
99
use rustc_middle::ty::ConstKind;
1010
use rustc_span::DUMMY_SP;
@@ -202,7 +202,7 @@ pub(crate) fn codegen_const_value<'tcx>(
202202
&mut fx.constants_cx,
203203
fx.module,
204204
alloc_id,
205-
alloc.mutability,
205+
alloc.inner().mutability,
206206
);
207207
let local_data_id =
208208
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
@@ -257,11 +257,15 @@ pub(crate) fn codegen_const_value<'tcx>(
257257

258258
pub(crate) fn pointer_for_allocation<'tcx>(
259259
fx: &mut FunctionCx<'_, '_, 'tcx>,
260-
alloc: &'tcx Allocation,
260+
alloc: ConstAllocation<'tcx>,
261261
) -> crate::pointer::Pointer {
262262
let alloc_id = fx.tcx.create_memory_alloc(alloc);
263-
let data_id =
264-
data_id_for_alloc_id(&mut fx.constants_cx, &mut *fx.module, alloc_id, alloc.mutability);
263+
let data_id = data_id_for_alloc_id(
264+
&mut fx.constants_cx,
265+
&mut *fx.module,
266+
alloc_id,
267+
alloc.inner().mutability,
268+
);
265269

266270
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
267271
if fx.clif_comments.enabled() {
@@ -361,7 +365,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
361365
let data_id = *cx.anon_allocs.entry(alloc_id).or_insert_with(|| {
362366
module
363367
.declare_anonymous_data(
364-
alloc.mutability == rustc_hir::Mutability::Mut,
368+
alloc.inner().mutability == rustc_hir::Mutability::Mut,
365369
false,
366370
)
367371
.unwrap()
@@ -386,6 +390,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
386390
}
387391

388392
let mut data_ctx = DataContext::new();
393+
let alloc = alloc.inner();
389394
data_ctx.set_align(alloc.align.bytes());
390395

391396
if let Some(section_name) = section_name {
@@ -429,7 +434,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
429434
continue;
430435
}
431436
GlobalAlloc::Memory(target_alloc) => {
432-
data_id_for_alloc_id(cx, module, alloc_id, target_alloc.mutability)
437+
data_id_for_alloc_id(cx, module, alloc_id, target_alloc.inner().mutability)
433438
}
434439
GlobalAlloc::Static(def_id) => {
435440
if tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::THREAD_LOCAL)

‎compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
159159
let idx_bytes = match idx_const {
160160
ConstValue::ByRef { alloc, offset } => {
161161
let size = Size::from_bytes(4 * ret_lane_count /* size_of([u32; ret_lane_count]) */);
162-
alloc.get_bytes(fx, alloc_range(offset, size)).unwrap()
162+
alloc.inner().get_bytes(fx, alloc_range(offset, size)).unwrap()
163163
}
164164
_ => unreachable!("{:?}", idx_const),
165165
};

‎compiler/rustc_codegen_gcc/src/common.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_codegen_ssa::traits::{
1313
use rustc_middle::mir::Mutability;
1414
use rustc_middle::ty::ScalarInt;
1515
use rustc_middle::ty::layout::{TyAndLayout, LayoutOf};
16-
use rustc_middle::mir::interpret::{Allocation, GlobalAlloc, Scalar};
16+
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};
1717
use rustc_span::Symbol;
1818
use rustc_target::abi::{self, HasDataLayout, Pointer, Size};
1919

@@ -230,6 +230,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
230230
match self.tcx.global_alloc(alloc_id) {
231231
GlobalAlloc::Memory(alloc) => {
232232
let init = const_alloc_to_gcc(self, alloc);
233+
let alloc = alloc.inner();
233234
let value =
234235
match alloc.mutability {
235236
Mutability::Mut => self.static_addr_of_mut(init, alloc.align, None),
@@ -262,21 +263,21 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
262263
}
263264
}
264265

265-
fn const_data_from_alloc(&self, alloc: &Allocation) -> Self::Value {
266+
fn const_data_from_alloc(&self, alloc: ConstAllocation<'tcx>) -> Self::Value {
266267
const_alloc_to_gcc(self, alloc)
267268
}
268269

269-
fn from_const_alloc(&self, layout: TyAndLayout<'tcx>, alloc: &Allocation, offset: Size) -> PlaceRef<'tcx, RValue<'gcc>> {
270-
assert_eq!(alloc.align, layout.align.abi);
270+
fn from_const_alloc(&self, layout: TyAndLayout<'tcx>, alloc: ConstAllocation<'tcx>, offset: Size) -> PlaceRef<'tcx, RValue<'gcc>> {
271+
assert_eq!(alloc.inner().align, layout.align.abi);
271272
let ty = self.type_ptr_to(layout.gcc_type(self, true));
272273
let value =
273274
if layout.size == Size::ZERO {
274-
let value = self.const_usize(alloc.align.bytes());
275+
let value = self.const_usize(alloc.inner().align.bytes());
275276
self.context.new_cast(None, value, ty)
276277
}
277278
else {
278279
let init = const_alloc_to_gcc(self, alloc);
279-
let base_addr = self.static_addr_of(init, alloc.align, None);
280+
let base_addr = self.static_addr_of(init, alloc.inner().align, None);
280281

281282
let array = self.const_bitcast(base_addr, self.type_i8p());
282283
let value = self.context.new_array_access(None, array, self.const_usize(offset.bytes())).get_address(None);

‎compiler/rustc_codegen_gcc/src/consts.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}
77
use rustc_middle::mir::mono::MonoItem;
88
use rustc_middle::ty::{self, Instance, Ty};
99
use rustc_middle::ty::layout::LayoutOf;
10-
use rustc_middle::mir::interpret::{self, Allocation, ErrorHandled, Scalar as InterpScalar, read_target_uint};
10+
use rustc_middle::mir::interpret::{self, ConstAllocation, ErrorHandled, Scalar as InterpScalar, read_target_uint};
1111
use rustc_span::Span;
1212
use rustc_span::def_id::DefId;
1313
use rustc_target::abi::{self, Align, HasDataLayout, Primitive, Size, WrappingRange};
@@ -284,7 +284,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
284284
}
285285
}
286286

287-
pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: &Allocation) -> RValue<'gcc> {
287+
pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAllocation<'tcx>) -> RValue<'gcc> {
288+
let alloc = alloc.inner();
288289
let mut llvals = Vec::with_capacity(alloc.relocations().len() + 1);
289290
let dl = cx.data_layout();
290291
let pointer_size = dl.pointer_size.bytes() as usize;
@@ -338,7 +339,7 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: &Alloca
338339
cx.const_struct(&llvals, true)
339340
}
340341

341-
pub fn codegen_static_initializer<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, def_id: DefId) -> Result<(RValue<'gcc>, &'tcx Allocation), ErrorHandled> {
342+
pub fn codegen_static_initializer<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, def_id: DefId) -> Result<(RValue<'gcc>, ConstAllocation<'tcx>), ErrorHandled> {
342343
let alloc = cx.tcx.eval_static_initializer(def_id)?;
343344
Ok((const_alloc_to_gcc(cx, alloc), alloc))
344345
}

‎compiler/rustc_codegen_llvm/src/common.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_ast::Mutability;
1111
use rustc_codegen_ssa::mir::place::PlaceRef;
1212
use rustc_codegen_ssa::traits::*;
1313
use rustc_middle::bug;
14-
use rustc_middle::mir::interpret::{Allocation, GlobalAlloc, Scalar};
14+
use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc, Scalar};
1515
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1616
use rustc_middle::ty::ScalarInt;
1717
use rustc_span::symbol::Symbol;
@@ -249,6 +249,7 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
249249
let (base_addr, base_addr_space) = match self.tcx.global_alloc(alloc_id) {
250250
GlobalAlloc::Memory(alloc) => {
251251
let init = const_alloc_to_llvm(self, alloc);
252+
let alloc = alloc.inner();
252253
let value = match alloc.mutability {
253254
Mutability::Mut => self.static_addr_of_mut(init, alloc.align, None),
254255
_ => self.static_addr_of(init, alloc.align, None),
@@ -285,24 +286,25 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
285286
}
286287
}
287288

288-
fn const_data_from_alloc(&self, alloc: &Allocation) -> Self::Value {
289+
fn const_data_from_alloc(&self, alloc: ConstAllocation<'tcx>) -> Self::Value {
289290
const_alloc_to_llvm(self, alloc)
290291
}
291292

292293
fn from_const_alloc(
293294
&self,
294295
layout: TyAndLayout<'tcx>,
295-
alloc: &Allocation,
296+
alloc: ConstAllocation<'tcx>,
296297
offset: Size,
297298
) -> PlaceRef<'tcx, &'ll Value> {
298-
assert_eq!(alloc.align, layout.align.abi);
299+
let alloc_align = alloc.inner().align;
300+
assert_eq!(alloc_align, layout.align.abi);
299301
let llty = self.type_ptr_to(layout.llvm_type(self));
300302
let llval = if layout.size == Size::ZERO {
301-
let llval = self.const_usize(alloc.align.bytes());
303+
let llval = self.const_usize(alloc_align.bytes());
302304
unsafe { llvm::LLVMConstIntToPtr(llval, llty) }
303305
} else {
304306
let init = const_alloc_to_llvm(self, alloc);
305-
let base_addr = self.static_addr_of(init, alloc.align, None);
307+
let base_addr = self.static_addr_of(init, alloc_align, None);
306308

307309
let llval = unsafe {
308310
llvm::LLVMRustConstInBoundsGEP2(

‎compiler/rustc_codegen_llvm/src/consts.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_codegen_ssa::traits::*;
1212
use rustc_hir::def_id::DefId;
1313
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
1414
use rustc_middle::mir::interpret::{
15-
read_target_uint, Allocation, ErrorHandled, GlobalAlloc, InitChunk, Pointer,
15+
read_target_uint, Allocation, ConstAllocation, ErrorHandled, GlobalAlloc, InitChunk, Pointer,
1616
Scalar as InterpScalar,
1717
};
1818
use rustc_middle::mir::mono::MonoItem;
@@ -25,7 +25,8 @@ use rustc_target::abi::{
2525
use std::ops::Range;
2626
use tracing::debug;
2727

28-
pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll Value {
28+
pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<'_>) -> &'ll Value {
29+
let alloc = alloc.inner();
2930
let mut llvals = Vec::with_capacity(alloc.relocations().len() + 1);
3031
let dl = cx.data_layout();
3132
let pointer_size = dl.pointer_size.bytes() as usize;
@@ -127,7 +128,7 @@ pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) ->
127128
pub fn codegen_static_initializer<'ll, 'tcx>(
128129
cx: &CodegenCx<'ll, 'tcx>,
129130
def_id: DefId,
130-
) -> Result<(&'ll Value, &'tcx Allocation), ErrorHandled> {
131+
) -> Result<(&'ll Value, ConstAllocation<'tcx>), ErrorHandled> {
131132
let alloc = cx.tcx.eval_static_initializer(def_id)?;
132133
Ok((const_alloc_to_llvm(cx, alloc), alloc))
133134
}
@@ -370,6 +371,7 @@ impl<'ll> StaticMethods for CodegenCx<'ll, '_> {
370371
// Error has already been reported
371372
return;
372373
};
374+
let alloc = alloc.inner();
373375

374376
let g = self.get_static(def_id);
375377

‎compiler/rustc_codegen_ssa/src/traits/consts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::BackendTypes;
22
use crate::mir::place::PlaceRef;
3-
use rustc_middle::mir::interpret::{Allocation, Scalar};
3+
use rustc_middle::mir::interpret::{ConstAllocation, Scalar};
44
use rustc_middle::ty::layout::TyAndLayout;
55
use rustc_span::Symbol;
66
use rustc_target::abi::{self, Size};
@@ -26,13 +26,13 @@ pub trait ConstMethods<'tcx>: BackendTypes {
2626
fn const_to_opt_uint(&self, v: Self::Value) -> Option<u64>;
2727
fn const_to_opt_u128(&self, v: Self::Value, sign_ext: bool) -> Option<u128>;
2828

29-
fn const_data_from_alloc(&self, alloc: &Allocation) -> Self::Value;
29+
fn const_data_from_alloc(&self, alloc: ConstAllocation<'tcx>) -> Self::Value;
3030

3131
fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, llty: Self::Type) -> Self::Value;
3232
fn from_const_alloc(
3333
&self,
3434
layout: TyAndLayout<'tcx>,
35-
alloc: &Allocation,
35+
alloc: ConstAllocation<'tcx>,
3636
offset: Size,
3737
) -> PlaceRef<'tcx, Self::Value>;
3838

‎compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
367367
"the raw bytes of the constant ({}",
368368
display_allocation(
369369
*ecx.tcx,
370-
ecx.tcx.global_alloc(alloc_id).unwrap_memory()
370+
ecx.tcx.global_alloc(alloc_id).unwrap_memory().inner()
371371
)
372372
));
373373
},

‎compiler/rustc_const_eval/src/const_eval/machine.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use rustc_target::abi::{Align, Size};
1818
use rustc_target::spec::abi::Abi;
1919

2020
use crate::interpret::{
21-
self, compile_time_machine, AllocId, Allocation, Frame, ImmTy, InterpCx, InterpResult, OpTy,
22-
PlaceTy, Scalar, StackPopUnwind,
21+
self, compile_time_machine, AllocId, ConstAllocation, Frame, ImmTy, InterpCx, InterpResult,
22+
OpTy, PlaceTy, Scalar, StackPopUnwind,
2323
};
2424

2525
use super::error::*;
@@ -475,13 +475,14 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
475475
fn before_access_global(
476476
memory_extra: &MemoryExtra,
477477
alloc_id: AllocId,
478-
allocation: &Allocation,
478+
alloc: ConstAllocation<'tcx>,
479479
static_def_id: Option<DefId>,
480480
is_write: bool,
481481
) -> InterpResult<'tcx> {
482+
let alloc = alloc.inner();
482483
if is_write {
483484
// Write access. These are never allowed, but we give a targeted error message.
484-
if allocation.mutability == Mutability::Not {
485+
if alloc.mutability == Mutability::Not {
485486
Err(err_ub!(WriteToReadOnly(alloc_id)).into())
486487
} else {
487488
Err(ConstEvalErrKind::ModifiedGlobal.into())
@@ -504,7 +505,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
504505
// But make sure we never accept a read from something mutable, that would be
505506
// unsound. The reason is that as the content of this allocation may be different
506507
// now and at run-time, so if we permit reading now we might return the wrong value.
507-
assert_eq!(allocation.mutability, Mutability::Not);
508+
assert_eq!(alloc.mutability, Mutability::Not);
508509
Ok(())
509510
}
510511
}

‎compiler/rustc_const_eval/src/const_eval/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ pub(crate) fn deref_const<'tcx>(
183183
let mplace = ecx.deref_operand(&op).unwrap();
184184
if let Some(alloc_id) = mplace.ptr.provenance {
185185
assert_eq!(
186-
tcx.get_global_alloc(alloc_id).unwrap().unwrap_memory().mutability,
186+
tcx.get_global_alloc(alloc_id).unwrap().unwrap_memory().inner().mutability,
187187
Mutability::Not,
188188
"deref_const cannot be used with mutable allocations as \
189189
that could allow pattern matching to observe mutable statics",

‎compiler/rustc_const_eval/src/interpret/intern.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ use rustc_middle::ty::{self, layout::TyAndLayout, Ty};
2323

2424
use rustc_ast::Mutability;
2525

26-
use super::{AllocId, Allocation, InterpCx, MPlaceTy, Machine, MemoryKind, PlaceTy, ValueVisitor};
26+
use super::{
27+
AllocId, Allocation, ConstAllocation, InterpCx, MPlaceTy, Machine, MemoryKind, PlaceTy,
28+
ValueVisitor,
29+
};
2730
use crate::const_eval;
2831

2932
pub trait CompileTimeMachine<'mir, 'tcx, T> = Machine<
@@ -131,8 +134,8 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval:
131134
alloc.mutability = Mutability::Not;
132135
};
133136
// link the alloc id to the actual allocation
134-
let alloc = tcx.intern_const_alloc(alloc);
135137
leftover_allocations.extend(alloc.relocations().iter().map(|&(_, alloc_id)| alloc_id));
138+
let alloc = tcx.intern_const_alloc(alloc);
136139
tcx.set_alloc_id_memory(alloc_id, alloc);
137140
None
138141
}
@@ -393,7 +396,7 @@ pub fn intern_const_alloc_recursive<
393396
}
394397
let alloc = tcx.intern_const_alloc(alloc);
395398
tcx.set_alloc_id_memory(alloc_id, alloc);
396-
for &(_, alloc_id) in alloc.relocations().iter() {
399+
for &(_, alloc_id) in alloc.inner().relocations().iter() {
397400
if leftover_allocations.insert(alloc_id) {
398401
todo.push(alloc_id);
399402
}
@@ -425,7 +428,7 @@ impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>>
425428
&mut InterpCx<'mir, 'tcx, M>,
426429
&PlaceTy<'tcx, M::PointerTag>,
427430
) -> InterpResult<'tcx, ()>,
428-
) -> InterpResult<'tcx, &'tcx Allocation> {
431+
) -> InterpResult<'tcx, ConstAllocation<'tcx>> {
429432
let dest = self.allocate(layout, MemoryKind::Stack)?;
430433
f(self, &dest.into())?;
431434
let mut alloc = self.memory.alloc_map.remove(&dest.ptr.provenance.unwrap()).unwrap().1;

‎compiler/rustc_const_eval/src/interpret/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ crate fn eval_nullary_intrinsic<'tcx>(
5656
sym::type_name => {
5757
ensure_monomorphic_enough(tcx, tp_ty)?;
5858
let alloc = type_name::alloc_type_name(tcx, tp_ty);
59-
ConstValue::Slice { data: alloc, start: 0, end: alloc.len() }
59+
ConstValue::Slice { data: alloc, start: 0, end: alloc.inner().len() }
6060
}
6161
sym::needs_drop => {
6262
ensure_monomorphic_enough(tcx, tp_ty)?;

‎compiler/rustc_const_eval/src/interpret/intrinsics/type_name.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_hir::def_id::CrateNum;
22
use rustc_hir::definitions::DisambiguatedDefPathData;
3-
use rustc_middle::mir::interpret::Allocation;
3+
use rustc_middle::mir::interpret::{Allocation, ConstAllocation};
44
use rustc_middle::ty::{
55
self,
66
print::{PrettyPrinter, Print, Printer},
@@ -188,7 +188,7 @@ impl Write for AbsolutePathPrinter<'_> {
188188
}
189189

190190
/// Directly returns an `Allocation` containing an absolute path representation of the given type.
191-
crate fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> &'tcx Allocation {
191+
crate fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ConstAllocation<'tcx> {
192192
let path = AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path;
193193
let alloc = Allocation::from_bytes_byte_aligned_immutable(path.into_bytes());
194194
tcx.intern_const_alloc(alloc)

‎compiler/rustc_const_eval/src/interpret/machine.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ use rustc_target::abi::Size;
1313
use rustc_target::spec::abi::Abi;
1414

1515
use super::{
16-
AllocId, AllocRange, Allocation, Frame, ImmTy, InterpCx, InterpResult, LocalValue, MemPlace,
17-
Memory, MemoryKind, OpTy, Operand, PlaceTy, Pointer, Provenance, Scalar, StackPopUnwind,
16+
AllocId, AllocRange, Allocation, ConstAllocation, Frame, ImmTy, InterpCx, InterpResult,
17+
LocalValue, MemPlace, Memory, MemoryKind, OpTy, Operand, PlaceTy, Pointer, Provenance, Scalar,
18+
StackPopUnwind,
1819
};
1920

2021
/// Data returned by Machine::stack_pop,
@@ -252,7 +253,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
252253
fn before_access_global(
253254
_memory_extra: &Self::MemoryExtra,
254255
_alloc_id: AllocId,
255-
_allocation: &Allocation,
256+
_allocation: ConstAllocation<'tcx>,
256257
_static_def_id: Option<DefId>,
257258
_is_write: bool,
258259
) -> InterpResult<'tcx> {

0 commit comments

Comments
 (0)
Please sign in to comment.