On Tue, 26 May 2026, Nicolas Frattaroli <[email protected]> wrote: > On Tuesday, 26 May 2026 12:52:31 Central European Summer Time Jani Nikula > wrote: >> On Tue, 26 May 2026, Nicolas Frattaroli <[email protected]> >> wrote: >> > +static __pure const char *drm_scdc_frl_rate_str(enum drm_scdc_frl_rate >> > rate) >> >> There are a total of only 71 __pure usages in the kernel. Is this >> helpful for a static function where the compiler can figure it out by >> itself? > > For the compiler, no. For the programmer, maybe. It's basically > documentation that foo(x) remains the same for a specific x, so > that having 3 calls with the same parameter in some scope is not > actually 3 separate function calls, but just retrieving a value > without manually saving it into a stack variable. A compiler can > infer that in this case, but a programmer that has their LSP show > them the function signature on hover will immediately know what's > going on without having to look at the implementation. > > I have a habit of slapping it onto any function that is pure just > because, but if you'd rather have me drop it then I can do that. > I'm aware that slapping attributes onto function signatures can > make them a bit noisy to read.
I'm not dead set on this. But my observation, in general, is that setting an example is something to be done with care. People try to do the right thing, and cargo cult. And then you find out it's all over the place. So IMO the question is not so much, "is it a good thing here", but rather, "is this what we want for all pure functions". BR, Jani. -- Jani Nikula, Intel
