Skip to content

Commit

Permalink
Auto merge of rust-lang#85376 - RalfJung:ptrless-allocs, r=oli-obk
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed May 19, 2021
2 parents be8450e + d5ccf68 commit 3e827cc
Show file tree
Hide file tree
Showing 19 changed files with 597 additions and 510 deletions.
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_cranelift/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::ErrorReported;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::interpret::{
read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Pointer, Scalar,
alloc_range, read_target_uint, AllocId, Allocation, ConstValue, ErrorHandled, GlobalAlloc, Scalar,
};
use rustc_middle::ty::ConstKind;

Expand Down Expand Up @@ -176,8 +176,7 @@ pub(crate) fn codegen_const_value<'tcx>(
std::iter::repeat(0).take(size.bytes_usize()).collect::<Vec<u8>>(),
align,
);
let ptr = Pointer::new(AllocId(!0), Size::ZERO); // The alloc id is never used
alloc.write_scalar(fx, ptr, x.into(), size).unwrap();
alloc.write_scalar(fx, alloc_range(Size::ZERO, size), x.into()).unwrap();
let alloc = fx.tcx.intern_const_alloc(alloc);
return CValue::by_ref(pointer_for_allocation(fx, alloc), layout);
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(

let idx_bytes = match idx_const {
ConstValue::ByRef { alloc, offset } => {
let ptr = Pointer::new(AllocId(0 /* dummy */), offset);
let size = Size::from_bytes(4 * ret_lane_count /* size_of([u32; ret_lane_count]) */);
alloc.get_bytes(fx, ptr, size).unwrap()
alloc.get_bytes(fx, alloc_range(offset, size)).unwrap()
}
_ => unreachable!("{:?}", idx_const),
};
Expand Down
Loading

0 comments on commit 3e827cc

Please sign in to comment.