rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Benno Lossin <lossin@kernel.org>
Cc: "Alice Ryhl" <aliceryhl@google.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>, "Tejun Heo" <tj@kernel.org>,
	"Tamir Duberstein" <tamird@gmail.com>,
	"Dirk Behme" <dirk.behme@gmail.com>,
	"Alban Kurti" <kurti@invicto.ai>, "Fiona Behrens" <me@kloenk.dev>,
	rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] rust: pin-init: add pin projections to `#[pin_data]`
Date: Wed, 10 Sep 2025 20:31:34 -0700	[thread overview]
Message-ID: <aMJClvnT6O5WrcCD@tardis.local> (raw)
In-Reply-To: <DCP44KG3HEKL.35ANJWT161W6M@kernel.org>

On Wed, Sep 10, 2025 at 02:18:12PM +0200, Benno Lossin wrote:
> On Wed Sep 10, 2025 at 12:54 PM CEST, Alice Ryhl wrote:
> > On Wed, Sep 10, 2025 at 12:38 PM Benno Lossin <lossin@kernel.org> wrote:
> >>
> >> On Wed Sep 10, 2025 at 12:23 PM CEST, Alice Ryhl wrote:
> >> > On Fri, Sep 5, 2025 at 7:12 PM Benno Lossin <lossin@kernel.org> wrote:
> >> >> +    (make_pin_projections:
> >> >> +        @vis($vis:vis),
> >> >> +        @name($name:ident),
> >> >> +        @impl_generics($($impl_generics:tt)*),
> >> >> +        @ty_generics($($ty_generics:tt)*),
> >> >> +        @decl_generics($($decl_generics:tt)*),
> >> >> +        @where($($whr:tt)*),
> >> >> +        @pinned($($(#[$($p_attr:tt)*])* $pvis:vis $p_field:ident : $p_type:ty),* $(,)?),
> >> >> +        @not_pinned($($(#[$($attr:tt)*])* $fvis:vis $field:ident : $type:ty),* $(,)?),
> >> >> +    ) => {
> >> >> +        $crate::macros::paste! {
> >> >> +            #[doc(hidden)]
> >> >> +            $vis struct [< $name Projection >] <'__pin, $($decl_generics)*> {
> >> >
> >> > I'm not sure we want $vis here. That's the visibility of the original
> >> > struct, but I don't think we want it to be pub just because the struct
> >> > is.
> >>
> >> Why shouldn't it be pub if the original is pub? I don't really
> >> understand the concern, since the fields themselves will still have the
> >> correct visibility. Additionally, there is the `___pin_phantom_data`
> >> field that's always private, so you cannot construct this outside of the
> >> module.
> >
> > I mean, for instance, it's going to mean that every single struct that
> > wraps Opaque in a private field will get a useless pub function called
> > project that will appear in html docs.
> 
> It's `#[doc(hidden)]` :)
> 
> > Pin-project limits the visibility to pub(crate) when the struct is pub.
> 
> I think I would have to look inside the `vis` to recreate that behavior,
> so I'd rather do it as a future patch. Thoughts?
> 

This reminds me: I think should make these functions `#[inline]` for
now? (Until we make a decision about whether it's pub(crate) or $vis)

Otherwise compiler will generate functions in kernel binaries for some
of them. E.g.

nm .kunit/vmlinux.o  | rustfilt | grep project
00000000002449cc T <kernel::sync::LockClassKey>::project
000000000023ef40 T <kernel::sync::completion::Completion>::project
000000000023ef40 T <kernel::sync::poll::PollCondVar>::project
0000000000244994 T <kernel::sync::condvar::CondVar>::project
0000000000260a68 T <doctests_kernel_generated::rust_doctest_kernel_init_rs_3::main::_doctest_main____rust_kernel_init_rs_69_0::RawFoo>::project
0000000000008b70 d __UNIQUE_ID___addressable__RNvMs0_NtCshc5sK6KjdJJ_6kernel4syncNtB5_12LockClassKey7project2007
0000000000008c98 d __UNIQUE_ID___addressable__RNvMs1_NtNtCshc5sK6KjdJJ_6kernel4sync10completionNtB5_10Completion7project2044
0000000000008ca0 d __UNIQUE_ID___addressable__RNvMs1_NtNtCshc5sK6KjdJJ_6kernel4sync4pollNtB5_11PollCondVar7project2045
0000000000008b60 d __UNIQUE_ID___addressable__RNvMs1_NtNtCshc5sK6KjdJJ_6kernel4sync7condvarNtB5_7CondVar7project2005
0000000000010d28 r __export_symbol_<kernel::sync::LockClassKey>::project
0000000000010f78 r __export_symbol_<kernel::sync::completion::Completion>::project
0000000000010f88 r __export_symbol_<kernel::sync::poll::PollCondVar>::project
0000000000010d08 r __export_symbol_<kernel::sync::condvar::CondVar>::project

Otherwise the patch looks good to me. Feel free to add:

Reviewed-by: Boqun Feng <boqun.feng@gmail.com>

Regards,
Boqun

> ---
> Cheers,
> Benno

  parent reply	other threads:[~2025-09-11  3:31 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-05 17:12 [PATCH 1/2] rust: pin-init: rename `project` -> `project_this` in doctest Benno Lossin
2025-09-05 17:12 ` [PATCH 2/2] rust: pin-init: add pin projections to `#[pin_data]` Benno Lossin
2025-09-10 10:23   ` Alice Ryhl
2025-09-10 10:24     ` Alice Ryhl
2025-09-10 10:38       ` Benno Lossin
2025-09-10 10:38     ` Benno Lossin
2025-09-10 10:54       ` Alice Ryhl
2025-09-10 12:18         ` Benno Lossin
2025-09-10 12:28           ` Alice Ryhl
2025-09-10 12:52             ` Benno Lossin
2025-09-11  3:31           ` Boqun Feng [this message]
2025-09-10 22:20   ` Gary Guo
2025-09-11 21:32 ` [PATCH 1/2] rust: pin-init: rename `project` -> `project_this` in doctest Benno Lossin

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=aMJClvnT6O5WrcCD@tardis.local \
    --to=boqun.feng@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=dakr@kernel.org \
    --cc=dirk.behme@gmail.com \
    --cc=gary@garyguo.net \
    --cc=kurti@invicto.ai \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=me@kloenk.dev \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tamird@gmail.com \
    --cc=tj@kernel.org \
    --cc=tmgross@umich.edu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).