Skip to content

Commit d689034

Browse files
committed
interpret: remove Readable trait, we can use Projectable instead
1 parent 6cf068d commit d689034

File tree

5 files changed

+21
-47
lines changed

5 files changed

+21
-47
lines changed

compiler/rustc_const_eval/src/interpret/discriminant.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_target::abi::{self, TagEncoding, VariantIdx, Variants};
77
use tracing::{instrument, trace};
88

99
use super::{
10-
err_ub, throw_ub, ImmTy, InterpCx, InterpResult, Machine, Readable, Scalar, Writeable,
10+
err_ub, throw_ub, ImmTy, InterpCx, InterpResult, Machine, Projectable, Scalar, Writeable,
1111
};
1212

1313
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
@@ -60,7 +60,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
6060
#[instrument(skip(self), level = "trace")]
6161
pub fn read_discriminant(
6262
&self,
63-
op: &impl Readable<'tcx, M::Provenance>,
63+
op: &impl Projectable<'tcx, M::Provenance>,
6464
) -> InterpResult<'tcx, VariantIdx> {
6565
let ty = op.layout().ty;
6666
trace!("read_discriminant_value {:#?}", op.layout());

compiler/rustc_const_eval/src/interpret/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub(crate) use self::intrinsics::eval_nullary_intrinsic;
3333
pub use self::machine::{compile_time_machine, AllocMap, Machine, MayLeak, ReturnAction};
3434
pub use self::memory::{AllocKind, AllocRef, AllocRefMut, FnVal, Memory, MemoryKind};
3535
use self::operand::Operand;
36-
pub use self::operand::{ImmTy, Immediate, OpTy, Readable};
36+
pub use self::operand::{ImmTy, Immediate, OpTy};
3737
pub use self::place::{MPlaceTy, MemPlaceMeta, PlaceTy, Writeable};
3838
use self::place::{MemPlace, Place};
3939
pub use self::projection::{OffsetMode, Projectable};

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -490,32 +490,6 @@ impl<'tcx, Prov: Provenance> Projectable<'tcx, Prov> for OpTy<'tcx, Prov> {
490490
}
491491
}
492492

493-
/// The `Readable` trait describes interpreter values that one can read from.
494-
pub trait Readable<'tcx, Prov: Provenance>: Projectable<'tcx, Prov> {
495-
fn as_mplace_or_imm(&self) -> Either<MPlaceTy<'tcx, Prov>, ImmTy<'tcx, Prov>>;
496-
}
497-
498-
impl<'tcx, Prov: Provenance> Readable<'tcx, Prov> for OpTy<'tcx, Prov> {
499-
#[inline(always)]
500-
fn as_mplace_or_imm(&self) -> Either<MPlaceTy<'tcx, Prov>, ImmTy<'tcx, Prov>> {
501-
self.as_mplace_or_imm()
502-
}
503-
}
504-
505-
impl<'tcx, Prov: Provenance> Readable<'tcx, Prov> for MPlaceTy<'tcx, Prov> {
506-
#[inline(always)]
507-
fn as_mplace_or_imm(&self) -> Either<MPlaceTy<'tcx, Prov>, ImmTy<'tcx, Prov>> {
508-
Left(self.clone())
509-
}
510-
}
511-
512-
impl<'tcx, Prov: Provenance> Readable<'tcx, Prov> for ImmTy<'tcx, Prov> {
513-
#[inline(always)]
514-
fn as_mplace_or_imm(&self) -> Either<MPlaceTy<'tcx, Prov>, ImmTy<'tcx, Prov>> {
515-
Right(self.clone())
516-
}
517-
}
518-
519493
impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
520494
/// Try reading an immediate in memory; this is interesting particularly for `ScalarPair`.
521495
/// Returns `None` if the layout does not permit loading this as a value.
@@ -588,9 +562,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
588562
/// ConstProp needs it, though.
589563
pub fn read_immediate_raw(
590564
&self,
591-
src: &impl Readable<'tcx, M::Provenance>,
565+
src: &impl Projectable<'tcx, M::Provenance>,
592566
) -> InterpResult<'tcx, Either<MPlaceTy<'tcx, M::Provenance>, ImmTy<'tcx, M::Provenance>>> {
593-
Ok(match src.as_mplace_or_imm() {
567+
Ok(match src.to_op(self)?.as_mplace_or_imm() {
594568
Left(ref mplace) => {
595569
if let Some(val) = self.read_immediate_from_mplace_raw(mplace)? {
596570
Right(val)
@@ -608,7 +582,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
608582
#[inline(always)]
609583
pub fn read_immediate(
610584
&self,
611-
op: &impl Readable<'tcx, M::Provenance>,
585+
op: &impl Projectable<'tcx, M::Provenance>,
612586
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
613587
if !matches!(
614588
op.layout().abi,
@@ -627,7 +601,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
627601
/// Read a scalar from a place
628602
pub fn read_scalar(
629603
&self,
630-
op: &impl Readable<'tcx, M::Provenance>,
604+
op: &impl Projectable<'tcx, M::Provenance>,
631605
) -> InterpResult<'tcx, Scalar<M::Provenance>> {
632606
Ok(self.read_immediate(op)?.to_scalar())
633607
}
@@ -638,21 +612,21 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
638612
/// Read a pointer from a place.
639613
pub fn read_pointer(
640614
&self,
641-
op: &impl Readable<'tcx, M::Provenance>,
615+
op: &impl Projectable<'tcx, M::Provenance>,
642616
) -> InterpResult<'tcx, Pointer<Option<M::Provenance>>> {
643617
self.read_scalar(op)?.to_pointer(self)
644618
}
645619
/// Read a pointer-sized unsigned integer from a place.
646620
pub fn read_target_usize(
647621
&self,
648-
op: &impl Readable<'tcx, M::Provenance>,
622+
op: &impl Projectable<'tcx, M::Provenance>,
649623
) -> InterpResult<'tcx, u64> {
650624
self.read_scalar(op)?.to_target_usize(self)
651625
}
652626
/// Read a pointer-sized signed integer from a place.
653627
pub fn read_target_isize(
654628
&self,
655-
op: &impl Readable<'tcx, M::Provenance>,
629+
op: &impl Projectable<'tcx, M::Provenance>,
656630
) -> InterpResult<'tcx, i64> {
657631
self.read_scalar(op)?.to_target_isize(self)
658632
}

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use tracing::{instrument, trace};
1515
use super::{
1616
alloc_range, mir_assign_valid_types, AllocRef, AllocRefMut, CheckAlignMsg, CtfeProvenance,
1717
ImmTy, Immediate, InterpCx, InterpResult, Machine, MemoryKind, Misalignment, OffsetMode, OpTy,
18-
Operand, Pointer, Projectable, Provenance, Readable, Scalar,
18+
Operand, Pointer, Projectable, Provenance, Scalar,
1919
};
2020

2121
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
@@ -436,7 +436,7 @@ where
436436
#[instrument(skip(self), level = "trace")]
437437
pub fn deref_pointer(
438438
&self,
439-
src: &impl Readable<'tcx, M::Provenance>,
439+
src: &impl Projectable<'tcx, M::Provenance>,
440440
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::Provenance>> {
441441
let val = self.read_immediate(src)?;
442442
trace!("deref to {} on {:?}", val.layout.ty, *val);
@@ -766,7 +766,7 @@ where
766766
#[inline(always)]
767767
pub(super) fn copy_op_no_dest_validation(
768768
&mut self,
769-
src: &impl Readable<'tcx, M::Provenance>,
769+
src: &impl Projectable<'tcx, M::Provenance>,
770770
dest: &impl Writeable<'tcx, M::Provenance>,
771771
) -> InterpResult<'tcx> {
772772
self.copy_op_inner(
@@ -779,7 +779,7 @@ where
779779
#[inline(always)]
780780
pub fn copy_op_allow_transmute(
781781
&mut self,
782-
src: &impl Readable<'tcx, M::Provenance>,
782+
src: &impl Projectable<'tcx, M::Provenance>,
783783
dest: &impl Writeable<'tcx, M::Provenance>,
784784
) -> InterpResult<'tcx> {
785785
self.copy_op_inner(
@@ -792,7 +792,7 @@ where
792792
#[inline(always)]
793793
pub fn copy_op(
794794
&mut self,
795-
src: &impl Readable<'tcx, M::Provenance>,
795+
src: &impl Projectable<'tcx, M::Provenance>,
796796
dest: &impl Writeable<'tcx, M::Provenance>,
797797
) -> InterpResult<'tcx> {
798798
self.copy_op_inner(
@@ -806,7 +806,7 @@ where
806806
#[instrument(skip(self), level = "trace")]
807807
fn copy_op_inner(
808808
&mut self,
809-
src: &impl Readable<'tcx, M::Provenance>,
809+
src: &impl Projectable<'tcx, M::Provenance>,
810810
dest: &impl Writeable<'tcx, M::Provenance>,
811811
allow_transmute: bool,
812812
validate_dest: bool,
@@ -841,7 +841,7 @@ where
841841
#[instrument(skip(self), level = "trace")]
842842
fn copy_op_no_validate(
843843
&mut self,
844-
src: &impl Readable<'tcx, M::Provenance>,
844+
src: &impl Projectable<'tcx, M::Provenance>,
845845
dest: &impl Writeable<'tcx, M::Provenance>,
846846
allow_transmute: bool,
847847
) -> InterpResult<'tcx> {

src/tools/miri/src/helpers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
872872
/// Dereference a pointer operand to a place using `layout` instead of the pointer's declared type
873873
fn deref_pointer_as(
874874
&self,
875-
op: &impl Readable<'tcx, Provenance>,
875+
op: &impl Projectable<'tcx, Provenance>,
876876
layout: TyAndLayout<'tcx>,
877877
) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
878878
let this = self.eval_context_ref();
@@ -883,7 +883,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
883883
/// Calculates the MPlaceTy given the offset and layout of an access on an operand
884884
fn deref_pointer_and_offset(
885885
&self,
886-
op: &impl Readable<'tcx, Provenance>,
886+
op: &impl Projectable<'tcx, Provenance>,
887887
offset: u64,
888888
base_layout: TyAndLayout<'tcx>,
889889
value_layout: TyAndLayout<'tcx>,
@@ -900,7 +900,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
900900

901901
fn deref_pointer_and_read(
902902
&self,
903-
op: &impl Readable<'tcx, Provenance>,
903+
op: &impl Projectable<'tcx, Provenance>,
904904
offset: u64,
905905
base_layout: TyAndLayout<'tcx>,
906906
value_layout: TyAndLayout<'tcx>,
@@ -912,7 +912,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
912912

913913
fn deref_pointer_and_write(
914914
&mut self,
915-
op: &impl Readable<'tcx, Provenance>,
915+
op: &impl Projectable<'tcx, Provenance>,
916916
offset: u64,
917917
value: impl Into<Scalar>,
918918
base_layout: TyAndLayout<'tcx>,

0 commit comments

Comments
 (0)