@@ -278,42 +278,34 @@ where
278
278
let meta = val. to_meta ( ) ?;
279
279
let ptr = val. to_scalar_ptr ( ) ?;
280
280
let mplace = MemPlace { ptr, align, meta } ;
281
+ let mut mplace = MPlaceTy { mplace, layout } ;
281
282
// Pointer tag tracking might want to adjust the tag.
282
- let mplace = if M :: ENABLE_PTR_TRACKING_HOOKS {
283
- let ( size, _) = self . size_and_align_of ( meta, layout) ?
284
- // for extern types, just cover what we can
285
- . unwrap_or_else ( || layout. size_and_align ( ) ) ;
283
+ if M :: ENABLE_PTR_TRACKING_HOOKS {
286
284
let mutbl = match val. layout . ty . sty {
287
285
// `builtin_deref` considers boxes immutable, that's useless for our purposes
288
286
ty:: Ref ( _, _, mutbl) => Some ( mutbl) ,
289
287
ty:: Adt ( def, _) if def. is_box ( ) => Some ( hir:: MutMutable ) ,
290
288
ty:: RawPtr ( _) => None ,
291
289
_ => bug ! ( "Unexpected pointer type {}" , val. layout. ty. sty) ,
292
290
} ;
293
- M :: tag_dereference ( self , mplace, pointee_type, size, mutbl) ?
294
- } else {
295
- mplace
296
- } ;
297
- Ok ( MPlaceTy { mplace, layout } )
291
+ mplace. mplace . ptr = M :: tag_dereference ( self , mplace, mutbl) ?;
292
+ }
293
+ // Done
294
+ Ok ( mplace)
298
295
}
299
296
300
297
/// Turn a mplace into a (thin or fat) pointer, as a reference, pointing to the same space.
301
298
/// This is the inverse of `ref_to_mplace`.
302
299
/// `mutbl` indicates whether we are create a shared or mutable ref, or a raw pointer (`None`).
303
300
pub fn create_ref (
304
301
& mut self ,
305
- place : MPlaceTy < ' tcx , M :: PointerTag > ,
302
+ mut place : MPlaceTy < ' tcx , M :: PointerTag > ,
306
303
mutbl : Option < hir:: Mutability > ,
307
304
) -> EvalResult < ' tcx , Value < M :: PointerTag > > {
308
305
// Pointer tag tracking might want to adjust the tag
309
- let place = if M :: ENABLE_PTR_TRACKING_HOOKS {
310
- let ( size, _) = self . size_and_align_of_mplace ( place) ?
311
- // for extern types, just cover what we can
312
- . unwrap_or_else ( || place. layout . size_and_align ( ) ) ;
313
- M :: tag_reference ( self , * place, place. layout . ty , size, mutbl) ?
314
- } else {
315
- * place
316
- } ;
306
+ if M :: ENABLE_PTR_TRACKING_HOOKS {
307
+ place. mplace . ptr = M :: tag_reference ( self , place, mutbl) ?
308
+ }
317
309
Ok ( match place. meta {
318
310
None => Value :: Scalar ( place. ptr . into ( ) ) ,
319
311
Some ( meta) => Value :: ScalarPair ( place. ptr . into ( ) , meta. into ( ) ) ,
@@ -489,6 +481,8 @@ where
489
481
490
482
/// Get the place of a field inside the place, and also the field's type.
491
483
/// Just a convenience function, but used quite a bit.
484
+ /// This is the only projection that might have a side-effect: We cannot project
485
+ /// into the field of a local `ScalarPair`, we have to first allocate it.
492
486
pub fn place_field (
493
487
& mut self ,
494
488
base : PlaceTy < ' tcx , M :: PointerTag > ,
@@ -501,7 +495,7 @@ where
501
495
}
502
496
503
497
pub fn place_downcast (
504
- & mut self ,
498
+ & self ,
505
499
base : PlaceTy < ' tcx , M :: PointerTag > ,
506
500
variant : usize ,
507
501
) -> EvalResult < ' tcx , PlaceTy < ' tcx , M :: PointerTag > > {
@@ -510,7 +504,7 @@ where
510
504
Place :: Ptr ( mplace) =>
511
505
self . mplace_downcast ( MPlaceTy { mplace, layout : base. layout } , variant) ?. into ( ) ,
512
506
Place :: Local { .. } => {
513
- let layout = base. layout . for_variant ( & self , variant) ;
507
+ let layout = base. layout . for_variant ( self , variant) ;
514
508
PlaceTy { layout, ..base }
515
509
}
516
510
} )
@@ -643,7 +637,7 @@ where
643
637
644
638
if M :: enforce_validity ( self ) {
645
639
// Data got changed, better make sure it matches the type!
646
- self . validate_operand ( self . place_to_op ( dest) ?, & mut vec ! [ ] , None , /*const_mode*/ false ) ?;
640
+ self . validate_operand ( self . place_to_op ( dest) ?, vec ! [ ] , None , /*const_mode*/ false ) ?;
647
641
}
648
642
649
643
Ok ( ( ) )
@@ -765,7 +759,7 @@ where
765
759
766
760
if M :: enforce_validity ( self ) {
767
761
// Data got changed, better make sure it matches the type!
768
- self . validate_operand ( self . place_to_op ( dest) ?, & mut vec ! [ ] , None , /*const_mode*/ false ) ?;
762
+ self . validate_operand ( self . place_to_op ( dest) ?, vec ! [ ] , None , /*const_mode*/ false ) ?;
769
763
}
770
764
771
765
Ok ( ( ) )
@@ -843,7 +837,7 @@ where
843
837
844
838
if M :: enforce_validity ( self ) {
845
839
// Data got changed, better make sure it matches the type!
846
- self . validate_operand ( dest. into ( ) , & mut vec ! [ ] , None , /*const_mode*/ false ) ?;
840
+ self . validate_operand ( dest. into ( ) , vec ! [ ] , None , /*const_mode*/ false ) ?;
847
841
}
848
842
849
843
Ok ( ( ) )
0 commit comments