@@ -192,14 +192,6 @@ enum AddressKind {
192192 Address ( RawPtrKind ) ,
193193}
194194
195- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
196- enum AddressBase {
197- /// This address is based on the local.
198- Local ( VnIndex ) ,
199- /// This address is based on the deref of this pointer.
200- Deref ( VnIndex ) ,
201- }
202-
203195#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
204196enum Value < ' a , ' tcx > {
205197 // Root values.
@@ -232,9 +224,8 @@ enum Value<'a, 'tcx> {
232224 Repeat ( VnIndex , ty:: Const < ' tcx > ) ,
233225 /// The address of a place.
234226 Address {
235- base : AddressBase ,
227+ base : VnIndex ,
236228 // We do not use a plain `Place` as we want to be able to reason about indices.
237- // This does not contain any `Deref` projection.
238229 projection : & ' a [ ProjectionElem < VnIndex , Ty < ' tcx > > ] ,
239230 kind : AddressKind ,
240231 /// Give each borrow and pointer a different provenance, so we don't merge them.
@@ -456,18 +447,12 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
456447 AddressKind :: Address ( mutbl) => Ty :: new_ptr ( self . tcx , pty, mutbl. to_mutbl_lossy ( ) ) ,
457448 } ;
458449
459- let mut projection = place. projection . iter ( ) ;
460450 let base = self . locals [ place. local ] ?;
461- let base = if place. is_indirect_first_projection ( ) {
462- // Skip the initial `Deref`.
463- projection. next ( ) ;
464- AddressBase :: Deref ( base)
465- } else {
466- AddressBase :: Local ( base)
467- } ;
468451 // Do not try evaluating inside `Index`, this has been done by `simplify_place_projection`.
469- let projection =
470- projection. map ( |proj| proj. try_map ( |index| self . locals [ index] , |ty| ty) . ok_or ( ( ) ) ) ;
452+ let projection = place
453+ . projection
454+ . iter ( )
455+ . map ( |proj| proj. try_map ( |index| self . locals [ index] , |ty| ty) . ok_or ( ( ) ) ) ;
471456 let projection = self . arena . try_alloc_from_iter ( projection) . ok ( ) ?;
472457
473458 let index = self . values . insert_unique ( ty, |provenance| Value :: Address {
@@ -644,12 +629,12 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
644629 self . ecx . project ( base, elem) . discard_err ( ) ?
645630 }
646631 Address { base, projection, .. } => {
647- debug_assert ! ( !projection. contains( & ProjectionElem :: Deref ) ) ;
648- let pointer = match base {
649- AddressBase :: Deref ( pointer) => self . eval_to_const ( pointer) ?,
632+ let mut projection = projection. iter ( ) ;
633+ let Some ( ProjectionElem :: Deref ) = projection. next ( ) else {
650634 // We have no stack to point to.
651- AddressBase :: Local ( _ ) => return None ,
635+ return None ;
652636 } ;
637+ let pointer = self . eval_to_const ( base) ?;
653638 let mut mplace = self . ecx . deref_pointer ( pointer) . discard_err ( ) ?;
654639 for elem in projection {
655640 // `Index` by constants should have been replaced by `ConstantIndex` by
@@ -782,25 +767,14 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
782767 #[ instrument( level = "trace" , skip( self ) , ret) ]
783768 fn dereference_address (
784769 & mut self ,
785- base : AddressBase ,
770+ mut base : VnIndex ,
786771 projection : & [ ProjectionElem < VnIndex , Ty < ' tcx > > ] ,
787772 ) -> Option < VnIndex > {
788- let ( mut place_ty, mut value) = match base {
789- // The base is a local, so we take the local's value and project from it.
790- AddressBase :: Local ( local) => {
791- let place_ty = PlaceTy :: from_ty ( self . ty ( local) ) ;
792- ( place_ty, local)
793- }
794- // The base is a pointer's deref, so we introduce the implicit deref.
795- AddressBase :: Deref ( reborrow) => {
796- let place_ty = PlaceTy :: from_ty ( self . ty ( reborrow) ) ;
797- self . project ( place_ty, reborrow, ProjectionElem :: Deref ) ?
798- }
799- } ;
773+ let mut place_ty = PlaceTy :: from_ty ( self . ty ( base) ) ;
800774 for & proj in projection {
801- ( place_ty, value ) = self . project ( place_ty, value , proj) ?;
775+ ( place_ty, base ) = self . project ( place_ty, base , proj) ?;
802776 }
803- Some ( value )
777+ Some ( base )
804778 }
805779
806780 #[ instrument( level = "trace" , skip( self ) , ret) ]
@@ -1290,11 +1264,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
12901264 }
12911265
12921266 // `&mut *p`, `&raw *p`, etc don't change metadata.
1293- Value :: Address { base : AddressBase :: Deref ( reborrowed) , projection, .. }
1294- if projection. is_empty ( ) =>
1295- {
1296- reborrowed
1297- }
1267+ Value :: Address { base, projection : [ ProjectionElem :: Deref ] , .. } => base,
12981268
12991269 _ => break ,
13001270 } ;
0 commit comments