-
Notifications
You must be signed in to change notification settings - Fork 13k
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
warning: Quasi-quoting might make incremental compilation very inefficient: NtIdent(..) #40946
Comments
That's strange. @jseyfried, do you see anything in the macro above that in a
|
ping @jseyfried: Do you know what could be going on here? Where does the macro definition above introduce a |
The I believe the solution here is to expand interpolated/nonterminal tokens into their underlying terminal tokens as we lower to HIR. |
@jseyfried If I understand correctly, something is inefficient but what needs to change to fix it is in rustc rather than in my code? |
@SimonSapin That is correct. It's an inefficiency in rustc's handling of some parts of the HIR/AST. |
@jseyfried, that sounds like a great solution. Would that be much work? |
@michaelwoerister |
I'm getting this warning too when using proc-macro-hack (cc @dtolnay). Is there any way to suppress it? warning: Quasi-quoting might make incremental compilation very inefficient: NtIdent(..)
--> derive/src/lib.rs:9:1
|
9 | proc_macro_expr_impl! {
| _^ starting here...
10 | | pub fn args_impl(input: &str) -> String {
11 | | args::Args::new(input)
12 | | .process().tokens
13 | | .to_string()
14 | | }
15 | | }
| |_^ ...ending here
|
= note: this error originates in a macro outside of the current crate |
If it will take a while to fix this, it would be nice to at least be able to suppress the warning. |
@jseyfried Is there an ETA for #40939? |
Now that #40939 has landed, will you look into a fix, @jseyfried? |
@michaelwoerister Sure, I still think #40946 (comment) is the best fix; I'll implement this week. |
Thanks a lot, @jseyfried ❤️ |
After rust-lang#43252 is merged, building stage0 libcore with -i (--incremental) flag will cause 17 "Quasi-quoting might make incremental compilation very inefficient: NtExpr(..)" warnings, as in rust-lang#40946. Fixing the warning in rust-lang#40946 will take 12 weeks from now to make into the next stage0, so it is quicker to workaround it in libcore instead.
…n-rustbuild, r=alexcrichton Workaround "Quasi-quoting is inefficient" warning in incremental rustbuild introduced in rust-lang#43252. After rust-lang#43252 is merged, building stage0 libcore with `-i` (`--incremental`) flag will cause 17 "Quasi-quoting might make incremental compilation very inefficient: NtExpr(..)" warnings, as in rust-lang#40946. ``` warning: Quasi-quoting might make incremental compilation very inefficient: NtExpr(..) --> src/libcore/default.rs:133:21 | 133 | #[doc = $doc] | ^^^^ ... 139 | default_impl! { (), (), "Returns the default value of `()`" } | ------------------------------------------------------------- in this macro invocation (× 17) ``` True fix for rust-lang#40946 will take at least 12 weeks from now to make into the next stage0, so it is quicker to workaround it in libcore instead. cc @vbrandl @jseyfried
@jseyfried any updates on status of this? |
I've made a PR for this at #44601, although @jseyfried if that's not at all what you were thinking, just let me know! |
Right now the HIR contains raw `syntax::ast::Attribute` structure but nowadays these can contain arbitrary tokens. One variant of the `Token` enum is an "interpolated" token which basically means to shove all the tokens for a nonterminal in this position. A "nonterminal" in this case is roughly analagous to a macro argument: macro_rules! foo { ($a:expr) => { // $a is a nonterminal as an expression } } Currently nonterminals contain namely items and expressions, and this poses a problem for incremental compilation! With incremental we want a stable hash of all HIR items, but this means we may transitively need a stable hash *of the entire AST*, which is certainly not stable w/ node ids and whatnot. Hence today there's a "bug" where the "stable hash" of an AST is just the raw hash value of the AST, and this only arises with interpolated nonterminals. The downside of this approach, however, is that a bunch of errors get spewed out during compilation about how this isn't a great idea. This PR is focused at fixing these warnings, basically deleting them from the compiler. The implementation here is to alter attributes as they're lowered from the AST to HIR, expanding all nonterminals in-place as we see them. This code for expanding a nonterminal to a token stream already exists for the `proc_macro` crate, so we basically just reuse the same implementation there. After this PR it's considered a bug to have an `Interpolated` token and hence the stable hash implementation simply uses `bug!` in this location. Closes rust-lang#40946
rustc: Forbid interpolated tokens in the HIR Right now the HIR contains raw `syntax::ast::Attribute` structure but nowadays these can contain arbitrary tokens. One variant of the `Token` enum is an "interpolated" token which basically means to shove all the tokens for a nonterminal in this position. A "nonterminal" in this case is roughly analagous to a macro argument: macro_rules! foo { ($a:expr) => { // $a is a nonterminal as an expression } } Currently nonterminals contain namely items and expressions, and this poses a problem for incremental compilation! With incremental we want a stable hash of all HIR items, but this means we may transitively need a stable hash *of the entire AST*, which is certainly not stable w/ node ids and whatnot. Hence today there's a "bug" where the "stable hash" of an AST is just the raw hash value of the AST, and this only arises with interpolated nonterminals. The downside of this approach, however, is that a bunch of errors get spewed out during compilation about how this isn't a great idea. This PR is focused at fixing these warnings, basically deleting them from the compiler. The implementation here is to alter attributes as they're lowered from the AST to HIR, expanding all nonterminals in-place as we see them. This code for expanding a nonterminal to a token stream already exists for the `proc_macro` crate, so we basically just reuse the same implementation there. After this PR it's considered a bug to have an `Interpolated` token and hence the stable hash implementation simply uses `bug!` in this location. Closes #40946
I have a macro like this:
When I use it, I get the warning in the title twice for every generated functions. When I move things into one crate to avoid "note: this error originates in a macro outside of the current crate", the span of the warning is on
$proc_macro_name
in#[proc_macro_derive($proc_macro_name)]
.Steps to reproduce: run
CARGO_INCREMENTAL=1 cargo +nightly build -p cssparser-macros
in https://github.com/servo/rust-cssparser/.I don’t understand this warning and what I can do about it. What does quasi-quoting mean in this context? How bad is the inefficiency really? Is it possible to fix it while keeping this macro’s flexibility?
CC @michaelwoerister and @nikomatsakis for #37787 that added this warning.
The text was updated successfully, but these errors were encountered: