@@ -33,18 +33,18 @@ mod tests;
33
33
/// Data for a single *location*.
34
34
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
35
35
pub ( super ) struct LocationState {
36
- /// A location is initialized when it is child-accessed for the first time (and the initial
36
+ /// A location is "accessed" when it is child-accessed for the first time (and the initial
37
37
/// retag initializes the location for the range covered by the type), and it then stays
38
- /// initialized forever.
39
- /// For initialized locations, "permission" is the current permission. However, for
40
- /// uninitialized locations, we still need to track the "future initial permission": this will
38
+ /// accessed forever.
39
+ /// For accessed locations, "permission" is the current permission. However, for
40
+ /// non-accessed locations, we still need to track the "future initial permission": this will
41
41
/// start out to be `default_initial_perm`, but foreign accesses need to be taken into account.
42
42
/// Crucially however, while transitions to `Disabled` would usually be UB if this location is
43
- /// protected, that is *not* the case for uninitialized locations. Instead we just have a latent
43
+ /// protected, that is *not* the case for non-accessed locations. Instead we just have a latent
44
44
/// "future initial permission" of `Disabled`, causing UB only if an access is ever actually
45
45
/// performed.
46
- /// Note that the tree root is also always initialized , as if the allocation was a write access.
47
- initialized : bool ,
46
+ /// Note that the tree root is also always accessed , as if the allocation was a write access.
47
+ accessed : bool ,
48
48
/// This pointer's current permission / future initial permission.
49
49
permission : Permission ,
50
50
/// See `foreign_access_skipping.rs`.
@@ -59,30 +59,30 @@ impl LocationState {
59
59
/// to any foreign access yet.
60
60
/// The permission is not allowed to be `Active`.
61
61
/// `sifa` is the (strongest) idempotent foreign access, see `foreign_access_skipping.rs`
62
- pub fn new_uninit ( permission : Permission , sifa : IdempotentForeignAccess ) -> Self {
62
+ pub fn new_non_accessed ( permission : Permission , sifa : IdempotentForeignAccess ) -> Self {
63
63
assert ! ( permission. is_initial( ) || permission. is_disabled( ) ) ;
64
- Self { permission, initialized : false , idempotent_foreign_access : sifa }
64
+ Self { permission, accessed : false , idempotent_foreign_access : sifa }
65
65
}
66
66
67
67
/// Constructs a new initial state. It has not yet been subjected
68
68
/// to any foreign access. However, it is already marked as having been accessed.
69
69
/// `sifa` is the (strongest) idempotent foreign access, see `foreign_access_skipping.rs`
70
- pub fn new_init ( permission : Permission , sifa : IdempotentForeignAccess ) -> Self {
71
- Self { permission, initialized : true , idempotent_foreign_access : sifa }
70
+ pub fn new_accessed ( permission : Permission , sifa : IdempotentForeignAccess ) -> Self {
71
+ Self { permission, accessed : true , idempotent_foreign_access : sifa }
72
72
}
73
73
74
- /// Check if the location has been initialized , i.e. if it has
74
+ /// Check if the location has been accessed , i.e. if it has
75
75
/// ever been accessed through a child pointer.
76
- pub fn is_initialized ( & self ) -> bool {
77
- self . initialized
76
+ pub fn is_accessed ( & self ) -> bool {
77
+ self . accessed
78
78
}
79
79
80
80
/// Check if the state can exist as the initial permission of a pointer.
81
81
///
82
- /// Do not confuse with `is_initialized `, the two are almost orthogonal
83
- /// as apart from `Active` which is not initial and must be initialized ,
82
+ /// Do not confuse with `is_accessed `, the two are almost orthogonal
83
+ /// as apart from `Active` which is not initial and must be accessed ,
84
84
/// any other permission can have an arbitrary combination of being
85
- /// initial/initialized .
85
+ /// initial/accessed .
86
86
/// FIXME: when the corresponding `assert` in `tree_borrows/mod.rs` finally
87
87
/// passes and can be uncommented, remove this `#[allow(dead_code)]`.
88
88
#[ cfg_attr( not( test) , allow( dead_code) ) ]
@@ -96,8 +96,8 @@ impl LocationState {
96
96
97
97
/// Apply the effect of an access to one location, including
98
98
/// - applying `Permission::perform_access` to the inner `Permission`,
99
- /// - emitting protector UB if the location is initialized ,
100
- /// - updating the initialized status (child accesses produce initialized locations).
99
+ /// - emitting protector UB if the location is accessed ,
100
+ /// - updating the accessed status (child accesses produce accessed locations).
101
101
fn perform_access (
102
102
& mut self ,
103
103
access_kind : AccessKind ,
@@ -107,23 +107,23 @@ impl LocationState {
107
107
let old_perm = self . permission ;
108
108
let transition = Permission :: perform_access ( access_kind, rel_pos, old_perm, protected)
109
109
. ok_or ( TransitionError :: ChildAccessForbidden ( old_perm) ) ?;
110
- self . initialized |= !rel_pos. is_foreign ( ) ;
110
+ self . accessed |= !rel_pos. is_foreign ( ) ;
111
111
self . permission = transition. applied ( old_perm) . unwrap ( ) ;
112
- // Why do only initialized locations cause protector errors?
112
+ // Why do only accessed locations cause protector errors?
113
113
// Consider two mutable references `x`, `y` into disjoint parts of
114
114
// the same allocation. A priori, these may actually both be used to
115
115
// access the entire allocation, as long as only reads occur. However,
116
116
// a write to `y` needs to somehow record that `x` can no longer be used
117
- // on that location at all. For these uninitialized locations (i.e., locations
117
+ // on that location at all. For these non-accessed locations (i.e., locations
118
118
// that haven't been accessed with `x` yet), we track the "future initial state":
119
119
// it defaults to whatever the initial state of the tag is,
120
120
// but the access to `y` moves that "future initial state" of `x` to `Disabled`.
121
121
// However, usually a `Reserved -> Disabled` transition would be UB due to the protector!
122
122
// So clearly protectors shouldn't fire for such "future initial state" transitions.
123
123
//
124
124
// See the test `two_mut_protected_same_alloc` in `tests/pass/tree_borrows/tree-borrows.rs`
125
- // for an example of safe code that would be UB if we forgot to check `self.initialized `.
126
- if protected && self . initialized && transition. produces_disabled ( ) {
125
+ // for an example of safe code that would be UB if we forgot to check `self.accessed `.
126
+ if protected && self . accessed && transition. produces_disabled ( ) {
127
127
return Err ( TransitionError :: ProtectedDisabled ( old_perm) ) ;
128
128
}
129
129
Ok ( transition)
@@ -158,11 +158,11 @@ impl LocationState {
158
158
self . idempotent_foreign_access . can_skip_foreign_access ( happening_now) ;
159
159
if self . permission . is_disabled ( ) {
160
160
// A foreign access to a `Disabled` tag will have almost no observable effect.
161
- // It's a theorem that `Disabled` node have no protected initialized children,
161
+ // It's a theorem that `Disabled` node have no protected accessed children,
162
162
// and so this foreign access will never trigger any protector.
163
- // (Intuition: You're either protected initialized , and thus can't become Disabled
164
- // or you're already Disabled protected, but not initialized , and then can't
165
- // become initialized since that requires a child access, which Disabled blocks.)
163
+ // (Intuition: You're either protected accessed , and thus can't become Disabled
164
+ // or you're already Disabled protected, but not accessed , and then can't
165
+ // become accessed since that requires a child access, which Disabled blocks.)
166
166
// Further, the children will never be able to read or write again, since they
167
167
// have a `Disabled` parent. So this only affects diagnostics, such that the
168
168
// blocking write will still be identified directly, just at a different tag.
@@ -218,7 +218,7 @@ impl LocationState {
218
218
impl fmt:: Display for LocationState {
219
219
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
220
220
write ! ( f, "{}" , self . permission) ?;
221
- if !self . initialized {
221
+ if !self . accessed {
222
222
write ! ( f, "?" ) ?;
223
223
}
224
224
Ok ( ( ) )
@@ -599,12 +599,15 @@ impl Tree {
599
599
let rperms = {
600
600
let mut perms = UniValMap :: default ( ) ;
601
601
// We manually set it to `Active` on all in-bounds positions.
602
- // We also ensure that it is initialized , so that no `Active` but
603
- // not yet initialized nodes exist. Essentially, we pretend there
602
+ // We also ensure that it is accessed , so that no `Active` but
603
+ // not yet accessed nodes exist. Essentially, we pretend there
604
604
// was a write that initialized these to `Active`.
605
605
perms. insert (
606
606
root_idx,
607
- LocationState :: new_init ( Permission :: new_active ( ) , IdempotentForeignAccess :: None ) ,
607
+ LocationState :: new_accessed (
608
+ Permission :: new_active ( ) ,
609
+ IdempotentForeignAccess :: None ,
610
+ ) ,
608
611
) ;
609
612
RangeMap :: new ( size, perms)
610
613
} ;
@@ -782,14 +785,14 @@ impl<'tcx> Tree {
782
785
///
783
786
/// If `access_range_and_kind` is `None`, this is interpreted as the special
784
787
/// access that is applied on protector release:
785
- /// - the access will be applied only to initialized locations of the allocation,
788
+ /// - the access will be applied only to accessed locations of the allocation,
786
789
/// - it will not be visible to children,
787
790
/// - it will be recorded as a `FnExit` diagnostic access
788
791
/// - and it will be a read except if the location is `Active`, i.e. has been written to,
789
792
/// in which case it will be a write.
790
793
///
791
794
/// `LocationState::perform_access` will take care of raising transition
792
- /// errors and updating the `initialized ` status of each location,
795
+ /// errors and updating the `accessed ` status of each location,
793
796
/// this traversal adds to that:
794
797
/// - inserting into the map locations that do not exist yet,
795
798
/// - trimming the traversal,
@@ -882,7 +885,7 @@ impl<'tcx> Tree {
882
885
}
883
886
} else {
884
887
// This is a special access through the entire allocation.
885
- // It actually only affects `initialized ` locations, so we need
888
+ // It actually only affects `accessed ` locations, so we need
886
889
// to filter on those before initiating the traversal.
887
890
//
888
891
// In addition this implicit access should not be visible to children,
@@ -892,10 +895,10 @@ impl<'tcx> Tree {
892
895
// why this is important.
893
896
for ( perms_range, perms) in self . rperms . iter_mut_all ( ) {
894
897
let idx = self . tag_mapping . get ( & tag) . unwrap ( ) ;
895
- // Only visit initialized permissions
898
+ // Only visit accessed permissions
896
899
if let Some ( p) = perms. get ( idx)
897
900
&& let Some ( access_kind) = p. permission . protector_end_access ( )
898
- && p. initialized
901
+ && p. accessed
899
902
{
900
903
let access_cause = diagnostics:: AccessCause :: FnExit ( access_kind) ;
901
904
TreeVisitor { nodes : & mut self . nodes , tag_mapping : & self . tag_mapping , perms }
@@ -1059,7 +1062,7 @@ impl Tree {
1059
1062
1060
1063
impl Node {
1061
1064
pub fn default_location_state ( & self ) -> LocationState {
1062
- LocationState :: new_uninit (
1065
+ LocationState :: new_non_accessed (
1063
1066
self . default_initial_perm ,
1064
1067
self . default_initial_idempotent_foreign_access ,
1065
1068
)
0 commit comments