Skip to content

Commit f24c4f2

Browse files
authored
Update dynsized_constraints.md
1 parent 17311ed commit f24c4f2

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/design_notes/dynsized_constraints.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@ This design document is about the restrictions on what `T: ?Sized + DynSized` ac
3535

3636
`Arc` supports "zombie" references, where all strong `Arc` and the pointee have been dropped,
3737
but `Weak` handles still exist and so the allocation still exists.
38-
This means that `Weak` needs to be able to determine the layout of the allocation from a dropped pointee.
38+
This means that `Weak` needs to be able to determine the layout of the allocation from a dropped pointee,
39+
as the `T` is dropped with the last `Arc` but the allocation freed with the last `Weak`.
3940

4041
In addition, `Weak` are pointers to the *reference count* part of the `ArcInner` allocation,
4142
and thus need to *statically* know the alignment of the pointee type to determine the offset
4243
(it cannot call `align_of_val_raw` without first knowing the offset).
4344

44-
For the alignment, there are three potential resolutions:
45-
46-
- Store layout information in the `ArcInner` header,
47-
- Require that alignment be determined solely from pointee metadata, or
48-
- Change the pointer of `Arc<T>` to point directly at `T` and use a fixed negative offset for the header.
49-
50-
For the both, there are three potential resolutions:
45+
There are three potential resolutions that cover both size and alignment:
5146

5247
- Store layout information in the `ArcInner` header, or
5348
- Require that layout be determined solely from pointee metadata, or
5449
- Require that layout be determinable from a dropped pointee.
50+
[^This is trivially the case if determining the layout does not read the pointee (i.e. is derivable by just the potentially wide pointer);
51+
alternatively, the pointee could ensure that layout information (e.g. vtable pointer) remains valid to read even after it's been dropped.]
52+
53+
Dealing with alignment can be simplified by changing `Arc<T>` from storing `*mut ArcInner<T>` to
54+
storing `*mut T` and storing the refcount metadata at a fixed negative offset independent of `T`.
5555

5656
T-lang commented on this in \[3] (w.r.t. const `Weak<T>::[into|from]_raw` and `Weak::new`):
5757

0 commit comments

Comments
 (0)