-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tracking Issue for RFC 3086: macro metavariable expressions #83527
Comments
There is a working prototype on the |
Update (2021-04-07)I've not yet started work on productionizing the prototype on the |
enum_dispatch is somewhat broken, and we need to write manual dispatch code for pyo3 anyway (and have written similar dispatch code for many other things). rust-lang/rust#83527 would make it more convenient to make our manual dispatch code generic.
Update (2021-05-09)I still haven't started on this yet as some stuff came up last month that prevented from having the time to work on it. It's still in my plan to work on it, and hopefully I'll have some time soon. |
Update (2021-06-29)Still no progress, as I haven't had any spare time to work on this project. I'm still planning to work on it, and hopefully will get some time soon. |
@markbt If you don't expect to find the bandwidth in the near future, would you potentially be interested in seeking help in the form of another owner for this initiative? If you're still interested in driving this, that's fine, but if you'd like us to switch gears from pinging you to broadcasting that the project could use help, we'd be happy to do that. |
I'd be happy with any help if there's someone available. I still plan to work on it, but personal stuff is getting in the way at the moment. Sorry about that. To recap: I have a working prototype on my branch at https://github.com/markbt/rust/tree/metavariable_expressions . The next steps are to rebase that onto the latest master, and then polish it up so that it's ready for inclusion. Then there's also the doc work to make sure the new feature is documented well. Help with any of this would be appreciated. |
@markbt Are you still working on this feature? If not, then I can pick up from where you stopped |
I haven't had a chance to work on it for a while. I'm still interested in it, so happy to help out if you're picking it up, it just had to take a back burner relative to some personal things.I have a branch with a prototype implementation on my github fork. It's likely very out of date, so will need rebasing up to something more recent. Or perhaps you can just use it for inspiration and start from scratch. Let me know if I can help at all, although I don't have a lot of free time at the moment.
|
Thank you @markbt I will take a look at the branch and then get in touch if any questions arise |
Fix remaining meta-variable expression TODOs As promised on rust-lang#93545. cc rust-lang#83527 cc `@mark-i-m` cc `@petrochenkov`
The implementation has been merged so please try testing the feature as much as possible to find any potential bugs |
Thanks @c410-f3r for all your hard work! From my limited experience with this feature, I have some concerns about the design:
|
Thank you @mark-i-m for reviewing #93545 and for all your contributions to the compiler. Hehehehe... You, me and @petrochenkov had trouble trying to understand this feature
Indeed! It is much easier cognitively to keep everything with the same direction instead of having
Yeap, someone that wrote
And as you said, throwing nested loops into the equation will alter indexing making understanding even harder. Not to mention mixing other meta-variable expressions like #![feature(macro_metavar_expr)]
fn main() {
macro_rules! mac {
( $( [ $( $i:ident )* ] )* ) => {{
// ***** No loop *****
println!("{}", ${count(i)}); // 5
println!("{}", ${count(i, 0)}); // 2
// Same as ${count(i)}
//println!("{}", ${count(i, 1)});
// Fobirdden. Index out of bounds
//println!("{}", ${count(i, 2)});
// ***** Outer-most loop *****
$(
println!("{}", ${count(i)}); // 3 and 2
// Same as ${count(i)}
//println!("{}", ${count(i, 0)});
// Fobirdden. Index out of bounds
//println!("{}", ${count(i, 1)});
)*
// ***** Outer-most and inner-most loops *****
$(
$(
${ignore(i)}
// Forbidden. Can't be placed inside the inner-most repetition
//println!("{}", ${count(i)});
)*
)*
}};
}
mac!([a b c] [d e]);
} Maybe As for myself, I learned to accept the things as they are currently defined in RFC, hehehehe 😁 |
Any thoughts @markbt? |
+1. Being inconsistent here seems out of the question. I would vote for "distance from innermost", agreeing with the rationale in the RFC:
Adding to this, having the
The only bad thing is that the English meaning of "depth" lends to "distance from outermost". But this is less important IMO. We could support both by having negative numbers (e.g.
Has it been considered to make theses values bind-able within the macro pattern? This would take macro_rules! mac {
($[i=index, l=length]($word:ident),*) => {
$(println!("{}/{}: {}", $i, $l, stringify!($word));)*
};
} |
refactor:higher-order http method macro we want to switch to rust nightly to be able to make use of rust metavariable expansions as defined by RFC rust-lang/rfcs#3086 and as tracked by rust-lang/rust#83527. other references include rust-lang/rust#99035. this feature was stabilized in 1.63, then unstabilized again in rust-lang/rust#99435 and is now only available in rust nightly, awaiting restabilization. however, the feature is stable enough for our use case, which is why i'm going ahead and enabling it.
@CAD97 for real? $$ and $ignore were supposed to be stabilized for over a year now. |
i am guessing the solution would be to merge $$ and $ignore ASAP, |
Yes, and I discovered the interesting behavior of
This becomes extremely necessary when using
I originally claimed it wouldn't be possible to stabilize
I don't actually have any power to directly block stabilization, let alone to revert an accepted stabilization on beta; if T-lang1 didn't agree with my concern about Though tbf, I'm not blameless; I've proposed various resolutions and haven't followed up with an implementation. (This reminds me, I should ideally try my hand at properly implementing my desired fix for Footnotes
|
$crate feels hacky to me. With macros 1.0, i force the user to import the entire scope of the macro, if it requires it. I admit i am not an expert, but it might be worth to read my ideas for macro 2.0: |
ProposalIn hopes of making some progress, two approaches based on the feedback provided so far will be proposed here. Feel free to discuss alternatives that will lead to consensus if any of the following suggestions are not desired. 1. Innermost vs Outermost indexes
To improve the situation, the order of all elements should start from the innermost index to the outermost index. Mentions
2.
|
It's nice to see this progressing. We recently found some more places where this would be useful, e.g. in constructing a tuple from a method that takes indexes using an expression like 1. IndexesFor For
This proposal switches the order of N, but it's fine for it to mean either way. 2.
|
Note from lang team: we discussed @c410-f3r's proposed changes in our meeting today and agree we should move forward, but please update the comment at top of the issue. More here. |
…enkov [`RFC 3086`] Attempt to try to resolve blocking concerns Implements what is described at rust-lang#83527 (comment) to hopefully make some progress. It is unknown if such approach is or isn't desired due to the lack of further feedback, as such, it is probably best to nominate this PR to the official entities. `@rustbot` labels +I-compiler-nominated
…chenkov [`RFC 3086`] Attempt to try to resolve blocking concerns Implements what is described at rust-lang#83527 (comment) to hopefully make some progress. It is unknown if such approach is or isn't desired due to the lack of further feedback, as such, it is probably best to nominate this PR to the official entities. `@rustbot` labels +I-compiler-nominated
…enkov [`RFC 3086`] Attempt to try to resolve blocking concerns Implements what is described at rust-lang#83527 (comment) to hopefully make some progress. It is unknown if such approach is or isn't desired due to the lack of further feedback, as such, it is probably best to nominate this PR to the official entities. `@rustbot` labels +I-compiler-nominated
[`RFC 3086`] Attempt to try to resolve blocking concerns Implements what is described at rust-lang/rust#83527 (comment) to hopefully make some progress. It is unknown if such approach is or isn't desired due to the lack of further feedback, as such, it is probably best to nominate this PR to the official entities. `@rustbot` labels +I-compiler-nominated
Nesting #![feature(macro_metavar_expr)]
struct Foo(i32);
struct Bar(i32);
struct Baz(i32);
macro_rules! mk_p {
($p_ty:ty $(, foo=$foo:ident)? $(, bar=$bar:ident)?) => {
$(${ignore($foo)} mk_p!($p_ty, foo=$foo, foo_or_bar=foo_or_bar); )?
$(${ignore($bar)} mk_p!($p_ty, bar=$bar, foo_or_bar=foo_or_bar); )?
};
($p_ty:ty $(, foo=$foo:ident)? $(, bar=$bar:ident)? $(, baz=$baz:ident)? $(, foo_or_bar=$foo_or_bar:ident)?) => {
impl $p_ty {
fn p(&self) {
$(
${ignore($baz)}
eprintln!("baz={}", self.0);
)?
$(
${ignore($foo_or_bar)}
let i = self.0 + 5;
$(
${ignore($foo)}
eprintln!("foo={i}");
)?
$(
${ignore($bar)}
eprintln!("bar={i}");
)?
)?
}
}
};
}
mk_p!(Foo, foo=foo);
mk_p!(Bar, bar=bar);
mk_p!(Baz, baz=baz);
fn main() {} Error:
Is this a current limitation or intended behavior? |
#117050 was merged ~2 months ago and no related issues have been created since then. Can we finally proceed with the stabilization of everything but |
A stabilization attempt is available at #122808 |
[`RFC 3086`] Attempt to try to resolve blocking concerns Implements what is described at rust-lang/rust#83527 (comment) to hopefully make some progress. It is unknown if such approach is or isn't desired due to the lack of further feedback, as such, it is probably best to nominate this PR to the official entities. `@rustbot` labels +I-compiler-nominated
[`RFC 3086`] Attempt to try to resolve blocking concerns Implements what is described at rust-lang/rust#83527 (comment) to hopefully make some progress. It is unknown if such approach is or isn't desired due to the lack of further feedback, as such, it is probably best to nominate this PR to the official entities. `@rustbot` labels +I-compiler-nominated
🚀 I found a way to evaluate Note: And in other words, Also, Also, https://crates.io/crates/with_builtin_macros allows one to use // (This code was not tested, may contain typos)
fn concat_idents!(a, b) () {} // Doesn't work
with_builtin_macros::with_eager_expansions! {
fn #{ concat_idents!(a, b) } () {} // Works! Even on stable!
}
macro_rules! this_macro_accepts_ident {
($a:ident) => {}
}
// Doesn't work, because "this_macro_accepts_ident" evaluates before "concat_idents"
this_macro_accepts_ident!(concat_idents!(a, b));
with_builtin_macros::with_eager_expansions! {
this_macro_accepts_ident!(#{ concat_idents!(a, b) }); // Works! Even on stable!
}
macro_rules! this_macro_accepts_literal {
($a:literal) => {}
}
// Doesn't work.
// Moreover, you cannot solve this problem using #[feature(macro_metavar_expr_concat)],
// because ${concat(...)} produces identifier, not string literal!!!
// Same applies to "paste"! "paste::paste!" deals with identifiers, not strings. So, with_builtin_macros is the only way!!!
this_macro_accepts_literal!(concat!("a", "b"));
with_builtin_macros::with_eager_expansions! {
this_macro_accepts_literal!(#{ concat!("a", "b") }); // Works! Even on stable!
} |
This is a tracking issue for the RFC "3086" (rust-lang/rfcs#3086).
The feature gate for the issue is
#![feature(macro_metavar_expr)]
.About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
Unresolved questions and bugs
Implementation history
The text was updated successfully, but these errors were encountered: