Re: [PATCH] gpu: nova-core: bitfield: use &mut self setters instead of builder pattern
From: Timur Tabi
Date: Wed Dec 31 2025 - 17:33:44 EST
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?
> 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.