Skip to content

Commit 3e827cc

Browse files
committed
Auto merge of rust-lang#85376 - RalfJung:ptrless-allocs, r=oli-obk
CTFE core engine allocation & memory API improvemenets This is a first step towards rust-lang/miri#841. - make `Allocation` API offset-based (no more making up `Pointer`s just to access an `Allocation`) - make `Memory` API higher-level (combine checking for access and getting access into one operation) The Miri-side PR is at rust-lang/miri#1804. r? `@oli-obk`
2 parents be8450e + d5ccf68 commit 3e827cc

File tree

19 files changed

+597
-510
lines changed

19 files changed

+597
-510
lines changed

compiler/rustc_codegen_cranelift/src/constant.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
66
use rustc_errors::ErrorReported;
77
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
88
use rustc_middle::mir::interpret::{
9-
read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Pointer, Scalar,
9+
alloc_range, read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
1010
};
1111
use rustc_middle::ty::ConstKind;
1212

@@ -176,8 +176,7 @@ pub(crate) fn codegen_const_value<'tcx>(
176176
std::iter::repeat(0).take(size.bytes_usize()).collect::<Vec<u8>>(),
177177
align,
178178
);
179-
let ptr = Pointer::new(AllocId(!0), Size::ZERO); // The alloc id is never used
180-
alloc.write_scalar(fx, ptr, x.into(), size).unwrap();
179+
alloc.write_scalar(fx, alloc_range(Size::ZERO, size), x.into()).unwrap();
181180
let alloc = fx.tcx.intern_const_alloc(alloc);
182181
return CValue::by_ref(pointer_for_allocation(fx, alloc), layout);
183182
}

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
8686

8787
let idx_bytes = match idx_const {
8888
ConstValue::ByRef { alloc, offset } => {
89-
let ptr = Pointer::new(AllocId(0 /* dummy */), offset);
9089
let size = Size::from_bytes(4 * ret_lane_count /* size_of([u32; ret_lane_count]) */);
91-
alloc.get_bytes(fx, ptr, size).unwrap()
90+
alloc.get_bytes(fx, alloc_range(offset, size)).unwrap()
9291
}
9392
_ => unreachable!("{:?}", idx_const),
9493
};

0 commit comments

Comments
 (0)