Skip to content

Commit 7d58865

Browse files
committed
rename deref_operand → deref_pointer and some Miri helper functions
1 parent 866710c commit 7d58865

File tree

25 files changed

+84
-85
lines changed

25 files changed

+84
-85
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
214214
// &str or &&str
215215
assert!(args.len() == 1);
216216

217-
let mut msg_place = self.deref_operand(&args[0])?;
217+
let mut msg_place = self.deref_pointer(&args[0])?;
218218
while msg_place.layout.ty.is_ref() {
219-
msg_place = self.deref_operand(&msg_place)?;
219+
msg_place = self.deref_pointer(&msg_place)?;
220220
}
221221

222222
let msg = Symbol::intern(self.read_str(&msg_place)?);

compiler/rustc_const_eval/src/const_eval/valtrees.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub(crate) fn const_to_valtree_inner<'tcx>(
102102
ty::FnPtr(_) | ty::RawPtr(_) => Err(ValTreeCreationError::NonSupportedType),
103103

104104
ty::Ref(_, _, _) => {
105-
let Ok(derefd_place)= ecx.deref_operand(place) else {
105+
let Ok(derefd_place)= ecx.deref_pointer(place) else {
106106
return Err(ValTreeCreationError::Other);
107107
};
108108
debug!(?derefd_place);

compiler/rustc_const_eval/src/interpret/intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
144144
}
145145

146146
sym::min_align_of_val | sym::size_of_val => {
147-
// Avoid `deref_operand` -- this is not a deref, the ptr does not have to be
147+
// Avoid `deref_pointer` -- this is not a deref, the ptr does not have to be
148148
// dereferenceable!
149149
let place = self.ref_to_mplace(&self.read_immediate(&args[0])?)?;
150150
let (size, align) = self
@@ -225,7 +225,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
225225
self.write_scalar(val, dest)?;
226226
}
227227
sym::discriminant_value => {
228-
let place = self.deref_operand(&args[0])?;
228+
let place = self.deref_pointer(&args[0])?;
229229
let variant = self.read_discriminant(&place)?;
230230
let discr = self.discriminant_for_variant(place.layout, variant)?;
231231
self.write_scalar(discr, dest)?;

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ where
419419
///
420420
/// Only call this if you are sure the place is "valid" (aligned and inbounds), or do not
421421
/// want to ever use the place for memory access!
422-
/// Generally prefer `deref_operand`.
422+
/// Generally prefer `deref_pointer`.
423423
pub fn ref_to_mplace(
424424
&self,
425425
val: &ImmTy<'tcx, M::Provenance>,
@@ -439,8 +439,9 @@ where
439439
}
440440

441441
/// Take an operand, representing a pointer, and dereference it to a place.
442+
/// Corresponds to the `*` operator in Rust.
442443
#[instrument(skip(self), level = "debug")]
443-
pub fn deref_operand(
444+
pub fn deref_pointer(
444445
&self,
445446
src: &impl Readable<'tcx, M::Provenance>,
446447
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {

compiler/rustc_const_eval/src/interpret/projection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ where
290290
OpaqueCast(ty) => base.transmute(self.layout_of(ty)?, self)?,
291291
Field(field, _) => self.project_field(base, field.index())?,
292292
Downcast(_, variant) => self.project_downcast(base, variant)?,
293-
Deref => self.deref_operand(&base.to_op(self)?)?.into(),
293+
Deref => self.deref_pointer(&base.to_op(self)?)?.into(),
294294
Index(local) => {
295295
let layout = self.layout_of(self.tcx.types.usize)?;
296296
let n = self.local_to_op(self.frame(), local, Some(layout))?;

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
661661
let receiver_place = loop {
662662
match receiver.layout.ty.kind() {
663663
ty::Ref(..) | ty::RawPtr(..) => {
664-
// We do *not* use `deref_operand` here: we don't want to conceptually
664+
// We do *not* use `deref_pointer` here: we don't want to conceptually
665665
// create a place that must be dereferenceable, since the receiver might
666666
// be a raw pointer and (for `*const dyn Trait`) we don't need to
667667
// actually access memory to resolve this method.

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
345345
value: &OpTy<'tcx, M::Provenance>,
346346
ptr_kind: PointerKind,
347347
) -> InterpResult<'tcx> {
348+
// Not using `deref_pointer` since we do the dereferenceable check ourselves below.
348349
let place = self.ecx.ref_to_mplace(&self.read_immediate(value, ptr_kind.into())?)?;
349350
// Handle wide pointers.
350351
// Check metadata early, for better diagnostics
@@ -515,9 +516,6 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
515516
Ok(true)
516517
}
517518
ty::RawPtr(..) => {
518-
// We are conservative with uninit for integers, but try to
519-
// actually enforce the strict rules for raw pointers (mostly because
520-
// that lets us re-use `ref_to_mplace`).
521519
let place =
522520
self.ecx.ref_to_mplace(&self.read_immediate(value, ExpectedKind::RawPtr)?)?;
523521
if place.layout.is_unsized() {

src/tools/miri/src/concurrency/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ pub(super) trait EvalContextExtPriv<'mir, 'tcx: 'mir>:
206206
) -> InterpResult<'tcx, Option<Id>> {
207207
let this = self.eval_context_mut();
208208
let value_place =
209-
this.deref_operand_and_offset(lock_op, offset, lock_layout, this.machine.layouts.u32)?;
209+
this.deref_pointer_and_offset(lock_op, offset, lock_layout, this.machine.layouts.u32)?;
210210

211211
// Since we are lazy, this update has to be atomic.
212212
let (old, success) = this

src/tools/miri/src/helpers.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -715,9 +715,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
715715
}
716716

717717
/// Dereference a pointer operand to a place using `layout` instead of the pointer's declared type
718-
fn deref_operand_as(
718+
fn deref_pointer_as(
719719
&self,
720-
op: &OpTy<'tcx, Provenance>,
720+
op: &impl Readable<'tcx, Provenance>,
721721
layout: TyAndLayout<'tcx>,
722722
) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
723723
let this = self.eval_context_ref();
@@ -746,15 +746,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
746746
}
747747

748748
/// Calculates the MPlaceTy given the offset and layout of an access on an operand
749-
fn deref_operand_and_offset(
749+
fn deref_pointer_and_offset(
750750
&self,
751-
op: &OpTy<'tcx, Provenance>,
751+
op: &impl Readable<'tcx, Provenance>,
752752
offset: u64,
753753
base_layout: TyAndLayout<'tcx>,
754754
value_layout: TyAndLayout<'tcx>,
755755
) -> InterpResult<'tcx, MPlaceTy<'tcx, Provenance>> {
756756
let this = self.eval_context_ref();
757-
let op_place = this.deref_operand_as(op, base_layout)?;
757+
let op_place = this.deref_pointer_as(op, base_layout)?;
758758
let offset = Size::from_bytes(offset);
759759

760760
// Ensure that the access is within bounds.
@@ -763,28 +763,28 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
763763
Ok(value_place)
764764
}
765765

766-
fn read_scalar_at_offset(
766+
fn deref_pointer_and_read(
767767
&self,
768-
op: &OpTy<'tcx, Provenance>,
768+
op: &impl Readable<'tcx, Provenance>,
769769
offset: u64,
770770
base_layout: TyAndLayout<'tcx>,
771771
value_layout: TyAndLayout<'tcx>,
772772
) -> InterpResult<'tcx, Scalar<Provenance>> {
773773
let this = self.eval_context_ref();
774-
let value_place = this.deref_operand_and_offset(op, offset, base_layout, value_layout)?;
774+
let value_place = this.deref_pointer_and_offset(op, offset, base_layout, value_layout)?;
775775
this.read_scalar(&value_place)
776776
}
777777

778-
fn write_scalar_at_offset(
778+
fn deref_pointer_and_write(
779779
&mut self,
780-
op: &OpTy<'tcx, Provenance>,
780+
op: &impl Readable<'tcx, Provenance>,
781781
offset: u64,
782782
value: impl Into<Scalar<Provenance>>,
783783
base_layout: TyAndLayout<'tcx>,
784784
value_layout: TyAndLayout<'tcx>,
785785
) -> InterpResult<'tcx, ()> {
786786
let this = self.eval_context_mut();
787-
let value_place = this.deref_operand_and_offset(op, offset, base_layout, value_layout)?;
787+
let value_place = this.deref_pointer_and_offset(op, offset, base_layout, value_layout)?;
788788
this.write_scalar(value, &value_place)
789789
}
790790

src/tools/miri/src/shims/backtrace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
9797
1 => {
9898
let [_flags, buf] = this.check_shim(abi, Abi::Rust, link_name, args)?;
9999

100-
let buf_place = this.deref_operand(buf)?;
100+
let buf_place = this.deref_pointer(buf)?;
101101

102102
let ptr_layout = this.layout_of(ptr_ty)?;
103103

0 commit comments

Comments
 (0)