From: "Gary Guo" <gary@garyguo.net>
To: "Boqun Feng" <boqun.feng@gmail.com>,
<linux-kernel@vger.kernel.org>, <rust-for-linux@vger.kernel.org>,
<rcu@vger.kernel.org>
Cc: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Arve Hjønnevåg" <arve@android.com>,
"Todd Kjos" <tkjos@android.com>,
"Christian Brauner" <brauner@kernel.org>,
"Carlos Llamas" <cmllamas@google.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Miguel Ojeda" <ojeda@kernel.org>, "Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
"Frederic Weisbecker" <frederic@kernel.org>,
"Neeraj Upadhyay" <neeraj.upadhyay@kernel.org>,
"Joel Fernandes" <joelagnelf@nvidia.com>,
"Josh Triplett" <josh@joshtriplett.org>,
"Uladzislau Rezki" <urezki@gmail.com>,
"Steven Rostedt" <rostedt@goodmis.org>,
"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
"Lai Jiangshan" <jiangshanlai@gmail.com>,
Zqiang <qiang.zhang@linux.dev>,
"FUJITA Tomonori" <fujita.tomonori@gmail.com>,
"Lyude Paul" <lyude@redhat.com>,
"Thomas Gleixner" <tglx@kernel.org>,
"Anna-Maria Behnsen" <anna-maria@linutronix.de>,
"John Stultz" <jstultz@google.com>,
"Stephen Boyd" <sboyd@kernel.org>,
"Yury Norov (NVIDIA)" <yury.norov@gmail.com>,
"Vitaly Wool" <vitaly.wool@konsulko.se>,
"Tamir Duberstein" <tamird@kernel.org>,
"Viresh Kumar" <viresh.kumar@linaro.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Mitchell Levy" <levymitchell0@gmail.com>,
"David Gow" <davidgow@google.com>,
"Peter Novak" <seimun018r@gmail.com>,
"José Expósito" <jose.exposito89@gmail.com>
Subject: Re: [RFC PATCH 0/7] Introduce HasField infrastructure
Date: Wed, 04 Feb 2026 14:20:09 +0000 [thread overview]
Message-ID: <DG68S0UN78BE.QUG4A0Y08XKN@garyguo.net> (raw)
In-Reply-To: <20260128215330.58410-1-boqun.feng@gmail.com>
On Wed Jan 28, 2026 at 9:53 PM GMT, Boqun Feng wrote:
> Currently we have a few similar places where we use a `Has*` trait to
> describe that a data structure has some types of field in it so that the
> containing type can do something with it. There are also a `impl_has_*!`
> macro to help implement the trait. While it's working, but it's less
> ergonomic to me, especially considering the amount of the work we need
> to do for something new (e.g. rcu_head).
>
> Therefore here is the effort to unify them into a proc-macro based
> solution. `Field` and `HasField` traits are introduced to generify the
> "Has A" relationship, and a derive macro `#[derive(HasField)]` is also
> added to support automatically implementing `HasField` trait.
>
> This series convert a few users (Work, HrTimer) and introduce a new
> `Field` type `RcuHead`. These improvements demonstrate how this
> infrastructure can be used.
>
> Some future work is still needed: using `HasField` for `DelayedWork` and
> `ListLink` is still missing. Also it's possible to clean up `HasWork`
> trait as well.
>
> One known issue is that `#[derive(HasField)]` doesn't play alone with
> `#[pin_data]` at the moment, for example:
>
> #[derive(HasField)]
> #[pin_data]
> struct Foo { .. }
>
> works, but
>
> #[pin_data]
> #[derive(HasField)]
> struct Foo { .. }
>
> doesn't. Maybe it's by design or maybe something could be improved by
> pin-init.
>
>
> The patchset is based on today's rust/rust-next, top commit is:
>
> a7c013f77953 ('Merge patch series "refactor Rust proc macros with `syn`"')
>
> Regards,
> Boqun
Hi Boqun,
Thanks for working on this.
You currently divide things into two traits, `Field<T>` which doesn't seem to be
doing anything (actually, why does this need to exist at all?) and
`HasField<T, F>` which defines all the field projection.
For some prior art that attempts to have fields, e.g. my field-projection
experiemnt crate
https://docs.rs/field-projection
and Benno's work on field-representing-types in the Rust language, we opt to
have a type to represent each field instead.
I think we should have a unified projection infrastructure in the kernel, for
both intrusive data structure and I/O projection and others, so I think it's
useful to have types representing fields (and projection in general, this could
also extend to the `register!` macro). For clarity, let me refer to this as
`field_of!(Base, foo)` and the trait is `Projection`.
With this infra, the `HasField` trait would simply looks like this:
trait HasField<Base, FieldType> {
type Field: Projection<Base = Base, Type = FieldType>;
}
and the macro derive would generate something like
impl HasField<MyStruct, Work<MyStruct>> {
type Field = field_of!(MyStruct, name_of_work_field);
}
Best,
Gary
>
> Boqun Feng (7):
> rust: types: Introduce HasField trait and derive macro
> rust: time: hrtimer: Make `HasField` a super-trait of `HasHrTimer`
> rust: workqueue: Add HasField support for Work
> drivers: android: binder: Replace `impl_has_work!` with
> `#[derive(HasField)]`
> rust: sync: Completion: Replace `impl_has_work!` with
> `#[derive(HasField)]`
> rust: work: Remove `impl_has_work!`
> rust: sync: rcu: Introduce RcuHead
>
> drivers/android/binder/process.rs | 6 +-
> rust/kernel/field.rs | 73 ++++++++++++++++++++
> rust/kernel/lib.rs | 1 +
> rust/kernel/prelude.rs | 4 +-
> rust/kernel/sync/completion.rs | 8 +--
> rust/kernel/sync/rcu.rs | 69 ++++++++++++++++++-
> rust/kernel/time/hrtimer.rs | 70 ++++---------------
> rust/kernel/workqueue.rs | 109 +++++++++++-------------------
> rust/macros/field.rs | 85 +++++++++++++++++++++++
> rust/macros/lib.rs | 11 +++
> 10 files changed, 299 insertions(+), 137 deletions(-)
> create mode 100644 rust/kernel/field.rs
> create mode 100644 rust/macros/field.rs
next prev parent reply other threads:[~2026-02-04 14:20 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 21:53 [RFC PATCH 0/7] Introduce HasField infrastructure Boqun Feng
2026-01-28 21:53 ` [RFC PATCH 1/7] rust: types: Introduce HasField trait and derive macro Boqun Feng
2026-01-28 21:53 ` [RFC PATCH 2/7] rust: time: hrtimer: Make `HasField` a super-trait of `HasHrTimer` Boqun Feng
2026-01-28 21:53 ` [RFC PATCH 3/7] rust: workqueue: Add HasField support for Work Boqun Feng
2026-01-28 21:53 ` [RFC PATCH 4/7] drivers: android: binder: Replace `impl_has_work!` with `#[derive(HasField)]` Boqun Feng
2026-01-28 21:53 ` [RFC PATCH 5/7] rust: sync: Completion: " Boqun Feng
2026-01-28 21:53 ` [RFC PATCH 6/7] rust: work: Remove `impl_has_work!` Boqun Feng
2026-01-28 21:53 ` [RFC PATCH 7/7] rust: sync: rcu: Introduce RcuHead Boqun Feng
2026-02-04 14:20 ` Gary Guo [this message]
2026-02-05 20:47 ` [RFC PATCH 0/7] Introduce HasField infrastructure Boqun Feng
2026-02-17 1:21 ` Joel Fernandes
2026-02-27 15:00 ` Gary Guo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DG68S0UN78BE.QUG4A0Y08XKN@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=anna-maria@linutronix.de \
--cc=arve@android.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=brauner@kernel.org \
--cc=cmllamas@google.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=davidgow@google.com \
--cc=frederic@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jiangshanlai@gmail.com \
--cc=joelagnelf@nvidia.com \
--cc=jose.exposito89@gmail.com \
--cc=josh@joshtriplett.org \
--cc=jstultz@google.com \
--cc=levymitchell0@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=neeraj.upadhyay@kernel.org \
--cc=ojeda@kernel.org \
--cc=paulmck@kernel.org \
--cc=qiang.zhang@linux.dev \
--cc=rcu@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=seimun018r@gmail.com \
--cc=tamird@kernel.org \
--cc=tglx@kernel.org \
--cc=tkjos@android.com \
--cc=tmgross@umich.edu \
--cc=urezki@gmail.com \
--cc=viresh.kumar@linaro.org \
--cc=vitaly.wool@konsulko.se \
--cc=yury.norov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.