From: John Hubbard <jhubbard@nvidia.com>
To: "Eliot Courtney" <ecourtney@nvidia.com>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Joel Fernandes" <joelagnelf@nvidia.com>,
"Yury Norov" <yury.norov@gmail.com>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@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>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>
Cc: Alistair Popple <apopple@nvidia.com>,
Timur Tabi <ttabi@nvidia.com>, Zhi Wang <zhiw@nvidia.com>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
driver-core@lists.linux.dev, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 1/3] rust: extract `bitfield!` macro from `register!`
Date: Wed, 15 Apr 2026 16:18:00 -0700 [thread overview]
Message-ID: <a221aadf-a953-4fed-912a-11fbd16b65ae@nvidia.com> (raw)
In-Reply-To: <DHRO963VKBJG.1RNNN4EJ791PP@nvidia.com>
On 4/12/26 7:29 PM, Eliot Courtney wrote:
> On Thu Apr 9, 2026 at 11:58 PM JST, Alexandre Courbot wrote:
...
> In the nova version of bitfield we had @check_field_bounds. If we put
> in the bit numbers the wrong way around, this patch gives a compile
> error like:
>
> ```
> attempt to compute `4_u32 - 7_u32`, which would overflow
> ```
>
> The original nova version looks like it used build_assert, but I think
> we can do it with const assert!, so we should be able to get a better
> build error message for this case:
>
> ```
> const _: () = assert!($hi >= $lo, "bitfield: hi bit must be >= lo bit");
> ```
>
> With just that we get an extra build error, although it still spams the
> confusing build error. We could also consider adding a function like:
>
> ```
> pub const fn bitfield_width(hi: u32, lo: u32) -> u32 {
> assert!(hi >= lo, "bitfield: hi bit must be >= lo bit");
> hi + 1 - lo
> }
> ```
>
> Using this instead gets rid of some confusing build errors since we can
> also use it in type bounds. But to get rid of all of them we would need
> to do it for the mask etc and others.
>
> WDYT?
Just an admin note: if you do any or all of the above, please let's make
it a separate patch, so that this first patch remains just a "move the
code" (almost, anyway).
thanks,
--
John Hubbard
next prev parent reply other threads:[~2026-04-15 23:18 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-09 14:58 [PATCH v2 0/3] rust: add `bitfield!` macro Alexandre Courbot
2026-04-09 14:58 ` [PATCH v2 1/3] rust: extract `bitfield!` macro from `register!` Alexandre Courbot
2026-04-13 2:29 ` Eliot Courtney
2026-04-15 23:18 ` John Hubbard [this message]
2026-04-16 1:35 ` Yury Norov
2026-04-09 14:58 ` [PATCH v2 2/3] rust: bitfield: Add KUNIT tests for bitfield Alexandre Courbot
2026-04-13 2:28 ` Eliot Courtney
2026-04-16 2:44 ` Yury Norov
2026-04-16 6:59 ` Alice Ryhl
2026-04-16 12:48 ` Yury Norov
2026-04-09 14:58 ` [PATCH v2 3/3] gpu: nova-core: switch to kernel bitfield macro Alexandre Courbot
2026-04-13 2:01 ` Eliot Courtney
2026-04-15 23:20 ` John Hubbard
2026-04-15 23:22 ` [PATCH v2 0/3] rust: add `bitfield!` macro John Hubbard
2026-04-16 1:08 ` Eliot Courtney
2026-04-16 22:18 ` Danilo Krummrich
2026-04-16 22:43 ` John Hubbard
2026-04-17 1:33 ` Alexandre Courbot
2026-04-17 3:11 ` Alexandre Courbot
2026-04-17 3:19 ` John Hubbard
2026-04-17 3:57 ` Alexandre Courbot
2026-04-17 4:15 ` John Hubbard
2026-04-17 5:55 ` Miguel Ojeda
2026-04-17 10:59 ` Mark Brown
2026-04-17 12:30 ` Danilo Krummrich
2026-04-17 12:00 ` Danilo Krummrich
2026-04-17 12:21 ` Miguel Ojeda
2026-04-17 14:59 ` Danilo Krummrich
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=a221aadf-a953-4fed-912a-11fbd16b65ae@nvidia.com \
--to=jhubbard@nvidia.com \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=aliceryhl@google.com \
--cc=apopple@nvidia.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=driver-core@lists.linux.dev \
--cc=ecourtney@nvidia.com \
--cc=gary@garyguo.net \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
--cc=ttabi@nvidia.com \
--cc=yury.norov@gmail.com \
--cc=zhiw@nvidia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox