[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CANiq72kXHQSbGjavdOKgDK4FnGYCeC3B4ZfgZDU5KD_ZLKn7RQ@mail.gmail.com>
Date: Wed, 28 Sep 2022 18:36:04 +0200
From: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
To: Wei Liu <wei.liu@...nel.org>
Cc: Miguel Ojeda <ojeda@...nel.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-fsdevel@...r.kernel.org, patches@...ts.linux.dev,
Jarkko Sakkinen <jarkko@...nel.org>,
Alex Gaynor <alex.gaynor@...il.com>,
Finn Behrens <me@...enk.de>,
Adam Bratschi-Kaye <ark.email@...il.com>,
Wedson Almeida Filho <wedsonaf@...gle.com>,
Sumera Priyadarsini <sylphrenadin@...il.com>,
Gary Guo <gary@...yguo.net>, Matthew Bakhtiari <dev@...k.me>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Boqun Feng <boqun.feng@...il.com>
Subject: Re: [PATCH v10 10/27] rust: add `macros` crate
On Wed, Sep 28, 2022 at 5:29 PM Wei Liu <wei.liu@...nel.org> wrote:
>
> Just a general question: what is the house rule for adding new proc
> macros? They are powerful tools. I can see their value in `module!`
> because writing all that boilerplate by hand is just painful. Yet they
> are not straightforward to understand. It is difficult, just by looking
> at the macro, to fully grasp what the final code looks like (though the
> rsi target will help). Is there a concern that proc macro gets abused?
The rule is "use them as last resort". That is, they are not banned,
but they need to be justified: if there is an alternative that is not
too bad (e.g. in terms of ergonomics or implementation), then the
alternative should be used instead.
Nevertheless, sometimes they are very handy. Apart from `module!`
here, we are currently using them in the full repo for vtables [1] and
the Asahi M1 GPU driver is using them for versioning [2].
It is also possible to make proc macros easier to handle, for instance
if we end up deciding to allow utilities like the `syn` crate.
[1] https://github.com/Rust-for-Linux/linux/blob/fcad53ca9071c7bf6a412640a82e679bad6d1cd4/rust/macros/lib.rs#L99-L148
[2] https://github.com/AsahiLinux/linux/blob/3c8982e2c78c219bf96761445c8b73c2b3034fba/drivers/gpu/drm/asahi/fw/buffer.rs#L43-L56
Cheers,
Miguel
Powered by blists - more mailing lists