Skip to content

Commit fa60ea7

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

5 files changed

Lines changed: 21 additions & 47 deletions

File tree

‎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
usesuper::{
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
pubfnread_discriminant(
6262
&self,
63-
op:&implReadable<'tcx,M::Provenance>,
63+
op:&implProjectable<'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
pubuseself::machine::{compile_time_machine,AllocMap,Machine,MayLeak,ReturnAction};
3434
pubuseself::memory::{AllocKind,AllocRef,AllocRefMut,FnVal,Memory,MemoryKind};
3535
useself::operand::Operand;
36-
pubuseself::operand::{ImmTy,Immediate,OpTy,Readable};
36+
pubuseself::operand::{ImmTy,Immediate,OpTy};
3737
pubuseself::place::{MPlaceTy,MemPlaceMeta,PlaceTy,Writeable};
3838
useself::place::{MemPlace,Place};
3939
pubuseself::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-
pubtraitReadable<'tcx,Prov:Provenance>:Projectable<'tcx,Prov>{
495-
fnas_mplace_or_imm(&self) -> Either<MPlaceTy<'tcx,Prov>,ImmTy<'tcx,Prov>>;
496-
}
497-
498-
impl<'tcx,Prov:Provenance>Readable<'tcx,Prov>forOpTy<'tcx,Prov>{
499-
#[inline(always)]
500-
fnas_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>forMPlaceTy<'tcx,Prov>{
506-
#[inline(always)]
507-
fnas_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>forImmTy<'tcx,Prov>{
513-
#[inline(always)]
514-
fnas_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
pubfnread_immediate_raw(
590564
&self,
591-
src:&implReadable<'tcx,M::Provenance>,
565+
src:&implProjectable<'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
ifletSome(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
pubfnread_immediate(
610584
&self,
611-
op:&implReadable<'tcx,M::Provenance>,
585+
op:&implProjectable<'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
pubfnread_scalar(
629603
&self,
630-
op:&implReadable<'tcx,M::Provenance>,
604+
op:&implProjectable<'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
pubfnread_pointer(
640614
&self,
641-
op:&implReadable<'tcx,M::Provenance>,
615+
op:&implProjectable<'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
pubfnread_target_usize(
647621
&self,
648-
op:&implReadable<'tcx,M::Provenance>,
622+
op:&implProjectable<'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
pubfnread_target_isize(
654628
&self,
655-
op:&implReadable<'tcx,M::Provenance>,
629+
op:&implProjectable<'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
usesuper::{
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
pubfnderef_pointer(
438438
&self,
439-
src:&implReadable<'tcx,M::Provenance>,
439+
src:&implProjectable<'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)fncopy_op_no_dest_validation(
770770
&mutself,
771-
src:&implReadable<'tcx,M::Provenance>,
771+
src:&implProjectable<'tcx,M::Provenance>,
772772
dest:&implWriteable<'tcx,M::Provenance>,
773773
) -> InterpResult<'tcx>{
774774
self.copy_op_inner(
@@ -781,7 +781,7 @@ where
781781
#[inline(always)]
782782
pubfncopy_op_allow_transmute(
783783
&mutself,
784-
src:&implReadable<'tcx,M::Provenance>,
784+
src:&implProjectable<'tcx,M::Provenance>,
785785
dest:&implWriteable<'tcx,M::Provenance>,
786786
) -> InterpResult<'tcx>{
787787
self.copy_op_inner(
@@ -794,7 +794,7 @@ where
794794
#[inline(always)]
795795
pubfncopy_op(
796796
&mutself,
797-
src:&implReadable<'tcx,M::Provenance>,
797+
src:&implProjectable<'tcx,M::Provenance>,
798798
dest:&implWriteable<'tcx,M::Provenance>,
799799
) -> InterpResult<'tcx>{
800800
self.copy_op_inner(
@@ -808,7 +808,7 @@ where
808808
#[instrument(skip(self), level = "trace")]
809809
fncopy_op_inner(
810810
&mutself,
811-
src:&implReadable<'tcx,M::Provenance>,
811+
src:&implProjectable<'tcx,M::Provenance>,
812812
dest:&implWriteable<'tcx,M::Provenance>,
813813
allow_transmute:bool,
814814
validate_dest:bool,
@@ -843,7 +843,7 @@ where
843843
#[instrument(skip(self), level = "trace")]
844844
fncopy_op_no_validate(
845845
&mutself,
846-
src:&implReadable<'tcx,M::Provenance>,
846+
src:&implProjectable<'tcx,M::Provenance>,
847847
dest:&implWriteable<'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
fnderef_pointer_as(
871871
&self,
872-
op:&implReadable<'tcx,Provenance>,
872+
op:&implProjectable<'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
fnderef_pointer_and_offset(
882882
&self,
883-
op:&implReadable<'tcx,Provenance>,
883+
op:&implProjectable<'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
fnderef_pointer_and_read(
899899
&self,
900-
op:&implReadable<'tcx,Provenance>,
900+
op:&implProjectable<'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
fnderef_pointer_and_write(
911911
&mutself,
912-
op:&implReadable<'tcx,Provenance>,
912+
op:&implProjectable<'tcx,Provenance>,
913913
offset:u64,
914914
value:implInto<Scalar>,
915915
base_layout:TyAndLayout<'tcx>,

0 commit comments

Comments
 (0)