You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: wip/stacked-borrows.md
+9-3
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,10 @@ For more background, see the following blog-posts:
13
13
*[Stacked Borrows 2.0](https://www.ralfj.de/blog/2019/04/30/stacked-borrows-2.html) is a re-design of Stacked Borrows 1 that maintains the original core ideas, but changes the mechanism to support more precise tracking of shared references.
14
14
*[Stacked Borrows 2.1](https://www.ralfj.de/blog/2019/05/21/stacked-borrows-2.1.html) slightly tweaks the rules for read and write accesses and describes a high-level way of thinking about the new shape of the "stack" in Stacked Borrows 2.
15
15
16
+
Changes compared to the latest post (2.1):
17
+
18
+
* Retags are "shallow" instead of recursively looking for references inside compound types.
`Retag` is inserted into the MIR for the following situations:
111
115
112
-
* A retag happens after every assignment MIR statement where the assigned type may contain a reference type (checking recursively below compound types but not below references).
116
+
* A retag happens after every assignment MIR statement where the assigned type may by of reference or box type.
113
117
This is usually a `Default` retag. However, if the RHS of this assignment is a `Ref` which allows two-phase borrows, then this is a `TwoPhase` retag.
114
118
115
119
Currently, if the LHS of the assignment involves a `Deref`, no `Retag` is inserted.
@@ -311,14 +315,16 @@ location.stack.grant(
311
315
312
316
### Retagging
313
317
314
-
When executing `Retag(kind, place)`, we recursively visit all fields of this place, descending into compound types (`struct`, `enum`, arrays and so on) but not below any pointers.
315
-
For each reference (`&[mut] _`) and box (`Box<_>`) we encounter, and if `kind == Raw` also for each raw pointer (`*[const,mut] _`), we perform the following steps:
318
+
When executing `Retag(kind, place)`, we check if `place` holds a reference (`&[mut] _`) or box (`Box<_>`), and if `kind == Raw` we also check each raws pointer (`*[const,mut] _`).
319
+
For those we perform the following steps:
316
320
317
321
1. We compute a fresh tag: `Untagged` for raw pointers, `Tag(Tracking::new_ptr_id())` for everything else.
318
322
2. We determine if we will want to protect the items we are going to generate:
319
323
This is the case only if `kind == FnEntry` and the type of this pointer is a reference (not a box).
320
324
3. We perform reborrowing of the memory this pointer points to with the new tag and indicating whether we want protection, treating boxes as `RefKind::Unique { two_phase: false }`.
321
325
326
+
We do not recurse into fields of structs or other compound types, only "bare" references/... get retagged.
327
+
322
328
### Deallocating memory
323
329
324
330
Memory deallocation first acts like a write access through the pointer used for deallocation.
0 commit comments