-
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
Make declarative macro expansion a part of query system (cont. of #125356) #128605
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
|
Some changes occurred in src/tools/cargo cc @ehuss These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
Did a rebase, to no longer contain changes to submodules (wow rust is moving fast 🙈). |
Since you reviewed and self-assigned the original PR, I thought this would be ok/maybe a better fit than auto-assignment. Please feel free to re-/unassign if that's not the case! |
This comment has been minimized.
This comment has been minimized.
Oof, no idea where that error comes from, seems a dependency is broken/flaky? It's in stage0-checking, so can't be due to my changes yet I think? :O |
You need to revert the changes you've made to submodules in this PR. |
Thank you very much! Was a bit finicky, but I think it's correct now, the changes don't appear in the commit that had them anymore. |
There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged. You can start a rebase with the following commands:
The following commits are merge commits: |
I'm not sure what I should do with this PR. If some changes are refactorings orthogonal to #125356, then we can merge them in a separate PR before #125356 instead of on top of it (feel free to assign such a PR to me). |
Hmm, we can actually run benchmarks on this versions, since there are no CI failures anymore. |
This comment has been minimized.
This comment has been minimized.
Make declarative macro expansion a part of query system (cont. of rust-lang#125356) This is a continuation of the effort to make declarative macro expansion a part of the query system from rust-lang#125356 by `@SparrowLii.` #### Description from that PR: > This is an attempt to make the macro expansion a part of incremental compilation. > > Processing of procedural macros is difficult since they may involve interactions with the external environment. Declaring macros is a good start. > > **It is not yet possible to test the effect of this PR on incremental compilation since the new query is declared as eval_always.** #### Status of this PR: * It is rebased against a much more recent `master` commit * It contains the original commits from rust-lang#125356 (in a rebased form) * It adds the missing implementation for retrying macro matching that provides (better) error diagnostics * This was done by refactoring `rustc_expand::mbe::diagnostics::failed_to_match_macro()` to only require a `ParseSess` instead of an `ExtCtxt`. Otherwise, `ExtCtxt` would need to be in the interface of `TcxMacroExpander`, which is not possible, because `ExtCtxt` is part of `rustc_expand`, which depends on the crate that contains `TcxMacroExpander`, `rustc_middle`, and thus would introduce a circular dependency. * This refactoring moved the retrying down into the `impl TcxMacroExpander for MacroRulesMacroExpander` (this is just a change compared to the original PR, otherwise not important to know). * This PR passes `./x test tests/ui`, which produced errors before that were all due to the missing implementation of retry macro matching. * This PR does **not** yet contain changes for the open discussions from rust-lang#125356. I wanted to fix the tests first before tackling them, and I also need to figure out what the best solutions for them are. I'd welcome any help/support with this, e.g., opening up a corresponding discussion on this PR with a summary/the final decided fix if available :) In general, I'm new to working on rustc, so would be thankful for a bit more background/explanations in discussions and comments :) Thanks! :) (tangentially relevant: rust-lang#99515)
Thanks for taking a look!
I do intend to finish this, and have already started testing whether this enables incremental reuse (see futile/rust@expand1-cont...futile:rust:cache-decl-macros), and am also up to (try to) answer the questions from the other PR. ( However, I want to make sure that I'm not taking away @SparrowLii's work here, but I haven't heard back from them yet, so not sure what to do about that.
Maybe the changes in They make the module depend less on So, on the topic of incremental reuse. This will, somewhat obviously, require also making the macro arguments, a However. This will require us to somehow hash the In practice this triggered this panic when compiling rust/compiler/rustc_ast/src/token.rs Lines 1054 to 1061 in 60d1465
However! If I, instead, stable-hash the That said, I'm not sure if it might make sense to wait for #124141 here anyway, since that should (trivially) enable stable-hashing the Also ty for the perf run, hope it'll go well! :) |
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Cache declarative macro expansion on disk (for incremental comp.). Based on rust-lang#128605 ## NOTE: Don't merge yet, mostly here for CI, also rebased on top of rust-lang#128605! This PR enables on-disk caching for incremental compilation of declarative macro expansions. The base mechanism is added in rust-lang#128605, but not enabled for incremental comp. there yet. r? `@petrochenkov` since you are in the loop here, but feel free to un-/reassign.
Yes, from a brief look that's the part that can be split.
Yes, the flattening should work in the meantime. |
Finished benchmarking commit (3866917): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)Results (primary 5.6%, secondary 27.7%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary 3.0%, secondary 3.9%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 760.99s -> 762.113s (0.15%) |
Dang, but yeah, makes sense that it's a regression, since the path through the query system probably adds some overhead/instructions compared to the direct path. But ~1% on average is sadly a pretty hard hit 🙈 Let's wait what the perf results for #128747 will be, but having these results is nice to have a baseline for the caching cost. But given these regressions it probably doesn't make sense to merge this without actual re-use, either through #128747 or another approach, which then also has to show an actual performance improvement. |
@futile Thank you very much for your work. I can't spend much time on continuing the incremental compilation work for the time being due to some other work. Feel free to close #125356 if your work can replace it. (Notify me or @petrochenkov ) (I was waiting for #124141 to be finished. According to oli's opinion, using TokenStream as the query input parameter may be a better way.) |
…=petrochenkov refactor(rustc_expand::mbe): Don't require full ExtCtxt when not necessary Refactor `mbe::diagnostics::failed_to_match_macro()` to not require a full `ExtCtxt`, but only a `&ParseSess`. It hard-required the `ExtCtxt` only for a call to `cx.trace_macros_diag()`, which we move instead to the only call-site of the function. Note: This could be a potential change in observed behavior, because a call to `cx.trace_macros_diag()` now always happens after `failed_to_match_macro()` was called, where before it was only called at the end of the main return path of the function. But since `trace_macros_diag()` "flushes" out any not-yet-reported errors, it should be ok to call it for all paths, since there shouldn't be any on the non-main paths I think. However, I don't know the rest of the codebase well enough to say that with 100% confidence, but `tests/ui` still pass, which gives at least some confidence in the change. Also concretize the return type from `Box<dyn MacResult>` to `(Span, ErrorGuaranteed)`, because this function will _always_ return an error, and never any other kind of result. Was part of rust-lang#128605 and rust-lang#128747, but is a standalone refactoring. r? ``@petrochenkov``
Rollup merge of rust-lang#128798 - futile:refactor/mbe-diagnostics, r=petrochenkov refactor(rustc_expand::mbe): Don't require full ExtCtxt when not necessary Refactor `mbe::diagnostics::failed_to_match_macro()` to not require a full `ExtCtxt`, but only a `&ParseSess`. It hard-required the `ExtCtxt` only for a call to `cx.trace_macros_diag()`, which we move instead to the only call-site of the function. Note: This could be a potential change in observed behavior, because a call to `cx.trace_macros_diag()` now always happens after `failed_to_match_macro()` was called, where before it was only called at the end of the main return path of the function. But since `trace_macros_diag()` "flushes" out any not-yet-reported errors, it should be ok to call it for all paths, since there shouldn't be any on the non-main paths I think. However, I don't know the rest of the codebase well enough to say that with 100% confidence, but `tests/ui` still pass, which gives at least some confidence in the change. Also concretize the return type from `Box<dyn MacResult>` to `(Span, ErrorGuaranteed)`, because this function will _always_ return an error, and never any other kind of result. Was part of rust-lang#128605 and rust-lang#128747, but is a standalone refactoring. r? ``@petrochenkov``
This is a continuation of the effort to make declarative macro expansion a part of the query system from #125356 by @SparrowLii.
Description from that PR:
Status of this PR:
master
commitrustc_expand::mbe::diagnostics::failed_to_match_macro()
to only require aParseSess
instead of anExtCtxt
. Otherwise,ExtCtxt
would need to be in the interface ofTcxMacroExpander
, which is not possible, becauseExtCtxt
is part ofrustc_expand
, which depends on the crate that containsTcxMacroExpander
,rustc_middle
, and thus would introduce a circular dependency.impl TcxMacroExpander for MacroRulesMacroExpander
(this is just a change compared to the original PR, otherwise not important to know)../x test tests/ui
, which produced errors before that were all due to the missing implementation of retry macro matching.In general, I'm new to working on rustc, so would be thankful for a bit more background/explanations in discussions and comments :) Thanks! :)
(tangentially relevant: #99515)