@@ -288,8 +288,7 @@ struct NodeAppArgs<'visit> {
288288 /// The node map of this tree.
289289 nodes : & ' visit mut UniValMap < Node > ,
290290 /// The permissions map of this tree.
291- perms : & ' visit mut UniValMap < LocationState > ,
292- wildcard_accesses : Option < & ' visit mut UniValMap < WildcardState > >
291+ loc : & ' visit mut LocationTree ,
293292}
294293/// Data given to the error handler
295294struct ErrHandlerArgs < ' node , InErr > {
@@ -309,8 +308,7 @@ struct ErrHandlerArgs<'node, InErr> {
309308struct TreeVisitor < ' tree > {
310309 tag_mapping : & ' tree UniKeyMap < BorTag > ,
311310 nodes : & ' tree mut UniValMap < Node > ,
312- perms : & ' tree mut UniValMap < LocationState > ,
313- wildcard_accesses : Option < & ' tree mut UniValMap < WildcardState > > ,
311+ loc : & ' tree mut LocationTree ,
314312}
315313
316314/// Whether to continue exploring the children recursively or not.
@@ -367,7 +365,7 @@ where
367365 idx : UniIndex ,
368366 rel_pos : AccessRelatedness ,
369367 ) -> ContinueTraversal {
370- let args = NodeAppArgs { idx, rel_pos, nodes : this. nodes , perms : this. perms , wildcard_accesses : this . wildcard_accesses . as_deref_mut ( ) } ;
368+ let args = NodeAppArgs { idx, rel_pos, nodes : this. nodes , loc : this. loc } ;
371369 ( self . f_continue ) ( & args)
372370 }
373371
@@ -377,14 +375,15 @@ where
377375 idx : UniIndex ,
378376 rel_pos : AccessRelatedness ,
379377 ) -> Result < ( ) , OutErr > {
380- ( self . f_propagate ) ( NodeAppArgs { idx, rel_pos, nodes : this. nodes , perms : this. perms , wildcard_accesses : this . wildcard_accesses . as_deref_mut ( ) } )
381- . map_err ( |error_kind| {
378+ ( self . f_propagate ) ( NodeAppArgs { idx, rel_pos, nodes : this. nodes , loc : this. loc } ) . map_err (
379+ |error_kind| {
382380 ( self . err_builder ) ( ErrHandlerArgs {
383381 error_kind,
384382 conflicting_info : & this. nodes . get ( idx) . unwrap ( ) . debug_info ,
385383 accessed_info : & this. nodes . get ( self . initial ) . unwrap ( ) . debug_info ,
386384 } )
387- } )
385+ } ,
386+ )
388387 }
389388
390389 fn go_upwards_from_accessed (
@@ -769,48 +768,43 @@ impl<'tcx> Tree {
769768 // so we use the root as a default tag
770769 ProvenanceExtra :: Wildcard => self . nodes . get ( self . root ) . unwrap ( ) . tag ,
771770 } ;
772- TreeVisitor {
773- nodes : & mut self . nodes ,
774- tag_mapping : & self . tag_mapping ,
775- perms : & mut loc. perms ,
776- wildcard_accesses : None ,
777- }
778- . traverse_this_parents_children_other (
779- start_tag,
780- // visit all children, skipping none
781- |_| ContinueTraversal :: Recurse ,
782- |args : NodeAppArgs < ' _ > | -> Result < ( ) , TransitionError > {
783- let node = args. nodes . get ( args. idx ) . unwrap ( ) ;
784- let perm = args. perms . entry ( args. idx ) ;
785-
786- let perm =
787- perm. get ( ) . copied ( ) . unwrap_or_else ( || node. default_location_state ( ) ) ;
788- if global. borrow ( ) . protected_tags . get ( & node. tag )
771+ TreeVisitor { nodes : & mut self . nodes , tag_mapping : & self . tag_mapping , loc }
772+ . traverse_this_parents_children_other (
773+ start_tag,
774+ // visit all children, skipping none
775+ |_| ContinueTraversal :: Recurse ,
776+ |args : NodeAppArgs < ' _ > | -> Result < ( ) , TransitionError > {
777+ let node = args. nodes . get ( args. idx ) . unwrap ( ) ;
778+ let perm = args. loc . perms . entry ( args. idx ) ;
779+
780+ let perm =
781+ perm. get ( ) . copied ( ) . unwrap_or_else ( || node. default_location_state ( ) ) ;
782+ if global. borrow ( ) . protected_tags . get ( & node. tag )
789783 == Some ( & ProtectorKind :: StrongProtector )
790784 // Don't check for protector if it is a Cell (see `unsafe_cell_deallocate` in `interior_mutability.rs`).
791785 // Related to https://github.com/rust-lang/rust/issues/55005.
792786 && !perm. permission . is_cell ( )
793787 // Only trigger UB if the accessed bit is set, i.e. if the protector is actually protecting this offset. See #4579.
794788 && perm. accessed
795- {
796- Err ( TransitionError :: ProtectedDealloc )
797- } else {
798- Ok ( ( ) )
799- }
800- } ,
801- |args : ErrHandlerArgs < ' _ , TransitionError > | -> InterpErrorKind < ' tcx > {
802- let ErrHandlerArgs { error_kind, conflicting_info, accessed_info } = args;
803- TbError {
804- conflicting_info,
805- access_cause : diagnostics:: AccessCause :: Dealloc ,
806- alloc_id,
807- error_offset : loc_range. start ,
808- error_kind,
809- accessed_info : Some ( accessed_info) ,
810- }
811- . build ( )
812- } ,
813- ) ?;
789+ {
790+ Err ( TransitionError :: ProtectedDealloc )
791+ } else {
792+ Ok ( ( ) )
793+ }
794+ } ,
795+ |args : ErrHandlerArgs < ' _ , TransitionError > | -> InterpErrorKind < ' tcx > {
796+ let ErrHandlerArgs { error_kind, conflicting_info, accessed_info } = args;
797+ TbError {
798+ conflicting_info,
799+ access_cause : diagnostics:: AccessCause :: Dealloc ,
800+ alloc_id,
801+ error_offset : loc_range. start ,
802+ error_kind,
803+ accessed_info : Some ( accessed_info) ,
804+ }
805+ . build ( )
806+ } ,
807+ ) ?;
814808 }
815809 interp_ok ( ( ) )
816810 }
@@ -857,18 +851,18 @@ impl<'tcx> Tree {
857851 // the `RangeMap` on which we are currently working).
858852 let node_skipper = |access_kind : AccessKind , args : & NodeAppArgs < ' _ > | -> ContinueTraversal {
859853 let node = args. nodes . get ( args. idx ) . unwrap ( ) ;
860- let perm = args. perms . get ( args. idx ) ;
854+ let perm = args. loc . perms . get ( args. idx ) ;
861855
862856 let old_state = perm. copied ( ) . unwrap_or_else ( || node. default_location_state ( ) ) ;
863857 old_state. skip_if_known_noop ( access_kind, args. rel_pos )
864858 } ;
865859 let node_app = |perms_range : Range < u64 > ,
866860 access_kind : AccessKind ,
867861 access_cause : diagnostics:: AccessCause ,
868- mut args : NodeAppArgs < ' _ > |
862+ args : NodeAppArgs < ' _ > |
869863 -> Result < ( ) , TransitionError > {
870864 let node = args. nodes . get_mut ( args. idx ) . unwrap ( ) ;
871- let mut perm = args. perms . entry ( args. idx ) ;
865+ let mut perm = args. loc . perms . entry ( args. idx ) ;
872866
873867 let state = perm. or_insert ( node. default_location_state ( ) ) ;
874868 // Call this function now, which ensures it is only called when
@@ -892,21 +886,20 @@ impl<'tcx> Tree {
892886 // we need to update the wildcard access tracking information,
893887 // if the permission of an exposed pointer changes
894888 if node. is_exposed {
895- let wildcard_accesses = args. wildcard_accesses . as_deref_mut ( ) . unwrap ( ) ;
896889 //Protected doesnt change during access.
897890 let access_type = state. permission . strongest_allowed_child_access ( protected) ;
898891 WildcardState :: update_exposure (
899892 args. idx ,
900893 access_type,
901- & args. nodes ,
902- wildcard_accesses,
894+ args. nodes ,
895+ & mut args . loc . wildcard_accesses ,
903896 ) ;
904897 #[ cfg( feature = "expensive-consistency-checks" ) ]
905898 WildcardState :: verify_external_consistency (
906- idx,
907- this . nodes ,
908- this . perms ,
909- wildcard_accesses,
899+ args . idx ,
900+ & args . nodes ,
901+ & args . loc . perms ,
902+ & args . loc . wildcard_accesses ,
910903 & global. borrow ( ) . protected_tags ,
911904 ) ;
912905 }
@@ -936,20 +929,13 @@ impl<'tcx> Tree {
936929 // Default branch: this is a "normal" access through a known range.
937930 // We iterate over affected locations and traverse the tree for each of them.
938931 for ( loc_range, loc) in self . locations . iter_mut ( access_range. start , access_range. size ) {
939- TreeVisitor {
940- nodes : & mut self . nodes ,
941- tag_mapping : & self . tag_mapping ,
942- perms : & mut loc. perms ,
943- wildcard_accesses : Some ( & mut loc. wildcard_accesses ) ,
944- }
945- . traverse_this_parents_children_other (
946- tag,
947- |args| node_skipper ( access_kind, args) ,
948- |args| {
949- node_app ( loc_range. clone ( ) , access_kind, access_cause, args)
950- } ,
951- |args| err_handler ( loc_range. clone ( ) , access_cause, args) ,
952- ) ?;
932+ TreeVisitor { nodes : & mut self . nodes , tag_mapping : & self . tag_mapping , loc }
933+ . traverse_this_parents_children_other (
934+ tag,
935+ |args| node_skipper ( access_kind, args) ,
936+ |args| node_app ( loc_range. clone ( ) , access_kind, access_cause, args) ,
937+ |args| err_handler ( loc_range. clone ( ) , access_cause, args) ,
938+ ) ?;
953939 }
954940 } else {
955941 // This is a special access through the entire allocation.
@@ -969,25 +955,13 @@ impl<'tcx> Tree {
969955 && p. accessed
970956 {
971957 let access_cause = diagnostics:: AccessCause :: FnExit ( access_kind) ;
972- TreeVisitor {
973- nodes : & mut self . nodes ,
974- tag_mapping : & self . tag_mapping ,
975- perms : & mut loc. perms ,
976- wildcard_accesses : Some ( & mut loc. wildcard_accesses ) ,
977- }
978- . traverse_nonchildren (
979- tag,
980- |args| node_skipper ( access_kind, args) ,
981- |args| {
982- node_app (
983- loc_range. clone ( ) ,
984- access_kind,
985- access_cause,
986- args
987- )
988- } ,
989- |args| err_handler ( loc_range. clone ( ) , access_cause, args) ,
990- ) ?;
958+ TreeVisitor { nodes : & mut self . nodes , tag_mapping : & self . tag_mapping , loc }
959+ . traverse_nonchildren (
960+ tag,
961+ |args| node_skipper ( access_kind, args) ,
962+ |args| node_app ( loc_range. clone ( ) , access_kind, access_cause, args) ,
963+ |args| err_handler ( loc_range. clone ( ) , access_cause, args) ,
964+ ) ?;
991965 }
992966 }
993967 }
0 commit comments