mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joel Fernandes <joelagnelf@nvidia.com>
To: John Hubbard <jhubbard@nvidia.com>
Cc: Timur Tabi <ttabi@nvidia.com>,
	"dakr@kernel.org" <dakr@kernel.org>,
	Alexandre Courbot <acourbot@nvidia.com>,
	"lossin@kernel.org" <lossin@kernel.org>,
	"a.hindborg@kernel.org" <a.hindborg@kernel.org>,
	"boqun.feng@gmail.com" <boqun.feng@gmail.com>,
	"aliceryhl@google.com" <aliceryhl@google.com>,
	Zhi Wang <zhiw@nvidia.com>, "simona@ffwll.ch" <simona@ffwll.ch>,
	"alex.gaynor@gmail.com" <alex.gaynor@gmail.com>,
	"ojeda@kernel.org" <ojeda@kernel.org>,
	"tmgross@umich.edu" <tmgross@umich.edu>,
	"nouveau@lists.freedesktop.org" <nouveau@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"rust-for-linux@vger.kernel.org" <rust-for-linux@vger.kernel.org>,
	"bjorn3_gh@protonmail.com" <bjorn3_gh@protonmail.com>,
	Edwin Peer <epeer@nvidia.com>,
	"airlied@gmail.com" <airlied@gmail.com>,
	"bhelgaas@google.com" <bhelgaas@google.com>,
	"gary@garyguo.net" <gary@garyguo.net>,
	Alistair Popple <apopple@nvidia.com>
Subject: Re: [PATCH] gpu: nova-core: bitfield: use &mut self setters instead of builder pattern
Date: Thu, 1 Jan 2026 00:15:52 +0000	[thread overview]
Message-ID: <CE6A313F-9DF3-4944-A5AE-F26464D89C17@nvidia.com> (raw)
In-Reply-To: <ec3e5da4-f944-4526-a339-3da8286c36d2@nvidia.com>



> On Dec 31, 2025, at 5:47 PM, John Hubbard <jhubbard@nvidia.com> wrote:
> 
> On 12/31/25 2:33 PM, Timur Tabi wrote:
>>> On Wed, 2025-12-31 at 13:47 -0800, John Hubbard wrote:
>>> The builder-pattern setters (self -> Self) enabled method chaining like:
>>> 
>>>     reg.set_foo(x).set_sec(y).write(bar);
>>> 
>>> This made separate operations appear as a single expression, obscuring
>>> that each setter is a distinct mutation. 
>> 
>> So you're concerned about the fact that the compiler is not merging the set_foo(x) and the
>> set_sec(y) into a single read-modify-write?
> 
> No, I don't care about that aspect.
> 
>> 
>>> These setters are infallible,
>>> so the chaining provides no error-propagation benefit—it just obscures
>>> what are simple, independent assignments.
>>> 
>>> Change the bitfield!() macro to generate `&mut self` setters, so each
>>> operation is a distinct statement:
>>> 
>>>     reg.set_foo(x);
>>>     reg.set_sec(y);
>>>     reg.write(bar);
>> 
>> Are you sure about this?  It just seems like you're throwing out a neat little feature of Rust and
>> replacing it with something that's very C-like.  This breaks compatible with all users of the regs
>> macros.  Seems really disruptive for what seems to me like a cosmetic change.
>> 
> 
> It's only a neat feature if it *does* something. In this case, it *looks*
> like a neat Rust feature, but under the covers it really is just handing
> around copies unnecessarily, when really, it *is* doing the C-like thing
> in the end.
> 
> I object to the fake Rust-ness that's being done here. It's like putting
> hubcabs on a car.

But IMO there is only one operation here, the IO write. The setter is just mutations. Builder pattern chaining is idiomatic to Rust.

I would not call it fake Rustness since it is Rustness in the Rust language. Afair, similar arguments were made before and conclusion was, well, this is Rust.

Regarding the copies, I am intrigued - have you verified that the code generation actually results in copies? I would be surprised if the compiler did not optimize.

 - Joel





> 
> thanks,
> --
> John Hubbard
> 

  reply	other threads:[~2026-01-01  0:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-31 21:47 John Hubbard
2025-12-31 22:33 ` Timur Tabi
2025-12-31 22:47   ` John Hubbard
2026-01-01  0:15     ` Joel Fernandes [this message]
2026-01-01  0:46       ` John Hubbard
2026-01-01  2:42         ` Joel Fernandes
2026-01-01  2:52           ` John Hubbard
2026-01-01  4:05             ` Joel Fernandes
2026-01-01  4:28               ` Gary Guo
2026-01-01 10:01                 ` Joel Fernandes
2026-01-01  8:42 ` kernel test robot

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=CE6A313F-9DF3-4944-A5AE-F26464D89C17@nvidia.com \
    --to=joelagnelf@nvidia.com \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=airlied@gmail.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=apopple@nvidia.com \
    --cc=bhelgaas@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=dakr@kernel.org \
    --cc=epeer@nvidia.com \
    --cc=gary@garyguo.net \
    --cc=jhubbard@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=nouveau@lists.freedesktop.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=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

all inboxes | Powered by JetHome®