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

Use a single function for query manipulations #77833

Closed
wants to merge 10 commits into from

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Oct 11, 2020

There are three ways to invoke a query: get the value, ensure it runs, or have it automatically forced.

The three corresponding methods are merged into a single point of entry.
The goal is to increase the code sharing between the three cases.

@rust-highfive
Copy link
Collaborator

r? @varkor

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 11, 2020
@jyn514 jyn514 added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 11, 2020
@Xanewok
Copy link
Member

Xanewok commented Oct 12, 2020

I vaguely recall that this may have affected performance (e.g. see careful #[inline(never)] and #[inline(always)] annotations), let's see if this has any impact:

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Oct 12, 2020

⌛ Trying commit fd60635 with merge f8ec1548e1d547c63153b5e662eda2db7306b2f2...

@bors
Copy link
Contributor

bors commented Oct 12, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: f8ec1548e1d547c63153b5e662eda2db7306b2f2 (f8ec1548e1d547c63153b5e662eda2db7306b2f2)

@rust-timer
Copy link
Collaborator

Queued f8ec1548e1d547c63153b5e662eda2db7306b2f2 with parent 63962f0, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (f8ec1548e1d547c63153b5e662eda2db7306b2f2): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never

Copy link
Contributor

@Julian-Wollersberger Julian-Wollersberger left a comment

Choose a reason for hiding this comment

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

This refactoring should improve bootstrap times a bit, because it removes 216 000 llvm-lines (-1%).

Before:  Lines   Copies         Function name
--------------   ------         -------------
20218434 (100%)  600060 (100%)  (TOTAL)
  457651 (2.3%)     414 (0.1%)  rustc_query_system::query::plumbing::get_query_impl::{{closure}}
  168207 (0.8%)     354 (0.1%)  rustc_query_system::query::plumbing::force_query_impl::{{closure}}
   95634 (0.5%)     207 (0.0%)  rustc_query_system::query::plumbing::incremental_verify_ich
   87688 (0.4%)    4335 (0.7%)  core::ops::function::FnOnce::call_once
   75830 (0.4%)     621 (0.1%)  <rustc_query_system::query::caches::DefaultCache<K,V> as rustc_query_system::query::caches::QueryCache>::iter
   69233 (0.3%)     207 (0.0%)  rustc_query_system::query::plumbing::load_from_disk_and_cache_in_memory
   41047 (0.2%)     207 (0.0%)  rustc_query_system::query::plumbing::get_query_impl

After:  Lines    Copies         Function name
-------------    ------         -------------
20001669 (100%)  595297 (100%)  (TOTAL)
  434107 (2.2%)     354 (0.1%)  rustc_query_system::query::plumbing::call_query_impl::{{closure}}
   85516 (0.4%)    4257 (0.7%)  core::ops::function::FnOnce::call_once
   81774 (0.4%)     177 (0.0%)  rustc_query_system::query::plumbing::incremental_verify_ich
   75830 (0.4%)     621 (0.1%)  <rustc_query_system::query::caches::DefaultCache<K,V> as rustc_query_system::query::caches::QueryCache>::iter
   59176 (0.3%)     177 (0.0%)  rustc_query_system::query::plumbing::load_from_disk_and_cache_in_memory
   47042 (0.2%)     177 (0.0%)  rustc_query_system::query::plumbing::call_query_impl

(Omitted all entries from other crates; mostly core, alloc and hashbrown.)

key: query_keys::$name<$tcx>,
caller: QueryCaller<DepKind>,
) -> Option<<queries::$name<$tcx> as QueryConfig<TyCtxt<$tcx>>>::Stored> {
call_query::<queries::$name<'_>, _>(tcx, span, key, caller)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this wrapper needed? Can't the three places where this is used call call_query::<queries::$name<'_>, _>(tcx, span, key, caller)directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The point is to monomorphize call_query only once for each query. The easiest way is to call it through a monomorphic function.

Copy link
Contributor

@Julian-Wollersberger Julian-Wollersberger Oct 13, 2020

Choose a reason for hiding this comment

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

I just tested removing the wrapper. It removed another 39 022 llvm-lines.
I guess call_query is only monomorphized once for each query anyway, even though it is called from multiple places.

Edit: Created cjgillot#1

) where
C: QueryCache,
C::Key: Eq + Clone + crate::dep_graph::DepNodeParams<CTX>,
fn ensure_query_impl<CTX, K, V>(tcx: CTX, key: &K, query: &QueryVtable<CTX, K, V>) -> bool
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment what this bool means?

where
C: QueryCache,
Copy link
Contributor

Choose a reason for hiding this comment

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

Glad to see this C: QueryCache clause removed ^^
It is annoying when trying to make things dyn.

@cjgillot
Copy link
Contributor Author

LLVM-lines was the target, but perf is bad. Bootstrap times are not a win either. This definitely needs more work.

@jyn514 jyn514 added the A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) label Oct 12, 2020
@bors
Copy link
Contributor

bors commented Oct 22, 2020

☔ The latest upstream changes (presumably #77871) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@varkor varkor removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 23, 2020
@varkor varkor added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 23, 2020
@bors
Copy link
Contributor

bors commented Oct 25, 2020

☔ The latest upstream changes (presumably #78334) made this pull request unmergeable. Please resolve the merge conflicts.

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@cjgillot
Copy link
Contributor Author

Closed in favor of #78780.

@cjgillot cjgillot closed this Nov 20, 2020
@cjgillot cjgillot deleted the query-merge branch September 21, 2021 16:11
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. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

8 participants