@@ -180,41 +180,13 @@ impl<'tcx, Prov: Provenance> From<MPlaceTy<'tcx, Prov>> for OpTy<'tcx, Prov> {
180180 }
181181}
182182
183- impl < ' tcx , Prov : Provenance > From < & ' _ MPlaceTy < ' tcx , Prov > > for OpTy < ' tcx , Prov > {
184- #[ inline( always) ]
185- fn from ( mplace : & MPlaceTy < ' tcx , Prov > ) -> Self {
186- OpTy { op : Operand :: Indirect ( * * mplace) , layout : mplace. layout , align : Some ( mplace. align ) }
187- }
188- }
189-
190- impl < ' tcx , Prov : Provenance > From < & ' _ mut MPlaceTy < ' tcx , Prov > > for OpTy < ' tcx , Prov > {
191- #[ inline( always) ]
192- fn from ( mplace : & mut MPlaceTy < ' tcx , Prov > ) -> Self {
193- OpTy { op : Operand :: Indirect ( * * mplace) , layout : mplace. layout , align : Some ( mplace. align ) }
194- }
195- }
196-
197183impl < ' tcx , Prov : Provenance > From < ImmTy < ' tcx , Prov > > for OpTy < ' tcx , Prov > {
198184 #[ inline( always) ]
199185 fn from ( val : ImmTy < ' tcx , Prov > ) -> Self {
200186 OpTy { op : Operand :: Immediate ( val. imm ) , layout : val. layout , align : None }
201187 }
202188}
203189
204- impl < ' tcx , Prov : Provenance > From < & ' _ ImmTy < ' tcx , Prov > > for OpTy < ' tcx , Prov > {
205- #[ inline( always) ]
206- fn from ( val : & ImmTy < ' tcx , Prov > ) -> Self {
207- OpTy { op : Operand :: Immediate ( val. imm ) , layout : val. layout , align : None }
208- }
209- }
210-
211- impl < ' tcx , Prov : Provenance > From < & ' _ mut ImmTy < ' tcx , Prov > > for OpTy < ' tcx , Prov > {
212- #[ inline( always) ]
213- fn from ( val : & mut ImmTy < ' tcx , Prov > ) -> Self {
214- OpTy { op : Operand :: Immediate ( val. imm ) , layout : val. layout , align : None }
215- }
216- }
217-
218190impl < ' tcx , Prov : Provenance > ImmTy < ' tcx , Prov > {
219191 #[ inline]
220192 pub fn from_scalar ( val : Scalar < Prov > , layout : TyAndLayout < ' tcx > ) -> Self {
@@ -341,7 +313,7 @@ impl<'tcx, Prov: Provenance> Projectable<'tcx, Prov> for ImmTy<'tcx, Prov> {
341313 & self ,
342314 _ecx : & InterpCx < ' mir , ' tcx , M > ,
343315 ) -> InterpResult < ' tcx , OpTy < ' tcx , M :: Provenance > > {
344- Ok ( self . into ( ) )
316+ Ok ( self . clone ( ) . into ( ) )
345317 }
346318}
347319
@@ -400,6 +372,31 @@ impl<'tcx, Prov: Provenance + 'static> Projectable<'tcx, Prov> for OpTy<'tcx, Pr
400372 }
401373}
402374
375+ pub trait Readable < ' tcx , Prov : Provenance > : Projectable < ' tcx , Prov > {
376+ fn as_mplace_or_imm ( & self ) -> Either < MPlaceTy < ' tcx , Prov > , ImmTy < ' tcx , Prov > > ;
377+ }
378+
379+ impl < ' tcx , Prov : Provenance + ' static > Readable < ' tcx , Prov > for OpTy < ' tcx , Prov > {
380+ #[ inline( always) ]
381+ fn as_mplace_or_imm ( & self ) -> Either < MPlaceTy < ' tcx , Prov > , ImmTy < ' tcx , Prov > > {
382+ self . as_mplace_or_imm ( )
383+ }
384+ }
385+
386+ impl < ' tcx , Prov : Provenance + ' static > Readable < ' tcx , Prov > for MPlaceTy < ' tcx , Prov > {
387+ #[ inline( always) ]
388+ fn as_mplace_or_imm ( & self ) -> Either < MPlaceTy < ' tcx , Prov > , ImmTy < ' tcx , Prov > > {
389+ Left ( self . clone ( ) )
390+ }
391+ }
392+
393+ impl < ' tcx , Prov : Provenance > Readable < ' tcx , Prov > for ImmTy < ' tcx , Prov > {
394+ #[ inline( always) ]
395+ fn as_mplace_or_imm ( & self ) -> Either < MPlaceTy < ' tcx , Prov > , ImmTy < ' tcx , Prov > > {
396+ Right ( self . clone ( ) )
397+ }
398+ }
399+
403400impl < ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > InterpCx < ' mir , ' tcx , M > {
404401 /// Try reading an immediate in memory; this is interesting particularly for `ScalarPair`.
405402 /// Returns `None` if the layout does not permit loading this as a value.
@@ -472,7 +469,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
472469 /// ConstProp needs it, though.
473470 pub fn read_immediate_raw (
474471 & self ,
475- src : & OpTy < ' tcx , M :: Provenance > ,
472+ src : & impl Readable < ' tcx , M :: Provenance > ,
476473 ) -> InterpResult < ' tcx , Either < MPlaceTy < ' tcx , M :: Provenance > , ImmTy < ' tcx , M :: Provenance > > > {
477474 Ok ( match src. as_mplace_or_imm ( ) {
478475 Left ( ref mplace) => {
@@ -492,14 +489,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
492489 #[ inline( always) ]
493490 pub fn read_immediate (
494491 & self ,
495- op : & OpTy < ' tcx , M :: Provenance > ,
492+ op : & impl Readable < ' tcx , M :: Provenance > ,
496493 ) -> InterpResult < ' tcx , ImmTy < ' tcx , M :: Provenance > > {
497494 if !matches ! (
498- op. layout. abi,
495+ op. layout( ) . abi,
499496 Abi :: Scalar ( abi:: Scalar :: Initialized { .. } )
500497 | Abi :: ScalarPair ( abi:: Scalar :: Initialized { .. } , abi:: Scalar :: Initialized { .. } )
501498 ) {
502- span_bug ! ( self . cur_span( ) , "primitive read not possible for type: {:?}" , op. layout. ty) ;
499+ span_bug ! (
500+ self . cur_span( ) ,
501+ "primitive read not possible for type: {:?}" ,
502+ op. layout( ) . ty
503+ ) ;
503504 }
504505 let imm = self . read_immediate_raw ( op) ?. right ( ) . unwrap ( ) ;
505506 if matches ! ( * imm, Immediate :: Uninit ) {
@@ -511,7 +512,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
511512 /// Read a scalar from a place
512513 pub fn read_scalar (
513514 & self ,
514- op : & OpTy < ' tcx , M :: Provenance > ,
515+ op : & impl Readable < ' tcx , M :: Provenance > ,
515516 ) -> InterpResult < ' tcx , Scalar < M :: Provenance > > {
516517 Ok ( self . read_immediate ( op) ?. to_scalar ( ) )
517518 }
@@ -522,16 +523,22 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
522523 /// Read a pointer from a place.
523524 pub fn read_pointer (
524525 & self ,
525- op : & OpTy < ' tcx , M :: Provenance > ,
526+ op : & impl Readable < ' tcx , M :: Provenance > ,
526527 ) -> InterpResult < ' tcx , Pointer < Option < M :: Provenance > > > {
527528 self . read_scalar ( op) ?. to_pointer ( self )
528529 }
529530 /// Read a pointer-sized unsigned integer from a place.
530- pub fn read_target_usize ( & self , op : & OpTy < ' tcx , M :: Provenance > ) -> InterpResult < ' tcx , u64 > {
531+ pub fn read_target_usize (
532+ & self ,
533+ op : & impl Readable < ' tcx , M :: Provenance > ,
534+ ) -> InterpResult < ' tcx , u64 > {
531535 self . read_scalar ( op) ?. to_target_usize ( self )
532536 }
533537 /// Read a pointer-sized signed integer from a place.
534- pub fn read_target_isize ( & self , op : & OpTy < ' tcx , M :: Provenance > ) -> InterpResult < ' tcx , i64 > {
538+ pub fn read_target_isize (
539+ & self ,
540+ op : & impl Readable < ' tcx , M :: Provenance > ,
541+ ) -> InterpResult < ' tcx , i64 > {
535542 self . read_scalar ( op) ?. to_target_isize ( self )
536543 }
537544
0 commit comments