Skip to content

Commit fa60ea7

Browse files
committed
interpret: remove Readable trait, we can use Projectable instead
1 parent 7b18b3e commit fa60ea7

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
if src.layout().ty.is_box() {
442442
// Derefer should have removed all Box derefs.
@@ -768,7 +768,7 @@ where
768768
#[inline(always)]
769769
pub(super) fn copy_op_no_dest_validation(
770770
&mut self,
771-
src: &impl Readable<'tcx, M::Provenance>,
771+
src: &impl Projectable<'tcx, M::Provenance>,
772772
dest: &impl Writeable<'tcx, M::Provenance>,
773773
) -> InterpResult<'tcx> {
774774
self.copy_op_inner(
@@ -781,7 +781,7 @@ where
781781
#[inline(always)]
782782
pub fn copy_op_allow_transmute(
783783
&mut self,
784-
src: &impl Readable<'tcx, M::Provenance>,
784+
src: &impl Projectable<'tcx, M::Provenance>,
785785
dest: &impl Writeable<'tcx, M::Provenance>,
786786
) -> InterpResult<'tcx> {
787787
self.copy_op_inner(
@@ -794,7 +794,7 @@ where
794794
#[inline(always)]
795795
pub fn copy_op(
796796
&mut self,
797-
src: &impl Readable<'tcx, M::Provenance>,
797+
src: &impl Projectable<'tcx, M::Provenance>,
798798
dest: &impl Writeable<'tcx, M::Provenance>,
799799
) -> InterpResult<'tcx> {
800800
self.copy_op_inner(
@@ -808,7 +808,7 @@ where
808808
#[instrument(skip(self), level = "trace")]
809809
fn copy_op_inner(
810810
&mut self,
811-
src: &impl Readable<'tcx, M::Provenance>,
811+
src: &impl Projectable<'tcx, M::Provenance>,
812812
dest: &impl Writeable<'tcx, M::Provenance>,
813813
allow_transmute: bool,
814814
validate_dest: bool,
@@ -843,7 +843,7 @@ where
843843
#[instrument(skip(self), level = "trace")]
844844
fn copy_op_no_validate(
845845
&mut self,
846-
src: &impl Readable<'tcx, M::Provenance>,
846+
src: &impl Projectable<'tcx, M::Provenance>,
847847
dest: &impl Writeable<'tcx, M::Provenance>,
848848
allow_transmute: bool,
849849
) -> InterpResult<'tcx> {

src/tools/miri/src/helpers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
869869
/// Dereference a pointer operand to a place using `layout` instead of the pointer's declared type
870870
fn deref_pointer_as(
871871
&self,
872-
op: &impl Readable<'tcx, Provenance>,
872+
op: &impl Projectable<'tcx, Provenance>,
873873
layout: TyAndLayout<'tcx>,
874874
) -> InterpResult<'tcx, MPlaceTy<'tcx>> {
875875
let this = self.eval_context_ref();
@@ -880,7 +880,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
880880
/// Calculates the MPlaceTy given the offset and layout of an access on an operand
881881
fn deref_pointer_and_offset(
882882
&self,
883-
op: &impl Readable<'tcx, Provenance>,
883+
op: &impl Projectable<'tcx, Provenance>,
884884
offset: u64,
885885
base_layout: TyAndLayout<'tcx>,
886886
value_layout: TyAndLayout<'tcx>,
@@ -897,7 +897,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
897897

898898
fn deref_pointer_and_read(
899899
&self,
900-
op: &impl Readable<'tcx, Provenance>,
900+
op: &impl Projectable<'tcx, Provenance>,
901901
offset: u64,
902902
base_layout: TyAndLayout<'tcx>,
903903
value_layout: TyAndLayout<'tcx>,
@@ -909,7 +909,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
909909

910910
fn deref_pointer_and_write(
911911
&mut self,
912-
op: &impl Readable<'tcx, Provenance>,
912+
op: &impl Projectable<'tcx, Provenance>,
913913
offset: u64,
914914
value: impl Into<Scalar>,
915915
base_layout: TyAndLayout<'tcx>,

0 commit comments

Comments
 (0)