Re: [PATCH] rust: arc: remove unused PhantomData

From: Tamir Duberstein
Date: Wed Nov 06 2024 - 08:45:16 EST


On Wed, Nov 6, 2024 at 5:26 AM Alice Ryhl <aliceryhl@xxxxxxxxxx> wrote:
>
> On Tue, Nov 5, 2024 at 9:13 PM Tamir Duberstein <tamird@xxxxxxxxx> wrote:
> >
> > 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.
>
> We don't *have* to use #[may_dangle]. Using it may allow more stuff,
> but it's not a problem for it to be missing. We probably don't want to
> use it since it's unstable.
>
> Since we don't use #[may_dangle], we don't *need* the PhantomData
> field. Having it doesn't change anything.

In that case, should we reconsider this patch?