Skip to content

Commit 6b88e48

Browse files
committed
Add details on truncation and ref-uniq
1 parent a7b598f commit 6b88e48

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/types/closure.md

+17-10
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,12 @@ If a closure captures a field of a composite types such as structs, tuples, and
337337
* Helper functions:
338338
* `unsafe_check(Place, Mode) -> (Place, Mode)`
339339
* "Ensure unsafe accesses occur within the closure"
340-
* If Place contains a deref of a raw pointer:
341-
* Let Place1 = Place truncated just before the deref
342-
* Return (Place1, Mode)
343-
* If Mode is `ref *` and the place contains a field of a packed struct:
344-
* Let Place1 = Place truncated just before the field
345-
* Return (Place1, Mode)
340+
* If Place contains a deref (at index `i`) of a raw pointer:
341+
* Let `(Place1, Mode1) = truncate_place(Place, Mode, i)`
342+
* Return (Place1, Mode1)
343+
* If Mode is `ref *` and the place contains a field of a packed struct at index `i`:
344+
* Let `(Place1, Mode1) = truncate_place(Place, Mode, i)`
345+
* Return (Place1, Mode1)
346346
* Else
347347
* Return (Place, Mode)
348348
* `move_xform(Place, Mode) -> (Place, Mode)` (For move closures)
@@ -353,16 +353,16 @@ If a closure captures a field of a composite types such as structs, tuples, and
353353
* Return (Place, Mode)
354354
* Else if Mode is `ref *` and the place contains a deref of an `&`:
355355
* Return (Place, Mode)
356-
* Else if place contains a deref:
357-
* Let Place1 = Place truncated just before the deref
356+
* Else if place contains a deref at index `i`:
357+
* Let `(Place1, _) = truncate_place(Place, Mode, i)`
358358
* Return (Place1, ByValue)
359359
* Else:
360360
* Return (Place, ByValue)
361361
* `ref_xform(Place, Mode) -> (Place, Mode)` (for ref closures)
362362
* "If taking ownership of data, only move data from enclosing stack frame."
363363
* Generate C' by mapping each (Mode, Place) in C
364-
* If Mode is ByValue and place contains a deref:
365-
* Let Place1 = Place truncated just before the deref
364+
* If Mode is ByValue and place contains a deref at index `i`:
365+
* Let `(Place1, _) = truncate_place(Place, Mode, i)`
366366
* Return (Place1, ByValue)
367367
* Else:
368368
* Return (Place, Mode)
@@ -378,6 +378,13 @@ If a closure captures a field of a composite types such as structs, tuples, and
378378
and `Place.type_before_projection(l) = ty::Ref(.., Mutability::Not)`
379379
* Let Place1 = (Base, Projections[0..=l])
380380
* Return (Place1, Ref)
381+
* `truncate_place(Place, Mode, len) -> (Place, Mode)`
382+
* "Truncate the place to length `len`, i.e. upto but not including index `len`"
383+
* "If during truncation we drop Deref of a `&mut` and the place was being used by `ref mut`, the access to the truncated place must be unique"
384+
* Let (Proj_before, Proj_after) = Place.split_before(len)
385+
* If Mode == `ref mut` and there exists `Deref` in `Proj_after` at index `i` such that `Place.type_before_projection(len + i)` is `&mut T`
386+
* Return (Place(Proj_before, ..InputPlace), `ref-uniq`)
387+
* Else Return (Place(Proj_before, ..InputPlace), Mode)
381388

382389
## Key examples
383390

0 commit comments

Comments
 (0)