Skip to content

Commit a5a4629

Browse files
committed
Stacked Borrows: update for shallow retagging
1 parent f3781c2 commit a5a4629

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

wip/stacked-borrows.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ For more background, see the following blog-posts:
1313
* [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.
1414
* [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.
1515

16+
Changes compared to the latest post (2.1):
17+
18+
* Retags are "shallow" instead of recursively looking for references inside compound types.
19+
1620
[Miri]: https://github.com/solson/miri/
1721
[all-hands]: https://paper.dropbox.com/doc/Topic-Stacked-borrows--AXAkoFfUGViWL_PaSryqKK~hAg-2q57v4UM7cIkxCq9PQc22
1822

@@ -109,7 +113,7 @@ pub enum RetagKind {
109113

110114
`Retag` is inserted into the MIR for the following situations:
111115

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.
113117
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.
114118

115119
Currently, if the LHS of the assignment involves a `Deref`, no `Retag` is inserted.
@@ -311,14 +315,16 @@ location.stack.grant(
311315

312316
### Retagging
313317

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:
316320

317321
1. We compute a fresh tag: `Untagged` for raw pointers, `Tag(Tracking::new_ptr_id())` for everything else.
318322
2. We determine if we will want to protect the items we are going to generate:
319323
This is the case only if `kind == FnEntry` and the type of this pointer is a reference (not a box).
320324
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 }`.
321325

326+
We do not recurse into fields of structs or other compound types, only "bare" references/... get retagged.
327+
322328
### Deallocating memory
323329

324330
Memory deallocation first acts like a write access through the pointer used for deallocation.

0 commit comments

Comments
 (0)