-
Notifications
You must be signed in to change notification settings - Fork 13.5k
mbe: Defer checks for compile_error!
until reporting an unused macro rule
#143416
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
Conversation
rustbot has assigned @compiler-errors. Use |
As a potential added improvement, it might make sense to change |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
mbe: Defer checks for `compile_error!` until reporting an unused macro rule The current MBE parser checks rules at initial parse time to see if their RHS has `compile_error!` in it, and returns a list of rule indexes and LHS spans that don't map to `compile_error!`, for use in unused macro rule checking. Instead, have the unused macro rule reporting ask the macro for the rule to report, and let the macro check at that time. That avoids checking rules unless they're unused. In the process, refactor the data structure used to store macro rules, to group the LHS and RHS (and LHS span) of each rule together, and refactor the unused rule tracking to only track rule indexes. This builds atop a couple of minor MBE refactors. I would suggest reviewing commit-by-commit. This PR builds atop the fix for #143408 to avoid conflicts.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
9c9bed5
to
d6422f8
Compare
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
mbe: Defer checks for `compile_error!` until reporting an unused macro rule The current MBE parser checks rules at initial parse time to see if their RHS has `compile_error!` in it, and returns a list of rule indexes and LHS spans that don't map to `compile_error!`, for use in unused macro rule checking. Instead, have the unused macro rule reporting ask the macro for the rule to report, and let the macro check at that time. That avoids checking rules unless they're unused. In the process, refactor the data structure used to store macro rules, to group the LHS and RHS (and LHS span) of each rule together, and refactor the unused rule tracking to only track rule indexes. This builds atop a couple of minor MBE refactors. I would suggest reviewing commit-by-commit. This PR builds atop the fix for #143408 to avoid conflicts.
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (0d199d4): comparison URL. Overall result: ✅ improvements - no action neededBenchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf. @bors rollup=never Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (secondary -6.0%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary -4.4%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 461.827s -> 462.538s (0.15%) |
@bors rollup |
mbe: Change `unused_macro_rules` to a `DenseBitSet` Now that it only contains indexes, and no other information, a bitset provides a more compact and simpler representation. This builds on <#143416>. Only the last commit is new.
Rather than a `bool` that's `true` for the LHS and `false` for the RHS, use a self-documenting enum.
d6422f8
to
3c1559c
Compare
The parser repeatedly invokes the `parse` function, constructing a one-entry vector, and assuming that the return value will be a one-entry vector. Add a helper for that case. This will simplify adding additional callers, and put all the logic in one place to allow potential future simplification of the one-TT case.
…o rule The MBE parser checks rules at initial parse time to see if their RHS has `compile_error!` in it, and returns a list of rule indexes and LHS spans that don't map to `compile_error!`, for use in unused macro rule checking. Instead, have the unused macro rule reporting ask the macro for the rule to report, and let the macro check at that time. That avoids checking rules unless they're unused. In the process, refactor the data structure used to store macro rules, to group the LHS and RHS (and LHS span) of each rule together, and refactor the unused rule tracking to only track rule indexes. This ends up being a net simplification, and reduction in code size.
3c1559c
to
63cfb3a
Compare
@bors r+ |
Rollup of 6 pull requests Successful merges: - #143416 (mbe: Defer checks for `compile_error!` until reporting an unused macro rule) - #143470 (std: sys: net: uefi: tcp4: Implement read) - #143477 (use `is_multiple_of` and `div_ceil`) - #143484 (distinguish the duplicate item of rpitit) - #143493 (tidy: use --bless for tidy spellcheck instead of spellcheck:fix) - #143504 (compiletest: print slightly more information on fs::write failure) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #143416 - joshtriplett:mbe-simplifications, r=nnethercote mbe: Defer checks for `compile_error!` until reporting an unused macro rule The current MBE parser checks rules at initial parse time to see if their RHS has `compile_error!` in it, and returns a list of rule indexes and LHS spans that don't map to `compile_error!`, for use in unused macro rule checking. Instead, have the unused macro rule reporting ask the macro for the rule to report, and let the macro check at that time. That avoids checking rules unless they're unused. In the process, refactor the data structure used to store macro rules, to group the LHS and RHS (and LHS span) of each rule together, and refactor the unused rule tracking to only track rule indexes. This builds atop a couple of minor MBE refactors. I would suggest reviewing commit-by-commit. The overall result is a further simplification of the macro code.
…et, r=lqd mbe: Change `unused_macro_rules` to a `DenseBitSet` Now that it only contains indexes, and no other information, a bitset provides a more compact and simpler representation. This builds on <rust-lang#143416>. Only the last commit is new.
@@ -348,6 +348,10 @@ pub trait TTMacroExpander { | |||
span: Span, | |||
input: TokenStream, | |||
) -> MacroExpanderResult<'cx>; | |||
|
|||
fn get_unused_rule(&self, _rule_i: usize) -> Option<(&Ident, Span)> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This trait isn't supposed to know anything about rules or other ways to implement a macro, only about the macro's expander function.
It would probably be better to downcast from dyn TTMacroExpander (+ Any)
to MacroRulesMacroExpander
in check_unused_macros
and extract the necessary data directly if the downcast succeeds.
Or just revert the change, it doesn't actually bring perf benefits, but complicates the logic.
The current MBE parser checks rules at initial parse time to see if their RHS has
compile_error!
in it, and returns a list of rule indexes and LHS spans that don't map tocompile_error!
, for use in unused macro rule checking.Instead, have the unused macro rule reporting ask the macro for the rule to report, and let the macro check at that time. That avoids checking rules unless they're unused.
In the process, refactor the data structure used to store macro rules, to group the LHS and RHS (and LHS span) of each rule together, and refactor the unused rule tracking to only track rule indexes.
This builds atop a couple of minor MBE refactors. I would suggest reviewing commit-by-commit.
The overall result is a further simplification of the macro code.