Skip to content

Use a single function for query manipulations - #77833

Closed
cjgillot wants to merge 10 commits into
rust-lang:masterfrom
cjgillot:query-merge
Closed

Use a single function for query manipulations#77833
cjgillot wants to merge 10 commits into
rust-lang:masterfrom
cjgillot:query-merge

Conversation

@cjgillot

@cjgillotcjgillot commented Oct 11, 2020

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

r? @varkor

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

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 11, 2020
@jyn514jyn514 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
Copy Markdown
Contributor

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
Copy Markdown
Collaborator

Awaiting bors try build completion

@bors

bors commented Oct 12, 2020

Copy link
Copy Markdown
Collaborator

⌛ Trying commit fd60635 with merge f8ec1548e1d547c63153b5e662eda2db7306b2f2...

@bors

bors commented Oct 12, 2020

Copy link
Copy Markdown
Collaborator

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

@rust-timer

Copy link
Copy Markdown
Collaborator

Queued f8ec1548e1d547c63153b5e662eda2db7306b2f2 with parent 63962f0, future comparison URL.

@rust-timer

Copy link
Copy Markdown
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

@Julian-WollersbergerJulian-Wollersberger left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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.

@Julian-WollersbergerJulian-WollersbergerOct 13, 2020

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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?

query: &QueryVtable<CTX, K, V>,
) -> (V, DepNodeIndex)
where
C: QueryCache,

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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

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

bors commented Oct 22, 2020

Copy link
Copy Markdown
Collaborator

☔ 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

@varkorvarkor removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 23, 2020
@varkorvarkor 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

bors commented Oct 25, 2020

Copy link
Copy Markdown
Collaborator

☔ 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
Copy Markdown
ContributorAuthor

Closed in favor of #78780.

@cjgillot
cjgillot deleted the query-merge branch September 21, 2021 16:11
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-query-systemArea: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html)C-cleanupCategory: PRs that clean code up or issues documenting cleanup.S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.T-compilerRelevant 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

@cjgillot@rust-highfive@Xanewok@rust-timer@bors@Julian-Wollersberger@varkor@jyn514