-
Notifications
You must be signed in to change notification settings - Fork 13.3k
quote_expr, quote_tokens, etc. should not require an "ext_cx" to be in scope -- HOW TO FIX THEM #7727
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
Comments
It seems like this might lend itself to a solution for two problems: quoting and macros being only able to expand to expressions or (one) item (e.g. #4621). Specifically, something like: enum SyntaxWrapper<T> {
Plain(T),
Quote(T),
MacroInvocation(Mac)
}
type Expr = SyntaxWrapper<Exp_r>;
type Item = SyntaxWrapper<Item_>;
type Method = SyntaxWrapper<Method_>;
type Ty = SyntaxWrapper<Ty_>;
// ... (It'd be nice to have GADTs to be able to express that However, I would imagine that this would have a big negative effect on downstream code, and we appear to be moving away from the |
Since issues are forever, I should add that @graydon indicates that Rust used to have something like this, but that as he quite correctly points out, it doesn't solve quasiquoting. This is true; quasiquoting highlights the value of simplicity in ASTs. So, I still think adding a quoted-syntax AST node makes sense, but I see that you still need a nice way to mix computed and quoted elements to get quasiquote. |
They previously required one called "ext_cx" to be in scope. Fixes part of rust-lang#7727
They previously required one called "ext_cx" to be in scope. Fixes part of #7727
I'm not sure what the situation is today. @kmcallister ? |
Triage: with no updates since 2013, and big changes planned to the syntax extension system, i'm going to give this one a close. |
Update changelog to 1.56 As expected a pretty short changelog, because of the missed sync last release cycle. [Rendered](https://github.com/flip1995/rust-clippy/blob/changelog/CHANGELOG.md) changelog: none
There are a number of problems with our current quote_expr!, quote_tokens!, etc. macros. The first one is that they're cloaking/unhygienic. Fixing this is easy--just change the macro definition so that you have to supply an identifier as the first argument.
The second problem is that they really shouldn't work in the way that they do.
Specifically, these macros currently expand into ASTs that represent calls to the parser, thereby generating an AST. This discards all context/hygiene information, and is also inefficient, since you already have the AST that you're trying to protect.
Languages such as Racket just provide a language primitive called "quote-syntax" whose evaluation rule is literally the trivial one--a use of quote-syntax simply evaluates to the AST on the right hand side of the call.
What would it take to add this to Rust?
This should be less than a day of work for someone who really understands the system well. One question is whether you want to duplicate this work for each of the quote_... thingies, or make one that covers them all, with some kind of simple enum.
It appears to me that it would also allow us to throw out a huge amount of code--all of the quoting stuff that's in there currently.
The text was updated successfully, but these errors were encountered: