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

Move DepKind and query TLS to rustc_query_system #86038

Closed
wants to merge 5 commits into from

Conversation

cjgillot
Copy link
Contributor

@cjgillot cjgillot commented Jun 5, 2021

r? @ghost

@cjgillot
Copy link
Contributor Author

cjgillot commented Jun 5, 2021

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 5, 2021
@bors
Copy link
Contributor

bors commented Jun 5, 2021

⌛ Trying commit 84a156cb46350ea4ca35884c4a910b62343f0677 with merge b1ce53c0cc21a9301621cb4076f77bf3ec601d7b...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jun 5, 2021

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

@rust-timer
Copy link
Collaborator

Queued b1ce53c0cc21a9301621cb4076f77bf3ec601d7b with parent 9104c89, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (b1ce53c0cc21a9301621cb4076f77bf3ec601d7b): 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
@rustbot label: +S-waiting-on-review -S-waiting-on-perf

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 6, 2021
@mati865
Copy link
Contributor

mati865 commented Jun 6, 2021

31% diesel-doc regression is red herring: #85993 (comment)

@@ -28,12 +28,6 @@ pub struct ImplicitCtxt<'a> {
task_deps: Option<&'a Lock<TaskDeps>>,
Copy link
Member

@bjorn3 bjorn3 Jul 1, 2021

Choose a reason for hiding this comment

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

Could these Options be removed and instead clear the ImplicitContext in the tls when they would be None?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so. The implicitctxt is still required to detect cycles and to print query stack even when the dependencies are ignored.

Copy link
Member

Choose a reason for hiding this comment

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

And the other fields? At least one can be made non-optional, right? I don't see what the difference between no implicitctxt and an empty implicitctxt would be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, query should not need to be an option.

@cjgillot cjgillot force-pushed the tls branch 3 times, most recently from a5bfc56 to a91b82e Compare July 6, 2021 18:51
@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 31, 2021
@JohnCSimon
Copy link
Member

Ping from triage:
@cjgillot assigning back to author to resolve merge conflicts

@camelid
Copy link
Member

camelid commented Aug 20, 2021

triage: Is this PR experimental? If so, you can replace S-waiting-on-author with S-experimental to prevent it from being triaged.

@rust-lang rust-lang deleted a comment from bors Aug 21, 2021
@rust-lang rust-lang deleted a comment from bors Aug 21, 2021
@rust-lang rust-lang deleted a comment from bors Aug 21, 2021
@cjgillot
Copy link
Contributor Author

I finally got back to this PR.

In this new version, I stop moving the macros to rustc_query_system, and side with @Zoxc's suggestion to make DepKind a newtype over u16. This may be useful if we want to define queries in crates other than rustc_middle one day.

The global pointer to GlobalCtxt is now a thread-local *const GlobalCtxt<'static>. Since all the jobs in the compilation thread pool have the same GlobalCtxt, this should not trigger any issue, while at the same time allowing to run two instances of rustc in different threads as asked by @bjorn3.

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 16, 2022
@bors
Copy link
Contributor

bors commented Apr 16, 2022

⌛ Trying commit 4387490 with merge 0794d7f4f502d8a0e9a4a71f7669e4adda756b81...

@bors
Copy link
Contributor

bors commented Apr 16, 2022

☀️ Try build successful - checks-actions
Build commit: 0794d7f4f502d8a0e9a4a71f7669e4adda756b81 (0794d7f4f502d8a0e9a4a71f7669e4adda756b81)

@rust-timer
Copy link
Collaborator

Queued 0794d7f4f502d8a0e9a4a71f7669e4adda756b81 with parent febce1f, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0794d7f4f502d8a0e9a4a71f7669e4adda756b81): comparison url.

Summary:

  • Primary benchmarks: mixed results
  • Secondary benchmarks: mixed results
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 10 21 9 35 19
mean2 1.0% 2.6% -0.4% -0.6% 0.4%
max 3.4% 8.2% -0.7% -1.6% 3.4%

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@rustbot rustbot added perf-regression Performance regression. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Apr 16, 2022
@cjgillot
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 16, 2022
@bors
Copy link
Contributor

bors commented Apr 16, 2022

⌛ Trying commit 8b8c12e with merge 8227b19194e5b9a2926d15786b99e6cc9f73389f...

@bors
Copy link
Contributor

bors commented Apr 16, 2022

☀️ Try build successful - checks-actions
Build commit: 8227b19194e5b9a2926d15786b99e6cc9f73389f (8227b19194e5b9a2926d15786b99e6cc9f73389f)

@rust-timer
Copy link
Collaborator

Queued 8227b19194e5b9a2926d15786b99e6cc9f73389f with parent 878c783, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (8227b19194e5b9a2926d15786b99e6cc9f73389f): comparison url.

Summary:

  • Primary benchmarks: mixed results
  • Secondary benchmarks: mixed results
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 4 13 28 42 32
mean2 2.0% 3.7% -0.4% -0.5% -0.1%
max 3.2% 7.9% -0.7% -0.9% 3.2%

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

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.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

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

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 17, 2022
/// query. It is updated when
/// executing a new query.
#[derive(Clone, Default)]
struct ImplicitCtxt<'a> {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should keep the tcx field as a *const (). That lets you move more of the tls module intact and the parallel compiler doesn't regress. with_opt can convert it back in rustc_middle.

You'll want to add an assertion about GlobalCtxt being Sync too, since the type is now erased from ImplicitCtxt.

// Extend the lifetime of the GlobalCtxt so the new thread can know of it.
// The current thread will not free it, it is deadlocked.
let tcx: &'static GlobalCtxt<'static> =
tls::with(|tcx| &*(*tcx as *const GlobalCtxt<'_>).cast());
Copy link
Contributor

Choose a reason for hiding this comment

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

This is incorrect since it's only set on one of Rayon's threads. The deadlock handler can be called on any thread. The current state of things is also broken to be fair.

We can not use the Rayon "Task Local Value" either, since the deadlock handler can also be called from a thread with no rustc task is running. My solution to this was to point all threads to a lock which holds the GlobalCtxt when available. It was reverted in #74969.

@Mark-Simulacrum Mark-Simulacrum removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 7, 2022
@cjgillot cjgillot closed this Aug 22, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 14, 2024
Move TLS to rustc_query_system

Revival of rust-lang#86038

r? `@ghost`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 14, 2024
Move TLS to rustc_query_system

Revival of rust-lang#86038

r? `@ghost`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 15, 2024
Move TLS to rustc_query_system

Revival of rust-lang#86038

r? `@ghost`
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) perf-regression Performance regression. 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.