Re: [PATCH] rust: arc: remove unused PhantomData
From: Tamir Duberstein
Date: Tue Nov 05 2024 - 15:14:09 EST
On Tue, Nov 5, 2024 at 8:29 AM Miguel Ojeda
<miguel.ojeda.sandonis@xxxxxxxxx> wrote:
>
> On Mon, Nov 4, 2024 at 11:42 PM Boqun Feng <boqun.feng@xxxxxxxxx> wrote:
> >
> > I believe we need this `PhantomData` to inform drop chec [1] that the
> > drop of `Arc` may result into the drop of an `ArcInner<T>`. Rust std
> > `Arc` has the similar definition [2], you can find more information
> > about PhantomData usage on drop checking at [3].
>
> Hmm... But they use `may_dangle` in their `Drop` and we don't (and we
> have a `Drop` unlike something like `Unique`), no? Or am I confused?
> i.e. if I understand correctly, that would have been needed in the
> past, but not anymore.
Doing a bit of archaeology I found the reasoning for the presence of
`PhantomData` in std's `Arc`[0]. The TL;DR is that the presence of a
type parameter `T` implies "owns T", but `Arc` owns `ArcInner<T>`
rather than `T`. Thus in order to get correct dropck behavior it is
necessary to opt out of "owns T" using `may_dangle` and opt into "owns
ArcInner<T>" using `PhantomData`.
Please check my understanding; I couldn't find detailed documentation
of the interaction between `may_dangle` and `PhantomData`. If this
sounds correct, should we add `may_dangle` to our dropck? compile-fail
tests would be useful here.
Cheers,
Tamir
Link: https://github.com/rust-lang/rust/pull/46749#issuecomment-352146569 [0]