-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
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?
- You'd need a new AST node called (say) quote_expr.
- The typechecker would have to know that any quote_ast node trivially has the type ast::expr -- no checking required.
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.