2023-02-24 07:26:36

by Asahi Lina

[permalink] [raw]
Subject: [PATCH 0/3] rust: Miscellaneous macro improvements

Hi everyone!

This short series is part of the set of dependencies for the drm/asahi
Apple M1/M2 GPU driver.

The first two patches make concat_idents!(bindings::foo, bar) work.
I use this later in the DRM abstractions to construct DRM IOCTL command
names [1], which avoids having to import all of bindings::*.

The third patch allows specifying multiple module aliases. Since modules
can have multiple aliases, the macro naturally needs to be able to take
an array instead of a single alias. I don't use this in the current
iteration of the driver, since I introduced proper support for automatic
modpost alias generation for Rust modules, but it can be useful both to
remove that support as a blocking factor (we can specify aliases manually
as a fallback), and for modules which need extra aliases not covered by
device ID tables.

[1] https://github.com/AsahiLinux/linux/blob/gpu/rebase-20230224/rust/kernel/drm/ioctl.rs#L101

Signed-off-by: Asahi Lina <[email protected]>
---
Asahi Lina (3):
rust: macros: Make expect_punct() return the Punct directly
rust: macros: concat_idents: Allow :: paths in the first argument
rust: macros: Allow specifying multiple module aliases
rust/macros/concat_idents.rs | 24 +++++++++++++++++++++---
rust/macros/helpers.rs | 14 +++++++++++---
rust/macros/module.rs | 34 +++++++++++++++++++++++++++-------
3 files changed, 59 insertions(+), 13 deletions(-)
---
base-commit: 83f978b63fa7ad474ca22d7e2772c5988101c9bd
change-id: 20230224-rust-macros-633dbf870ae1

Thank you,
~~ Lina



2023-02-24 07:26:40

by Asahi Lina

[permalink] [raw]
Subject: [PATCH 1/3] rust: macros: Make expect_punct() return the Punct directly

This makes it mirror the way expect_ident() works, and means we can more
easily push the result back into the token stream.

Signed-off-by: Asahi Lina <[email protected]>
---
rust/macros/concat_idents.rs | 2 +-
rust/macros/helpers.rs | 6 +++---
rust/macros/module.rs | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/rust/macros/concat_idents.rs b/rust/macros/concat_idents.rs
index 7e4b450f3a50..6d955d65016e 100644
--- a/rust/macros/concat_idents.rs
+++ b/rust/macros/concat_idents.rs
@@ -15,7 +15,7 @@ fn expect_ident(it: &mut token_stream::IntoIter) -> Ident {
pub(crate) fn concat_idents(ts: TokenStream) -> TokenStream {
let mut it = ts.into_iter();
let a = expect_ident(&mut it);
- assert_eq!(expect_punct(&mut it), ',');
+ assert_eq!(expect_punct(&mut it).as_char(), ',');
let b = expect_ident(&mut it);
assert!(it.next().is_none(), "only two idents can be concatenated");
let res = Ident::new(&format!("{a}{b}"), b.span());
diff --git a/rust/macros/helpers.rs b/rust/macros/helpers.rs
index cf7ad950dc1e..65706ecc007e 100644
--- a/rust/macros/helpers.rs
+++ b/rust/macros/helpers.rs
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0

-use proc_macro::{token_stream, TokenTree};
+use proc_macro::{token_stream, Punct, TokenTree};

pub(crate) fn try_ident(it: &mut token_stream::IntoIter) -> Option<String> {
if let Some(TokenTree::Ident(ident)) = it.next() {
@@ -38,9 +38,9 @@ pub(crate) fn expect_ident(it: &mut token_stream::IntoIter) -> String {
try_ident(it).expect("Expected Ident")
}

-pub(crate) fn expect_punct(it: &mut token_stream::IntoIter) -> char {
+pub(crate) fn expect_punct(it: &mut token_stream::IntoIter) -> Punct {
if let TokenTree::Punct(punct) = it.next().expect("Reached end of token stream for Punct") {
- punct.as_char()
+ punct
} else {
panic!("Expected Punct");
}
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index a7e363c2b044..07503b242d2d 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -104,7 +104,7 @@ impl ModuleInfo {
);
}

- assert_eq!(expect_punct(it), ':');
+ assert_eq!(expect_punct(it).as_char(), ':');

match key.as_str() {
"type" => info.type_ = expect_ident(it),
@@ -119,7 +119,7 @@ impl ModuleInfo {
),
}

- assert_eq!(expect_punct(it), ',');
+ assert_eq!(expect_punct(it).as_char(), ',');

seen_keys.push(key);
}

--
2.35.1


2023-02-24 07:26:43

by Asahi Lina

[permalink] [raw]
Subject: [PATCH 2/3] rust: macros: concat_idents: Allow :: paths in the first argument

This makes things like concat_idents!(bindings::foo, bar) work.
Otherwise, there is no way to concatenate two idents and then use the
result as part of a type path.

Signed-off-by: Asahi Lina <[email protected]>
---
rust/macros/concat_idents.rs | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/rust/macros/concat_idents.rs b/rust/macros/concat_idents.rs
index 6d955d65016e..d6614b900aa2 100644
--- a/rust/macros/concat_idents.rs
+++ b/rust/macros/concat_idents.rs
@@ -14,10 +14,28 @@ fn expect_ident(it: &mut token_stream::IntoIter) -> Ident {

pub(crate) fn concat_idents(ts: TokenStream) -> TokenStream {
let mut it = ts.into_iter();
- let a = expect_ident(&mut it);
- assert_eq!(expect_punct(&mut it).as_char(), ',');
+ let mut out = TokenStream::new();
+ let a = loop {
+ let ident = expect_ident(&mut it);
+ let punct = expect_punct(&mut it);
+ match punct.as_char() {
+ ',' => break ident,
+ ':' => {
+ let punct2 = expect_punct(&mut it);
+ assert_eq!(punct2.as_char(), ':');
+ out.extend([
+ TokenTree::Ident(ident),
+ TokenTree::Punct(punct),
+ TokenTree::Punct(punct2),
+ ]);
+ }
+ _ => panic!("Expected , or ::"),
+ }
+ };
+
let b = expect_ident(&mut it);
assert!(it.next().is_none(), "only two idents can be concatenated");
let res = Ident::new(&format!("{a}{b}"), b.span());
- TokenStream::from_iter([TokenTree::Ident(res)])
+ out.extend([TokenTree::Ident(res)]);
+ out
}

--
2.35.1


2023-02-24 07:26:49

by Asahi Lina

[permalink] [raw]
Subject: [PATCH 3/3] rust: macros: Allow specifying multiple module aliases

Modules can (and usually do) have multiple alias tags, in order to
specify multiple possible device matches for autoloading. Allow this by
changing the alias ModuleInfo field to an Option<Vec<String>>.

Note: For normal device IDs this is autogenerated by modpost (which is
not properly integrated with Rust support yet), so it is useful to be
able to manually add device match aliases for now, and should still be
useful in the future for corner cases that modpost does not handle.

This pulls in the expect_group() helper from the rfl/rust branch
(with credit to authors).

Co-developed-by: Miguel Ojeda <[email protected]>
Signed-off-by: Miguel Ojeda <[email protected]>
Co-developed-by: Finn Behrens <[email protected]>
Signed-off-by: Finn Behrens <[email protected]>
Co-developed-by: Sumera Priyadarsini <[email protected]>
Signed-off-by: Sumera Priyadarsini <[email protected]>
Signed-off-by: Asahi Lina <[email protected]>
---
rust/macros/helpers.rs | 10 +++++++++-
rust/macros/module.rs | 30 +++++++++++++++++++++++++-----
2 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/rust/macros/helpers.rs b/rust/macros/helpers.rs
index 65706ecc007e..15bf0c892421 100644
--- a/rust/macros/helpers.rs
+++ b/rust/macros/helpers.rs
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0

-use proc_macro::{token_stream, Punct, TokenTree};
+use proc_macro::{token_stream, Group, Punct, TokenTree};

pub(crate) fn try_ident(it: &mut token_stream::IntoIter) -> Option<String> {
if let Some(TokenTree::Ident(ident)) = it.next() {
@@ -56,6 +56,14 @@ pub(crate) fn expect_string_ascii(it: &mut token_stream::IntoIter) -> String {
string
}

+pub(crate) fn expect_group(it: &mut token_stream::IntoIter) -> Group {
+ if let TokenTree::Group(group) = it.next().expect("Reached end of token stream for Group") {
+ group
+ } else {
+ panic!("Expected Group");
+ }
+}
+
pub(crate) fn expect_end(it: &mut token_stream::IntoIter) {
if it.next().is_some() {
panic!("Expected end");
diff --git a/rust/macros/module.rs b/rust/macros/module.rs
index 07503b242d2d..92cb35c235e1 100644
--- a/rust/macros/module.rs
+++ b/rust/macros/module.rs
@@ -1,9 +1,27 @@
// SPDX-License-Identifier: GPL-2.0

use crate::helpers::*;
-use proc_macro::{token_stream, Literal, TokenStream, TokenTree};
+use proc_macro::{token_stream, Delimiter, Literal, TokenStream, TokenTree};
use std::fmt::Write;

+fn expect_string_array(it: &mut token_stream::IntoIter) -> Vec<String> {
+ let group = expect_group(it);
+ assert_eq!(group.delimiter(), Delimiter::Bracket);
+ let mut values = Vec::new();
+ let mut it = group.stream().into_iter();
+
+ while let Some(val) = try_string(&mut it) {
+ assert!(val.is_ascii(), "Expected ASCII string");
+ values.push(val);
+ match it.next() {
+ Some(TokenTree::Punct(punct)) => assert_eq!(punct.as_char(), ','),
+ None => break,
+ _ => panic!("Expected ',' or end of array"),
+ }
+ }
+ values
+}
+
struct ModInfoBuilder<'a> {
module: &'a str,
counter: usize,
@@ -78,7 +96,7 @@ struct ModuleInfo {
name: String,
author: Option<String>,
description: Option<String>,
- alias: Option<String>,
+ alias: Option<Vec<String>>,
}

impl ModuleInfo {
@@ -112,7 +130,7 @@ impl ModuleInfo {
"author" => info.author = Some(expect_string(it)),
"description" => info.description = Some(expect_string(it)),
"license" => info.license = expect_string_ascii(it),
- "alias" => info.alias = Some(expect_string_ascii(it)),
+ "alias" => info.alias = Some(expect_string_array(it)),
_ => panic!(
"Unknown key \"{}\". Valid keys are: {:?}.",
key, EXPECTED_KEYS
@@ -163,8 +181,10 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {
modinfo.emit("description", &description);
}
modinfo.emit("license", &info.license);
- if let Some(alias) = info.alias {
- modinfo.emit("alias", &alias);
+ if let Some(aliases) = info.alias {
+ for alias in aliases {
+ modinfo.emit("alias", &alias);
+ }
}

// Built-in modules also export the `file` modinfo string.

--
2.35.1


2023-02-24 07:39:58

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 3/3] rust: macros: Allow specifying multiple module aliases

On Fri, Feb 24, 2023 at 04:25:57PM +0900, Asahi Lina wrote:
> Modules can (and usually do) have multiple alias tags, in order to
> specify multiple possible device matches for autoloading. Allow this by
> changing the alias ModuleInfo field to an Option<Vec<String>>.

Note, manually specifying the MODULE_ALIAS is only really ever done for
platform drivers today (and I would argue we need to fix that up),
otherwise the use of MODULE_DEVICE_TABLE() should really really be used
instead of having to manually specify aliases.

And why would a module alias be needed for new (i.e. rust) code anyway?
You aren't trying to do any backwards-compatibility stuff yet :)

Or is this just for a platform driver? It's hard to review
infrastructure changes without seeing any real users :(

thanks,

greg k-h

2023-02-24 12:41:19

by Asahi Lina

[permalink] [raw]
Subject: Re: [PATCH 3/3] rust: macros: Allow specifying multiple module aliases

On 24/02/2023 16.38, Greg KH wrote:
> On Fri, Feb 24, 2023 at 04:25:57PM +0900, Asahi Lina wrote:
>> Modules can (and usually do) have multiple alias tags, in order to
>> specify multiple possible device matches for autoloading. Allow this by
>> changing the alias ModuleInfo field to an Option<Vec<String>>.
>
> Note, manually specifying the MODULE_ALIAS is only really ever done for
> platform drivers today (and I would argue we need to fix that up),
> otherwise the use of MODULE_DEVICE_TABLE() should really really be used
> instead of having to manually specify aliases.

That's the plan, I just added this before adding support for
MODULE_DEVICE_TABLE() when I first realized that it wasn't yet in there!
We were briefly hardcoding the bus aliases for downstream kernels
because the depmod stuff couldn't work with the way device ID tables
were done in Rust downstream at the time (and I only noticed the first
time I tried to build it as a module, since I always develop with
monolithic kernels). That's fixed now ^^

However, the issue is that right now the module macro already takes a
single optional alias, and that doesn't make sense as an API. We could
remove support for this entirely (if I get my Rust MODULE_DEVICE_TABLE()
implementation in, there will be zero users of the alias argument as far
as I know), or add support for multiple aliases. But I think just
leaving it as a single alias doesn't really make sense? It doesn't
represent the way module aliases work, which is 0..N.

I'm fine with removing it if people prefer that, I just thought that for
something as basic as module metadata we might as well do it properly
even if there are no users right now, since it's already half in there...

~~ Lina

2023-02-24 12:49:23

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 3/3] rust: macros: Allow specifying multiple module aliases

On Fri, Feb 24, 2023 at 09:41:08PM +0900, Asahi Lina wrote:
> On 24/02/2023 16.38, Greg KH wrote:
> > On Fri, Feb 24, 2023 at 04:25:57PM +0900, Asahi Lina wrote:
> >> Modules can (and usually do) have multiple alias tags, in order to
> >> specify multiple possible device matches for autoloading. Allow this by
> >> changing the alias ModuleInfo field to an Option<Vec<String>>.
> >
> > Note, manually specifying the MODULE_ALIAS is only really ever done for
> > platform drivers today (and I would argue we need to fix that up),
> > otherwise the use of MODULE_DEVICE_TABLE() should really really be used
> > instead of having to manually specify aliases.
>
> That's the plan, I just added this before adding support for
> MODULE_DEVICE_TABLE() when I first realized that it wasn't yet in there!
> We were briefly hardcoding the bus aliases for downstream kernels
> because the depmod stuff couldn't work with the way device ID tables
> were done in Rust downstream at the time (and I only noticed the first
> time I tried to build it as a module, since I always develop with
> monolithic kernels). That's fixed now ^^
>
> However, the issue is that right now the module macro already takes a
> single optional alias, and that doesn't make sense as an API. We could
> remove support for this entirely (if I get my Rust MODULE_DEVICE_TABLE()
> implementation in, there will be zero users of the alias argument as far
> as I know), or add support for multiple aliases. But I think just
> leaving it as a single alias doesn't really make sense? It doesn't
> represent the way module aliases work, which is 0..N.
>
> I'm fine with removing it if people prefer that, I just thought that for
> something as basic as module metadata we might as well do it properly
> even if there are no users right now, since it's already half in there...

How about just removing it so that people don't think it is something
that they really should be doing and adding real MODULE_DEVICE_TABLE()
support instead?

Although the first filesystem that gets written will need the
MODULE_ALIAS() logic added back, oh well.

Anyway, no objection for me for this for now, just trying to point out
that drivers really should not be using MODULE_ALIAS() at all.

thanks,

greg k-h

2023-02-25 00:29:54

by Gary Guo

[permalink] [raw]
Subject: Re: [PATCH 1/3] rust: macros: Make expect_punct() return the Punct directly

On Fri, 24 Feb 2023 16:25:55 +0900
Asahi Lina <[email protected]> wrote:

> This makes it mirror the way expect_ident() works, and means we can more
> easily push the result back into the token stream.
>
> Signed-off-by: Asahi Lina <[email protected]>

Reviewed-by: Gary Guo <[email protected]>

> ---
> rust/macros/concat_idents.rs | 2 +-
> rust/macros/helpers.rs | 6 +++---
> rust/macros/module.rs | 4 ++--
> 3 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/rust/macros/concat_idents.rs b/rust/macros/concat_idents.rs
> index 7e4b450f3a50..6d955d65016e 100644
> --- a/rust/macros/concat_idents.rs
> +++ b/rust/macros/concat_idents.rs
> @@ -15,7 +15,7 @@ fn expect_ident(it: &mut token_stream::IntoIter) -> Ident {
> pub(crate) fn concat_idents(ts: TokenStream) -> TokenStream {
> let mut it = ts.into_iter();
> let a = expect_ident(&mut it);
> - assert_eq!(expect_punct(&mut it), ',');
> + assert_eq!(expect_punct(&mut it).as_char(), ',');
> let b = expect_ident(&mut it);
> assert!(it.next().is_none(), "only two idents can be concatenated");
> let res = Ident::new(&format!("{a}{b}"), b.span());
> diff --git a/rust/macros/helpers.rs b/rust/macros/helpers.rs
> index cf7ad950dc1e..65706ecc007e 100644
> --- a/rust/macros/helpers.rs
> +++ b/rust/macros/helpers.rs
> @@ -1,6 +1,6 @@
> // SPDX-License-Identifier: GPL-2.0
>
> -use proc_macro::{token_stream, TokenTree};
> +use proc_macro::{token_stream, Punct, TokenTree};
>
> pub(crate) fn try_ident(it: &mut token_stream::IntoIter) -> Option<String> {
> if let Some(TokenTree::Ident(ident)) = it.next() {
> @@ -38,9 +38,9 @@ pub(crate) fn expect_ident(it: &mut token_stream::IntoIter) -> String {
> try_ident(it).expect("Expected Ident")
> }
>
> -pub(crate) fn expect_punct(it: &mut token_stream::IntoIter) -> char {
> +pub(crate) fn expect_punct(it: &mut token_stream::IntoIter) -> Punct {
> if let TokenTree::Punct(punct) = it.next().expect("Reached end of token stream for Punct") {
> - punct.as_char()
> + punct
> } else {
> panic!("Expected Punct");
> }
> diff --git a/rust/macros/module.rs b/rust/macros/module.rs
> index a7e363c2b044..07503b242d2d 100644
> --- a/rust/macros/module.rs
> +++ b/rust/macros/module.rs
> @@ -104,7 +104,7 @@ impl ModuleInfo {
> );
> }
>
> - assert_eq!(expect_punct(it), ':');
> + assert_eq!(expect_punct(it).as_char(), ':');
>
> match key.as_str() {
> "type" => info.type_ = expect_ident(it),
> @@ -119,7 +119,7 @@ impl ModuleInfo {
> ),
> }
>
> - assert_eq!(expect_punct(it), ',');
> + assert_eq!(expect_punct(it).as_char(), ',');
>
> seen_keys.push(key);
> }
>


2023-02-25 00:32:05

by Gary Guo

[permalink] [raw]
Subject: Re: [PATCH 2/3] rust: macros: concat_idents: Allow :: paths in the first argument

On Fri, 24 Feb 2023 16:25:56 +0900
Asahi Lina <[email protected]> wrote:

> This makes things like concat_idents!(bindings::foo, bar) work.
> Otherwise, there is no way to concatenate two idents and then use the
> result as part of a type path.

It seems weird to me that this is called `concat_idents` despite
working for more things than just idents.

How about just implement a simple version of the `paste` macro instead?

Best,
Gary

>
> Signed-off-by: Asahi Lina <[email protected]>
> ---
> rust/macros/concat_idents.rs | 24 +++++++++++++++++++++---
> 1 file changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/rust/macros/concat_idents.rs b/rust/macros/concat_idents.rs
> index 6d955d65016e..d6614b900aa2 100644
> --- a/rust/macros/concat_idents.rs
> +++ b/rust/macros/concat_idents.rs
> @@ -14,10 +14,28 @@ fn expect_ident(it: &mut token_stream::IntoIter) -> Ident {
>
> pub(crate) fn concat_idents(ts: TokenStream) -> TokenStream {
> let mut it = ts.into_iter();
> - let a = expect_ident(&mut it);
> - assert_eq!(expect_punct(&mut it).as_char(), ',');
> + let mut out = TokenStream::new();
> + let a = loop {
> + let ident = expect_ident(&mut it);
> + let punct = expect_punct(&mut it);
> + match punct.as_char() {
> + ',' => break ident,
> + ':' => {
> + let punct2 = expect_punct(&mut it);
> + assert_eq!(punct2.as_char(), ':');
> + out.extend([
> + TokenTree::Ident(ident),
> + TokenTree::Punct(punct),
> + TokenTree::Punct(punct2),
> + ]);
> + }
> + _ => panic!("Expected , or ::"),
> + }
> + };
> +
> let b = expect_ident(&mut it);
> assert!(it.next().is_none(), "only two idents can be concatenated");
> let res = Ident::new(&format!("{a}{b}"), b.span());
> - TokenStream::from_iter([TokenTree::Ident(res)])
> + out.extend([TokenTree::Ident(res)]);
> + out
> }
>


2023-02-28 09:30:22

by Finn Behrens

[permalink] [raw]
Subject: Re: [PATCH 1/3] rust: macros: Make expect_punct() return the Punct directly



On 24 Feb 2023, at 8:25, Asahi Lina wrote:

> This makes it mirror the way expect_ident() works, and means we can more
> easily push the result back into the token stream.
>
> Signed-off-by: Asahi Lina <[email protected]>

Reviewed-by: Finn Behrens <[email protected]>

> ---
> rust/macros/concat_idents.rs | 2 +-
> rust/macros/helpers.rs | 6 +++---
> rust/macros/module.rs | 4 ++--
> 3 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/rust/macros/concat_idents.rs b/rust/macros/concat_idents.rs
> index 7e4b450f3a50..6d955d65016e 100644
> --- a/rust/macros/concat_idents.rs
> +++ b/rust/macros/concat_idents.rs
> @@ -15,7 +15,7 @@ fn expect_ident(it: &mut token_stream::IntoIter) -> Ident {
> pub(crate) fn concat_idents(ts: TokenStream) -> TokenStream {
> let mut it = ts.into_iter();
> let a = expect_ident(&mut it);
> - assert_eq!(expect_punct(&mut it), ',');
> + assert_eq!(expect_punct(&mut it).as_char(), ',');
> let b = expect_ident(&mut it);
> assert!(it.next().is_none(), "only two idents can be concatenated");
> let res = Ident::new(&format!("{a}{b}"), b.span());
> diff --git a/rust/macros/helpers.rs b/rust/macros/helpers.rs
> index cf7ad950dc1e..65706ecc007e 100644
> --- a/rust/macros/helpers.rs
> +++ b/rust/macros/helpers.rs
> @@ -1,6 +1,6 @@
> // SPDX-License-Identifier: GPL-2.0
>
> -use proc_macro::{token_stream, TokenTree};
> +use proc_macro::{token_stream, Punct, TokenTree};
>
> pub(crate) fn try_ident(it: &mut token_stream::IntoIter) -> Option<String> {
> if let Some(TokenTree::Ident(ident)) = it.next() {
> @@ -38,9 +38,9 @@ pub(crate) fn expect_ident(it: &mut token_stream::IntoIter) -> String {
> try_ident(it).expect("Expected Ident")
> }
>
> -pub(crate) fn expect_punct(it: &mut token_stream::IntoIter) -> char {
> +pub(crate) fn expect_punct(it: &mut token_stream::IntoIter) -> Punct {
> if let TokenTree::Punct(punct) = it.next().expect("Reached end of token stream for Punct") {
> - punct.as_char()
> + punct
> } else {
> panic!("Expected Punct");
> }
> diff --git a/rust/macros/module.rs b/rust/macros/module.rs
> index a7e363c2b044..07503b242d2d 100644
> --- a/rust/macros/module.rs
> +++ b/rust/macros/module.rs
> @@ -104,7 +104,7 @@ impl ModuleInfo {
> );
> }
>
> - assert_eq!(expect_punct(it), ':');
> + assert_eq!(expect_punct(it).as_char(), ':');
>
> match key.as_str() {
> "type" => info.type_ = expect_ident(it),
> @@ -119,7 +119,7 @@ impl ModuleInfo {
> ),
> }
>
> - assert_eq!(expect_punct(it), ',');
> + assert_eq!(expect_punct(it).as_char(), ',');
>
> seen_keys.push(key);
> }
>
> --
> 2.35.1

2023-03-01 17:16:42

by Vincenzo Palazzo

[permalink] [raw]
Subject: Re: [PATCH 1/3] rust: macros: Make expect_punct() return the Punct directly

> This makes it mirror the way expect_ident() works, and means we can more
> easily push the result back into the token stream.
>
> Signed-off-by: Asahi Lina <[email protected]>
> ---

Reviewed-by: Vincenzo Palazzo <[email protected]>

2023-03-01 17:18:10

by Vincenzo Palazzo

[permalink] [raw]
Subject: Re: [PATCH 2/3] rust: macros: concat_idents: Allow :: paths in the first argument

> This makes things like concat_idents!(bindings::foo, bar) work.
> Otherwise, there is no way to concatenate two idents and then use the
> result as part of a type path.
>
> Signed-off-by: Asahi Lina <[email protected]>
> ---

Reviewed-by: Vincenzo Palazzo <[email protected]>

2023-03-01 17:19:53

by Vincenzo Palazzo

[permalink] [raw]
Subject: Re: [PATCH 3/3] rust: macros: Allow specifying multiple module aliases

> Modules can (and usually do) have multiple alias tags, in order to
> specify multiple possible device matches for autoloading. Allow this by
> changing the alias ModuleInfo field to an Option<Vec<String>>.
>
> Note: For normal device IDs this is autogenerated by modpost (which is
> not properly integrated with Rust support yet), so it is useful to be
> able to manually add device match aliases for now, and should still be
> useful in the future for corner cases that modpost does not handle.
>
> This pulls in the expect_group() helper from the rfl/rust branch
> (with credit to authors).
>
> Co-developed-by: Miguel Ojeda <[email protected]>
> Signed-off-by: Miguel Ojeda <[email protected]>
> Co-developed-by: Finn Behrens <[email protected]>
> Signed-off-by: Finn Behrens <[email protected]>
> Co-developed-by: Sumera Priyadarsini <[email protected]>
> Signed-off-by: Sumera Priyadarsini <[email protected]>
> Signed-off-by: Asahi Lina <[email protected]>
> ---

Reviewed-by: Vincenzo Palazzo <[email protected]>

2023-03-07 20:22:51

by Miguel Ojeda

[permalink] [raw]
Subject: Re: [PATCH 2/3] rust: macros: concat_idents: Allow :: paths in the first argument

On Sat, Feb 25, 2023 at 1:32 AM Gary Guo <[email protected]> wrote:
>
> It seems weird to me that this is called `concat_idents` despite
> working for more things than just idents.
>
> How about just implement a simple version of the `paste` macro instead?

Opened https://github.com/Rust-for-Linux/linux/issues/983 in case we
end up applying the patch.

Cheers,
Miguel

2023-03-08 20:57:34

by Miguel Ojeda

[permalink] [raw]
Subject: Re: [PATCH 2/3] rust: macros: concat_idents: Allow :: paths in the first argument

On Sat, Feb 25, 2023 at 1:32 AM Gary Guo <[email protected]> wrote:
>
> It seems weird to me that this is called `concat_idents` despite
> working for more things than just idents.
>
> How about just implement a simple version of the `paste` macro instead?

We discussed this in our latest meeting: what about a change of name
to `concat_paths`? That addresses the concern plus it avoids sharing
the name with the unstable `concat_idents` which could be even more
confusing after this patch.

Cheers,
Miguel