@@ -35,23 +35,23 @@ This design document is about the restrictions on what `T: ?Sized + DynSized` ac
35
35
36
36
` Arc ` supports "zombie" references, where all strong ` Arc ` and the pointee have been dropped,
37
37
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 ` .
39
40
40
41
In addition, ` Weak ` are pointers to the * reference count* part of the ` ArcInner ` allocation,
41
42
and thus need to * statically* know the alignment of the pointee type to determine the offset
42
43
(it cannot call ` align_of_val_raw ` without first knowing the offset).
43
44
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:
51
46
52
47
- Store layout information in the ` ArcInner ` header, or
53
48
- Require that layout be determined solely from pointee metadata, or
54
49
- 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 ` .
55
55
56
56
T-lang commented on this in \[ 3] (w.r.t. const ` Weak<T>::[into|from]_raw ` and ` Weak::new ` ):
57
57
0 commit comments