rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Alice Ryhl <aliceryhl@google.com>,
	a.hindborg@samsung.com, alex.gaynor@gmail.com,  ardb@kernel.org,
	benno.lossin@proton.me, bjorn3_gh@protonmail.com,
	 boqun.feng@gmail.com, gary@garyguo.net, jbaron@akamai.com,
	 jpoimboe@kernel.org, linux-kernel@vger.kernel.org,
	 linux-trace-kernel@vger.kernel.org,
	mathieu.desnoyers@efficios.com,  mhiramat@kernel.org,
	ojeda@kernel.org, rostedt@goodmis.org,
	 rust-for-linux@vger.kernel.org, wedsonaf@gmail.com
Subject: Re: [PATCH 1/3] rust: add static_call support
Date: Fri, 7 Jun 2024 13:46:16 +0200	[thread overview]
Message-ID: <CANiq72=4y84CrmkP-QsrW7YYNbpNJRim3oFK=kfEE8oin38pMQ@mail.gmail.com> (raw)
In-Reply-To: <20240607105232.GP8774@noisy.programming.kicks-ass.net>

On Fri, Jun 7, 2024 at 12:52 PM Peter Zijlstra <peterz@infradead.org> wrote:
>
> I'm sorry, but 30+ years of reading ! as NOT (or factorial) isn't going
> to go away. So I'm reading your macros do NOT rule.

It makes it clear what is macro call or not. They could have gone for
UPPERCASE names (for instance), yes. On the other hand, they do not
work like C macros and are ~hygienic, so it also makes sense to avoid
confusion here.

I mean, I am not suggesting to do a CPP-pass to Rust files, but if
someone really, really wanted to mix them in a single file, it would
be nice to not confuse the two kinds. :)

Generally they feel "closer" to the language (given what they
do/support) compared to the CPP ones, so it also makes sense they
don't "shout" so much compared to UPPERCASE, if that makes sense.

> The above exaple fails, because the next token is :ident, whatever the
> heck that might be. Also, extra points for line-noise due to lack of
> whitespace.

$name:ident means "match what Rust would consider an identifier here
and call it $name for the purposes of this macro".

So, for instance, $x:ident matches:

    a
    a2
    a_b

But it would not match:

    2a
    a-b
    a _b

For the usual reasons why those are not identifiers.

https://godbolt.org/z/G7v4j67dc

    fn f(x: i32) -> i32 {
        x * 2
    }

    macro_rules! f {
        ($x:ident) => { $x * 2 }
    }

    fn main() {
        let a = 42;

        let b = f(a);       // Function.
        let c = f!(a);      // Macro.

        //let c = f!(a2);   // Works, but the variable does not exist.
        //let c = f!(2a);   // Error: no rules expected the token `2a`.

        //let c = f!(a_b);  // Works, but the variable does not exist.
        //let c = f!(a-b);  // Error: no rules expected the token `-`.
        //let c = f!(a_ b); // Error: no rules expected the token `b`.

        println!("{a} {b} {c}");
    }

I hope this makes it clearer.

> You just need to extend the rust thing to be able to consume C header
> files.

I agree, because in practice it is quite useful for a language like
Rust that consuming C header files is "natively" supported.

Though it also has downsides and is a big decision, which is why, like
Alice mentioned, some people agree, and some people don't.
Nevertheless, we have been doing our best for a long time to get the
best we can for the kernel -- just 2 days ago we told the Rust project
in one of our meetings that it would be nice to see that particular
"project goal" from that document realized (among others).

Cheers,
Miguel

  parent reply	other threads:[~2024-06-07 11:46 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-06 15:05 [PATCH 0/3] Tracepoints and static branch/call in Rust Alice Ryhl
2024-06-06 15:05 ` [PATCH 1/3] rust: add static_call support Alice Ryhl
2024-06-06 17:18   ` Peter Zijlstra
2024-06-06 19:09     ` Miguel Ojeda
2024-06-06 19:33       ` Peter Zijlstra
2024-06-07  9:43         ` Alice Ryhl
2024-06-07 10:52           ` Peter Zijlstra
2024-06-07 11:08             ` Alice Ryhl
2024-06-07 11:46             ` Miguel Ojeda [this message]
2024-06-06 15:05 ` [PATCH 2/3] rust: add static_key_false Alice Ryhl
2024-06-06 15:38   ` Mathieu Desnoyers
2024-06-06 16:19     ` Alice Ryhl
2024-06-06 17:23   ` Peter Zijlstra
2024-06-06 15:05 ` [PATCH 3/3] rust: add tracepoint support Alice Ryhl
2024-06-06 15:30   ` Mathieu Desnoyers
2024-06-06 15:49     ` Boqun Feng
2024-06-06 16:18       ` Mathieu Desnoyers
2024-06-06 17:35       ` Peter Zijlstra
2024-06-06 19:00         ` Boqun Feng
2024-06-06 19:29           ` Peter Zijlstra
2024-06-06 23:50             ` Boqun Feng
2024-06-06 16:16     ` Alice Ryhl
2024-06-06 16:21       ` Mathieu Desnoyers
2024-06-06 17:26   ` Peter Zijlstra
2024-06-06 15:25 ` [PATCH 0/3] Tracepoints and static branch/call in Rust Mathieu Desnoyers
2024-06-06 15:46   ` Alice Ryhl
2024-06-06 16:17     ` Mathieu Desnoyers

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='CANiq72=4y84CrmkP-QsrW7YYNbpNJRim3oFK=kfEE8oin38pMQ@mail.gmail.com' \
    --to=miguel.ojeda.sandonis@gmail.com \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=ardb@kernel.org \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=jbaron@akamai.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=wedsonaf@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;
as well as URLs for NNTP newsgroup(s).