@@ -180,41 +180,13 @@ impl<'tcx, Prov: Provenance> From<MPlaceTy<'tcx, Prov>> for OpTy<'tcx, Prov> {
180
180
}
181
181
}
182
182
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
-
197
183
impl < ' tcx , Prov : Provenance > From < ImmTy < ' tcx , Prov > > for OpTy < ' tcx , Prov > {
198
184
#[ inline( always) ]
199
185
fn from ( val : ImmTy < ' tcx , Prov > ) -> Self {
200
186
OpTy { op : Operand :: Immediate ( val. imm ) , layout : val. layout , align : None }
201
187
}
202
188
}
203
189
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
-
218
190
impl < ' tcx , Prov : Provenance > ImmTy < ' tcx , Prov > {
219
191
#[ inline]
220
192
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> {
341
313
& self ,
342
314
_ecx : & InterpCx < ' mir , ' tcx , M > ,
343
315
) -> InterpResult < ' tcx , OpTy < ' tcx , M :: Provenance > > {
344
- Ok ( self . into ( ) )
316
+ Ok ( self . clone ( ) . into ( ) )
345
317
}
346
318
}
347
319
@@ -400,6 +372,31 @@ impl<'tcx, Prov: Provenance + 'static> Projectable<'tcx, Prov> for OpTy<'tcx, Pr
400
372
}
401
373
}
402
374
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
+
403
400
impl < ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > InterpCx < ' mir , ' tcx , M > {
404
401
/// Try reading an immediate in memory; this is interesting particularly for `ScalarPair`.
405
402
/// 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> {
472
469
/// ConstProp needs it, though.
473
470
pub fn read_immediate_raw (
474
471
& self ,
475
- src : & OpTy < ' tcx , M :: Provenance > ,
472
+ src : & impl Readable < ' tcx , M :: Provenance > ,
476
473
) -> InterpResult < ' tcx , Either < MPlaceTy < ' tcx , M :: Provenance > , ImmTy < ' tcx , M :: Provenance > > > {
477
474
Ok ( match src. as_mplace_or_imm ( ) {
478
475
Left ( ref mplace) => {
@@ -492,14 +489,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
492
489
#[ inline( always) ]
493
490
pub fn read_immediate (
494
491
& self ,
495
- op : & OpTy < ' tcx , M :: Provenance > ,
492
+ op : & impl Readable < ' tcx , M :: Provenance > ,
496
493
) -> InterpResult < ' tcx , ImmTy < ' tcx , M :: Provenance > > {
497
494
if !matches ! (
498
- op. layout. abi,
495
+ op. layout( ) . abi,
499
496
Abi :: Scalar ( abi:: Scalar :: Initialized { .. } )
500
497
| Abi :: ScalarPair ( abi:: Scalar :: Initialized { .. } , abi:: Scalar :: Initialized { .. } )
501
498
) {
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
+ ) ;
503
504
}
504
505
let imm = self . read_immediate_raw ( op) ?. right ( ) . unwrap ( ) ;
505
506
if matches ! ( * imm, Immediate :: Uninit ) {
@@ -511,7 +512,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
511
512
/// Read a scalar from a place
512
513
pub fn read_scalar (
513
514
& self ,
514
- op : & OpTy < ' tcx , M :: Provenance > ,
515
+ op : & impl Readable < ' tcx , M :: Provenance > ,
515
516
) -> InterpResult < ' tcx , Scalar < M :: Provenance > > {
516
517
Ok ( self . read_immediate ( op) ?. to_scalar ( ) )
517
518
}
@@ -522,16 +523,22 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
522
523
/// Read a pointer from a place.
523
524
pub fn read_pointer (
524
525
& self ,
525
- op : & OpTy < ' tcx , M :: Provenance > ,
526
+ op : & impl Readable < ' tcx , M :: Provenance > ,
526
527
) -> InterpResult < ' tcx , Pointer < Option < M :: Provenance > > > {
527
528
self . read_scalar ( op) ?. to_pointer ( self )
528
529
}
529
530
/// 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 > {
531
535
self . read_scalar ( op) ?. to_target_usize ( self )
532
536
}
533
537
/// 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 > {
535
542
self . read_scalar ( op) ?. to_target_isize ( self )
536
543
}
537
544
0 commit comments