From: "Alexandre Courbot" <acourbot@nvidia.com>
To: "Joel Fernandes" <joelagnelf@nvidia.com>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Yury Norov" <yury.norov@gmail.com>,
"Danilo Krummrich" <dakr@kernel.org>,
"Miguel Ojeda" <ojeda@kernel.org>
Cc: <rust-for-linux@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH 0/2] rust: bounded integer types and use in register macro
Date: Thu, 02 Oct 2025 12:03:15 +0900 [thread overview]
Message-ID: <DD7I3NGT6DHI.114KADERSQ8VG@nvidia.com> (raw)
In-Reply-To: <6d4b5659-7c0e-4720-8305-5b0053807443@nvidia.com>
On Thu Oct 2, 2025 at 7:07 AM JST, Joel Fernandes wrote:
> Hi Alex,
>
> Nice!
>
> On 10/1/2025 11:03 AM, Alexandre Courbot wrote:
>> For convenience, this PoC is based on drm-rust-next. If we decide to
>> proceed with it, we would do it after the patchset extracting and moving
>> the bitfield logic [3] lands, as the two would conflict heavily.
>
> I would strongly prefer this as well, to avoid conflicts. On initial look, this
> seems to be in the right direction and solves the pain points we were seeing.
>
> - .set_sec(if sec { 1 } else { 0 });
> + .set_sec_bounded(BoundedInt::new(if sec { 1 } else { 0 }));
>
> Here, I would prefer if we did not add _bounded, since the idea is to solve the
> problems in the macro's setters itself (make it infallible, not panicking etc).
> So we can just modify those?
Oh absolutely, the and goal is to replace the existing accessors. For
this RFC I went the lazy way and added new ones, otherwise I would have
had to update more call sites in nova-core.
>
> Also, BoundedInt sounds like a good name to me IMO.
>
> Also, since TryFrom trait is implemented in the first patch, then in nova we can
> just do the following?
> .set_foo(value.try_into()?);
Yes! That does work indeed and is more concise. And we can also make
things less verbose on the caller side by adding a new generic setter in
the form of:
fn try_set_field<T: TryInto<BoundedInt<..>>(self, value:T) -> Result
This setter could try to perform the conversion itself and return an
error as needed, and the caller would just need to call e.g.
.try_set_foo(value)?;
instead of building the BoundedInt themselves.
There are also many other improvements that can be done, like having
fields with a round number of bits be represented by the relevant
primitive directly instead of a BoundedInt, but that will requires some
more macro magic.
next prev parent reply other threads:[~2025-10-02 3:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-01 15:03 [RFC PATCH 0/2] rust: bounded integer types and use in register macro Alexandre Courbot
2025-10-01 15:03 ` [PATCH RFC 1/2] rust: kernel: add bounded integer types Alexandre Courbot
2025-10-01 15:03 ` [PATCH RFC 2/2] gpu: nova-core: demonstrate use of BoundedInt Alexandre Courbot
2025-10-01 22:07 ` [RFC PATCH 0/2] rust: bounded integer types and use in register macro Joel Fernandes
2025-10-02 3:03 ` Alexandre Courbot [this message]
2025-10-02 13:32 ` Joel Fernandes
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=DD7I3NGT6DHI.114KADERSQ8VG@nvidia.com \
--to=acourbot@nvidia.com \
--cc=dakr@kernel.org \
--cc=joelagnelf@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox