Skip to content

Commit d31cbb5

Browse files
committed
make AllocRef APIs more consistent
1 parent c36572c commit d31cbb5

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

compiler/rustc_const_eval/src/interpret/memory.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> std::fmt::Debug for DumpAllocs<'a,
857857

858858
/// Reading and writing.
859859
impl<'tcx, 'a, Tag: Provenance, Extra> AllocRefMut<'a, 'tcx, Tag, Extra> {
860+
/// `range` is relative to this allocation reference, not the base of the allocation.
860861
pub fn write_scalar(
861862
&mut self,
862863
range: AllocRange,
@@ -870,6 +871,7 @@ impl<'tcx, 'a, Tag: Provenance, Extra> AllocRefMut<'a, 'tcx, Tag, Extra> {
870871
.map_err(|e| e.to_interp_error(self.alloc_id))?)
871872
}
872873

874+
/// `offset` is relative to this allocation reference, not the base of the allocation.
873875
pub fn write_ptr_sized(
874876
&mut self,
875877
offset: Size,
@@ -888,6 +890,7 @@ impl<'tcx, 'a, Tag: Provenance, Extra> AllocRefMut<'a, 'tcx, Tag, Extra> {
888890
}
889891

890892
impl<'tcx, 'a, Tag: Provenance, Extra> AllocRef<'a, 'tcx, Tag, Extra> {
893+
/// `range` is relative to this allocation reference, not the base of the allocation.
891894
pub fn read_scalar(
892895
&self,
893896
range: AllocRange,
@@ -902,21 +905,20 @@ impl<'tcx, 'a, Tag: Provenance, Extra> AllocRef<'a, 'tcx, Tag, Extra> {
902905
Ok(res)
903906
}
904907

905-
pub fn read_integer(
906-
&self,
907-
offset: Size,
908-
size: Size,
909-
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
910-
self.read_scalar(alloc_range(offset, size), /*read_provenance*/ false)
908+
/// `range` is relative to this allocation reference, not the base of the allocation.
909+
pub fn read_integer(&self, range: AllocRange) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
910+
self.read_scalar(range, /*read_provenance*/ false)
911911
}
912912

913+
/// `offset` is relative to this allocation reference, not the base of the allocation.
913914
pub fn read_pointer(&self, offset: Size) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
914915
self.read_scalar(
915916
alloc_range(offset, self.tcx.data_layout().pointer_size),
916917
/*read_provenance*/ true,
917918
)
918919
}
919920

921+
/// `range` is relative to this allocation reference, not the base of the allocation.
920922
pub fn check_bytes(
921923
&self,
922924
range: AllocRange,

compiler/rustc_const_eval/src/interpret/traits.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::convert::TryFrom;
22

3-
use rustc_middle::mir::interpret::{InterpResult, Pointer, PointerArithmetic};
3+
use rustc_middle::mir::interpret::{alloc_range, InterpResult, Pointer, PointerArithmetic};
44
use rustc_middle::ty::{
55
self, Ty, TyCtxt, COMMON_VTABLE_ENTRIES_ALIGN, COMMON_VTABLE_ENTRIES_DROPINPLACE,
66
COMMON_VTABLE_ENTRIES_SIZE,
@@ -102,18 +102,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
102102
)?
103103
.expect("cannot be a ZST");
104104
let size = vtable
105-
.read_integer(
105+
.read_integer(alloc_range(
106106
pointer_size * u64::try_from(COMMON_VTABLE_ENTRIES_SIZE).unwrap(),
107107
pointer_size,
108-
)?
108+
))?
109109
.check_init()?;
110110
let size = size.to_machine_usize(self)?;
111111
let size = Size::from_bytes(size);
112112
let align = vtable
113-
.read_integer(
113+
.read_integer(alloc_range(
114114
pointer_size * u64::try_from(COMMON_VTABLE_ENTRIES_ALIGN).unwrap(),
115115
pointer_size,
116-
)?
116+
))?
117117
.check_init()?;
118118
let align = align.to_machine_usize(self)?;
119119
let align = Align::from_bytes(align).map_err(|e| err_ub!(InvalidVtableAlignment(e)))?;

0 commit comments

Comments
 (0)