From: Gary Guo <gary@garyguo.net>
To: Boqun Feng <boqun.feng@gmail.com>
Cc: "Benno Lossin" <benno.lossin@proton.me>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Wedson Almeida Filho" <wedsonaf@gmail.com>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Alice Ryhl" <aliceryhl@google.com>,
"Andreas Hindborg" <nmi@metaspace.dk>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
patches@lists.linux.dev, "Asahi Lina" <lina@asahilina.net>
Subject: Re: [PATCH 5/7] rust: init: add `..Zeroable::zeroed()` syntax for zeroing all missing fields
Date: Wed, 5 Jul 2023 18:48:36 +0100 [thread overview]
Message-ID: <20230705184836.363c8c8b.gary@garyguo.net> (raw)
In-Reply-To: <ZKMQW4UGPQZ8yF39@boqun-archlinux>
On Mon, 3 Jul 2023 11:15:55 -0700
Boqun Feng <boqun.feng@gmail.com> wrote:
> On Sat, Jun 24, 2023 at 09:25:19AM +0000, Benno Lossin wrote:
> [...]
> (this is `init_slot`)
> > @@ -1064,7 +1152,7 @@ macro_rules! __init_internal {
> > @data($data:ident),
> > @slot($slot:ident),
> > @guards($($guards:ident,)*),
> > - @munch_fields($(,)?),
> > + @munch_fields($(..Zeroable::zeroed())? $(,)?),
>
> since you append an unconditional comma ',' to init_slot and
> make_initializer when "calling" them in with_update_parsed, shouldn't
> this be:
>
> + @munch_fields($(..Zeroable::zeroed(),)? $(,)?),
>
> , and..
>
> > ) => {
> > // Endpoint of munching, no fields are left. If execution reaches this point, all fields
> > // have been initialized. Therefore we can now dismiss the guards by forgetting them.
> > @@ -1157,6 +1245,30 @@ macro_rules! __init_internal {
> > @munch_fields($($rest)*),
> > );
> > };
> > + (make_initializer:
> > + @slot($slot:ident),
> > + @type_name($t:ident),
> > + @munch_fields(..Zeroable::zeroed() $(,)?),
>
> this should be:
>
> + @munch_fields(..Zeroable::zeroed() , $(,)?),
>
> Otherwise the example before `pin_init!()` wouldn't compile:
>
> /// pin_init!(Buf {
> /// buf: [1; 64],
> /// ..Zeroable::zeroed(),
> /// });
Comma is not allowed after base struct.
>
> Regards,
> Boqun
>
> > + @acc($($acc:tt)*),
> > + ) => {
> > + // Endpoint, nothing more to munch, create the initializer. Since the users specified
> > + // `..Zeroable::zeroed()`, the slot will already have been zeroed and all field that have
> > + // not been overwritten are thus zero and initialized. We still check that all fields are
> > + // actually accessible by using the struct update syntax ourselves.
> > + // Since we are in the `if false` branch, this will never get executed. We abuse `slot` to
> > + // get the correct type inference here:
> > + unsafe {
> > + let mut zeroed = ::core::mem::zeroed();
> > + // We have to use type inference her to make zeroed have the correct type. This does
> > + // not get executed, so it has no effect.
> > + ::core::ptr::write($slot, zeroed);
> > + zeroed = ::core::mem::zeroed();
> > + ::core::ptr::write($slot, $t {
> > + $($acc)*
> > + ..zeroed
> > + });
> > + }
> > + };
> > (make_initializer:
> > @slot($slot:ident),
> > @type_name($t:ident),
> > --
> > 2.41.0
> >
> >
next prev parent reply other threads:[~2023-07-05 17:48 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-24 9:24 [PATCH 1/7] rust: init: consolidate init macros Benno Lossin
2023-06-24 9:25 ` [PATCH 2/7] rust: add derive macro for `Zeroable` Benno Lossin
2023-06-24 14:55 ` Björn Roy Baron
2023-06-25 20:46 ` Gary Guo
2023-07-03 11:50 ` Alice Ryhl
2023-06-24 9:25 ` [PATCH 3/7] rust: init: make guards in the init macros hygienic Benno Lossin
2023-06-24 14:58 ` Björn Roy Baron
2023-06-25 20:54 ` Gary Guo
2023-06-28 11:41 ` Benno Lossin
2023-06-28 16:48 ` Gary Guo
2023-06-24 9:25 ` [PATCH 4/7] rust: init: wrap type checking struct initializers in a closure Benno Lossin
2023-06-24 15:03 ` Björn Roy Baron
2023-06-24 21:05 ` Benno Lossin
2023-06-24 9:25 ` [PATCH 5/7] rust: init: add `..Zeroable::zeroed()` syntax for zeroing all missing fields Benno Lossin
2023-06-24 15:11 ` Björn Roy Baron
2023-06-24 21:14 ` Benno Lossin
2023-06-25 12:56 ` Björn Roy Baron
2023-06-25 13:07 ` Benno Lossin
2023-06-25 14:17 ` Björn Roy Baron
2023-06-25 16:46 ` Benno Lossin
2023-07-03 11:58 ` Alice Ryhl
2023-07-03 18:15 ` Boqun Feng
2023-07-05 17:48 ` Gary Guo [this message]
2023-07-05 21:44 ` Benno Lossin
2023-06-24 9:25 ` [PATCH 6/7] rust: init: Add functions to create array initializers Benno Lossin
2023-06-24 15:17 ` Björn Roy Baron
2023-07-03 12:03 ` Alice Ryhl
2023-06-24 9:25 ` [PATCH 7/7] rust: init: add support for arbitrary paths in init macros Benno Lossin
2023-06-24 15:20 ` Björn Roy Baron
2023-06-25 21:01 ` Gary Guo
2023-06-28 11:26 ` Benno Lossin
2023-06-28 17:13 ` Gary Guo
2023-06-24 14:49 ` [PATCH 1/7] rust: init: consolidate " Björn Roy Baron
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=20230705184836.363c8c8b.gary@garyguo.net \
--to=gary@garyguo.net \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=benno.lossin@proton.me \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=lina@asahilina.net \
--cc=linux-kernel@vger.kernel.org \
--cc=nmi@metaspace.dk \
--cc=ojeda@kernel.org \
--cc=patches@lists.linux.dev \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@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.