@@ -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 this local.
198- Local ( Local ) ,
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 ( ) ;
460- let base = if place. is_indirect_first_projection ( ) {
461- let base = self . locals [ place. local ] ?;
462- // Skip the initial `Deref`.
463- projection. next ( ) ;
464- AddressBase :: Deref ( base)
465- } else {
466- AddressBase :: Local ( place. local )
467- } ;
450+ let base = self . locals [ place. local ] ?;
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
@@ -775,26 +760,14 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
775760 #[ instrument( level = "trace" , skip( self ) , ret) ]
776761 fn dereference_address (
777762 & mut self ,
778- base : AddressBase ,
763+ mut base : VnIndex ,
779764 projection : & [ ProjectionElem < VnIndex , Ty < ' tcx > > ] ,
780765 ) -> Option < VnIndex > {
781- let ( mut place_ty, mut value) = match base {
782- // The base is a local, so we take the local's value and project from it.
783- AddressBase :: Local ( local) => {
784- let local = self . locals [ local] ?;
785- let place_ty = PlaceTy :: from_ty ( self . ty ( local) ) ;
786- ( place_ty, local)
787- }
788- // The base is a pointer's deref, so we introduce the implicit deref.
789- AddressBase :: Deref ( reborrow) => {
790- let place_ty = PlaceTy :: from_ty ( self . ty ( reborrow) ) ;
791- self . project ( place_ty, reborrow, ProjectionElem :: Deref ) ?
792- }
793- } ;
766+ let mut place_ty = PlaceTy :: from_ty ( self . ty ( base) ) ;
794767 for & proj in projection {
795- ( place_ty, value ) = self . project ( place_ty, value , proj) ?;
768+ ( place_ty, base ) = self . project ( place_ty, base , proj) ?;
796769 }
797- Some ( value )
770+ Some ( base )
798771 }
799772
800773 #[ instrument( level = "trace" , skip( self ) , ret) ]
@@ -1286,11 +1259,7 @@ impl<'body, 'a, 'tcx> VnState<'body, 'a, 'tcx> {
12861259 }
12871260
12881261 // `&mut *p`, `&raw *p`, etc don't change metadata.
1289- Value :: Address { base : AddressBase :: Deref ( reborrowed) , projection, .. }
1290- if projection. is_empty ( ) =>
1291- {
1292- reborrowed
1293- }
1262+ Value :: Address { base, projection : [ ProjectionElem :: Deref ] , .. } => base,
12941263
12951264 _ => break ,
12961265 } ;
0 commit comments