[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <87il963ysz.fsf@metaspace.dk>
Date: Wed, 23 Aug 2023 11:06:37 +0200
From: "Andreas Hindborg (Samsung)" <nmi@...aspace.dk>
To: Benno Lossin <benno.lossin@...ton.me>
Cc: Alice Ryhl <aliceryhl@...gle.com>, rust-for-linux@...r.kernel.org,
Tejun Heo <tj@...nel.org>, Miguel Ojeda <ojeda@...nel.org>,
Lai Jiangshan <jiangshanlai@...il.com>,
Wedson Almeida Filho <wedsonaf@...il.com>,
Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
linux-kernel@...r.kernel.org, patches@...ts.linux.dev
Subject: Re: [PATCH v3 6/9] rust: workqueue: add helper for defining
work_struct fields
"Andreas Hindborg (Samsung)" <nmi@...aspace.dk> writes:
> Hi Benno,
>
> Benno Lossin <benno.lossin@...ton.me> writes:
>
> ...
>
>>> +/// Links for a work item.
>>> +///
>>> +/// This struct contains a function pointer to the `run` function from the [`WorkItemPointer`]
>>> +/// trait, and defines the linked list pointers necessary to enqueue a work item in a workqueue.
>>> +///
>>> +/// Wraps the kernel's C `struct work_struct`.
>>> +///
>>> +/// This is a helper type used to associate a `work_struct` with the [`WorkItem`] that uses it.
>>> +#[repr(transparent)]
>>> +pub struct Work<T: ?Sized, const ID: u64 = 0> {
>>> + work: Opaque<bindings::work_struct>,
>>> + _inner: PhantomData<T>,
>>
>> Should this really be `PhantomData<T>`? Are you dropping `T`s in the
>> destructor of `Work<T>`? I do not think so `PhantomData<fn() -> Box<T>>`
>> should do the trick.
>>
>
> Could you elaborate what is the issue in having `PhantomData<T>`?
I played around with this and as far as I can tell, using
`PhantomData<fn() -> Box<T>>` does not disable dropck for T. Thus,
`PhantomData<T>` has the same effect as `PhantomData<fn() -> Box<T>`,
which is covariance over T and dropck:
```rust
use std::marker::PhantomData;
struct A<T> {
_marker: PhantomData<fn() -> Box<T>>,
}
//#[cfg(disable)]
impl<T> Drop for A<T> {
fn drop(&mut self) {
todo!()
}
}
struct B {}
fn main() {
let (_a, b);
b = B {};
_a = foo(&b);
}
fn foo<'a>(_b: &'a B) -> A<&'a B> {
let a: A<&'a B> = A {
_marker: PhantomData,
};
a
}
```
This is a little surprising to me since nomicon [1] explicitly marks
`PhantomData<T>` as "covariant (with drop check)" but only "covariant"
for `PhantomData<fn() -> T>`.
Not sure why you wanted the box?
Best regards,
Andreas
[1] https://doc.rust-lang.org/nomicon/phantom-data.html#table-of-phantomdata-patterns
Powered by blists - more mailing lists