Skip to content
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

Further simplify the macros generated by rustc_queries #101173

Merged
merged 4 commits into from
Sep 15, 2022

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Aug 29, 2022

This doesn't actually move anything outside the macros, but it makes them simpler to read.

  • Add a new rustc_query_names macro. This allows a much simpler syntax for the matchers in the macros passed to it as a callback.
  • Convert define_dep_nodes and alloc_once to use rustc_query_names. This is possible because they only use the names
    (despite the quite complicated matchers in define_dep_nodes, none of the other arguments are used).
  • Get rid of rustc_dep_node_append.

r? @cjgillot

@jyn514 jyn514 added the A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) label Aug 29, 2022
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 29, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 29, 2022
@jyn514 jyn514 added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label Aug 29, 2022
[$($attrs:tt)*]
$variant:ident $(( $tuple_arg_ty:ty $(,)? ))*
,)*
$( $( #[$attr:meta] )* $variant:ident, )+
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lose the documentation for variants defined using the proc-macro, but get some for the nodes defined in this file. Shouldn't we have documentation for all or nothing?

Copy link
Member Author

@jyn514 jyn514 Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, excellent catch. Yes, I forgot that previously attrs could include doc-comments, I agree we should keep those.

I almost wonder if we should remove rustc_query_names altogether and force everyone to match on the tokens for rustc_query_append. It's not that much extra work and it allows getting rid of another macro, and makes it easy to extend all the callsites to use the additional info in the future if they need it.

(Just as a note, we weren't including the doc-comments even before my change, we would match on them and then immediately discard them.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having just rustc_query_append seems great. We'll just need a bit of creativity to give a signature to the 5 extra dep-nodes. Actually, could we declare those 5 extra dep-nodes inside rustc_middle::query directly, and get rid of the _append part of the macro?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think I can do both those things :) and it should be possible to get rid of rustc_cached_queries at the same time, since we can match on the cache modifier in the macro rather than requiring it be done by the proc-macro.

Copy link
Member Author

@jyn514 jyn514 Sep 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to avoid declaring the 5 dep-nodes in rustc_middle::query for now; ignoring the snake_case warning is harder than I expected (at least until #101512 is fixed), and it's not that hard to add the extra matchers in the other macros. I'll try and follow up on that later.

Copy link
Member Author

@jyn514 jyn514 Sep 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got rid of rustc_query_names and rustc_cached_queries. I think it might be possible to remove rustc_query_description after #101307 is merged, using (cache = $expr) and (desc = $fmt_str, $($arg),*).

@jyn514 jyn514 force-pushed the simplify-macro-arguments branch 3 times, most recently from 5210df9 to 64aa648 Compare September 7, 2022 02:37
- Add a new `rustc_query_names` macro. This allows a much simpler syntax for the matchers in the macros passed to it as a callback.
- Convert `define_dep_nodes` and `alloc_once` to use `rustc_query_names`. This is possible because they only use the names
  (despite the quite complicated matchers in `define_dep_nodes`, none of the other arguments are used).
- Get rid of `rustc_dep_node_append`.
@rust-log-analyzer

This comment has been minimized.

… macro

We can avoid these by adding slightly more information to `rustc_query_append` instead.
@cjgillot
Copy link
Contributor

@bors try @rust-timer perf

@bors
Copy link
Contributor

bors commented Sep 14, 2022

⌛ Trying commit cb2949e with merge 39c01438377c09997b8cb33020a9c4636ea8d7f8...

@bors
Copy link
Contributor

bors commented Sep 14, 2022

☀️ Try build successful - checks-actions
Build commit: 39c01438377c09997b8cb33020a9c4636ea8d7f8 (39c01438377c09997b8cb33020a9c4636ea8d7f8)

@jyn514
Copy link
Member Author

jyn514 commented Sep 14, 2022

@rust-timer build 39c01438377c09997b8cb33020a9c4636ea8d7f8

@rust-timer
Copy link
Collaborator

Queued 39c01438377c09997b8cb33020a9c4636ea8d7f8 with parent c97922d, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (39c01438377c09997b8cb33020a9c4636ea8d7f8): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking 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.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

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.

mean1 range count2
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.8% [3.8%, 3.8%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results

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.

mean1 range count2
Regressions ❌
(primary)
11.7% [11.7%, 11.7%] 1
Regressions ❌
(secondary)
2.7% [2.7%, 2.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.7% [-3.0%, -2.3%] 4
All ❌✅ (primary) 11.7% [11.7%, 11.7%] 1

Footnotes

  1. the arithmetic mean of the percent change 2

  2. number of relevant changes 2

@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Sep 15, 2022

📌 Commit cb2949e has been approved by cjgillot

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 15, 2022
@bors
Copy link
Contributor

bors commented Sep 15, 2022

⌛ Testing commit cb2949e with merge 294f0ee...

@bors
Copy link
Contributor

bors commented Sep 15, 2022

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 294f0ee to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 15, 2022
@bors bors merged commit 294f0ee into rust-lang:master Sep 15, 2022
@rustbot rustbot added this to the 1.65.0 milestone Sep 15, 2022
@bors bors mentioned this pull request Sep 15, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (294f0ee): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

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.

mean1 range count2
Regressions ❌
(primary)
1.3% [1.2%, 1.3%] 2
Regressions ❌
(secondary)
1.8% [1.5%, 2.1%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.9% [-3.9%, -3.9%] 1
All ❌✅ (primary) 1.3% [1.2%, 1.3%] 2

Cycles

Results

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.

mean1 range count2
Regressions ❌
(primary)
6.7% [2.1%, 11.3%] 2
Regressions ❌
(secondary)
2.1% [2.1%, 2.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 6.7% [2.1%, 11.3%] 2

Footnotes

  1. the arithmetic mean of the percent change 2

  2. number of relevant changes 2

@jyn514 jyn514 deleted the simplify-macro-arguments branch September 15, 2022 16:19
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 26, 2022
Use function pointers instead of macro-unrolled loops in rustc_query_impl

By making these standalone functions, we
a) allow making them extensible in the future with a new `QueryStruct`
b) greatly decrease the amount of code in each individual function, avoiding exponential blowup in llvm

Helps with rust-lang#96524. Based on rust-lang#101173; only the last commit is relevant.

r? `@cjgillot`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) C-cleanup Category: PRs that clean code up or issues documenting cleanup. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants