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

Construct query job latches on-demand #68693

Merged
merged 4 commits into from
Feb 14, 2020
Merged

Conversation

Zoxc
Copy link
Contributor

@Zoxc Zoxc commented Jan 31, 2020

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 31, 2020
@Zoxc
Copy link
Contributor Author

Zoxc commented Jan 31, 2020

@bors try

@bors
Copy link
Contributor

bors commented Jan 31, 2020

⌛ Trying commit aa0abc80119e8bb3b5f2f104b17b19a289a95121 with merge 38be9357b39a77cd206eab30844c05a019dc72f3...

@Zoxc
Copy link
Contributor Author

Zoxc commented Jan 31, 2020

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Jan 31, 2020

⌛ Trying commit 8ecd740 with merge 7ccaf1c...

bors added a commit that referenced this pull request Jan 31, 2020
[WIP] Construct query job latches on-demand

r? @michaelwoerister
@rust-highfive
Copy link
Collaborator

The job dist-x86_64-linux-alt of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2020-01-31T07:08:22.4499390Z    Compiling fmt_macros v0.0.0 (/checkout/src/libfmt_macros)
2020-01-31T07:08:24.3231932Z    Compiling rustc_session v0.0.0 (/checkout/src/librustc_session)
2020-01-31T07:08:46.3196047Z    Compiling rustc_hir v0.0.0 (/checkout/src/librustc_hir)
2020-01-31T07:09:01.1971460Z    Compiling rustc_parse v0.0.0 (/checkout/src/librustc_parse)
2020-01-31T07:09:16.9765290Z error[E0412]: cannot find type `PhantomData` in this scope
2020-01-31T07:09:16.9766448Z   --> src/librustc/ty/query/job.rs:85:12
2020-01-31T07:09:16.9766929Z    |
2020-01-31T07:09:16.9767497Z 85 |     dummy: PhantomData<QueryLatch<'tcx>>,
2020-01-31T07:09:16.9769089Z    |
2020-01-31T07:09:16.9769703Z help: possible candidates are found in other modules, you can import them into scope
2020-01-31T07:09:16.9770184Z    |
2020-01-31T07:09:16.9770696Z 1  | use core::marker::PhantomData;
2020-01-31T07:09:16.9770696Z 1  | use core::marker::PhantomData;
2020-01-31T07:09:16.9771153Z    |
2020-01-31T07:09:16.9771937Z 1  | use std::marker::PhantomData;
2020-01-31T07:09:16.9772418Z    |
2020-01-31T07:09:16.9775936Z 
2020-01-31T07:09:16.9987490Z error[E0425]: cannot find value `PhantomData` in this scope
2020-01-31T07:09:16.9989232Z   --> src/librustc/ty/query/job.rs:97:20
2020-01-31T07:09:16.9989746Z    |
2020-01-31T07:09:16.9990300Z 97 |             dummy: PhantomData,
2020-01-31T07:09:16.9991412Z    |
2020-01-31T07:09:16.9991989Z help: possible candidates are found in other modules, you can import them into scope
2020-01-31T07:09:16.9992443Z    |
2020-01-31T07:09:16.9992984Z 1  | use core::marker::PhantomData;
---
2020-01-31T07:09:46.2145077Z   local time: Fri Jan 31 07:09:46 UTC 2020
2020-01-31T07:09:46.9226763Z   network time: Fri, 31 Jan 2020 07:09:46 GMT
2020-01-31T07:09:46.9227114Z == end clock drift check ==
2020-01-31T07:09:47.2857182Z 
2020-01-31T07:09:47.2965292Z ##[error]Bash exited with code '1'.
2020-01-31T07:09:47.3038499Z ##[section]Starting: Checkout rust-lang/rust@try to s
2020-01-31T07:09:47.3040808Z ==============================================================================
2020-01-31T07:09:47.3040923Z Task         : Get sources
2020-01-31T07:09:47.3041019Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@bors
Copy link
Contributor

bors commented Jan 31, 2020

☀️ Try build successful - checks-azure
Build commit: 7ccaf1c (7ccaf1cdfde8cd513f14604879722adc5fb6dee8)

@rust-timer
Copy link
Collaborator

Queued 7ccaf1c with parent 266ecd6, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit 7ccaf1c, comparison URL.

@Zoxc
Copy link
Contributor Author

Zoxc commented Jan 31, 2020

The idea here is to avoid creating a Lrc<QueryJob> each time we want to execute a query and instead create a QueryLatch = Lrc<Mutex<QueryLatchInfo<'tcx>>> when we actually want to wait for a query.

A QueryJob is now stored inline in the active map and contains a Option<QueryLatch> which is created on demand. This way we avoid the allocation and the atomic operations when there's no waiters on the query.

We can no longer refer to queries using Lrc<QueryJob> which is a small type. Using Query<'tcx> is too expensive as that is quite big. Instead QueryToken is introduced which is a pointer to a stack value which uniquely identifies an active query execution. A QueryToken is stored for each running query in the active map. This allows you to look up information for a token by looking at all the active maps. While this is expensive, it only happens on cycle errors and ICEs.

@Zoxc Zoxc changed the title [WIP] Construct query job latches on-demand Construct query job latches on-demand Jan 31, 2020
@Zoxc
Copy link
Contributor Author

Zoxc commented Jan 31, 2020

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Jan 31, 2020

⌛ Trying commit f52b65c85a861033e46576cf9853683c6ba47ff8 with merge 89c6ff362254e2735d7304447a89dca0f130da31...

@bors
Copy link
Contributor

bors commented Feb 1, 2020

☀️ Try build successful - checks-azure
Build commit: 89c6ff362254e2735d7304447a89dca0f130da31 (89c6ff362254e2735d7304447a89dca0f130da31)

@rust-timer
Copy link
Collaborator

Queued 89c6ff362254e2735d7304447a89dca0f130da31 with parent cd1ef39, future comparison URL.

@michaelwoerister
Copy link
Member

The performance numbers look good. I'll try to make time for reviewing this some time this or next week.

Copy link
Member

@michaelwoerister michaelwoerister left a comment

Choose a reason for hiding this comment

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

I'm generally in favor of going forward with this. It's a good idea to move some of the more expensive operations out of the fast-path. I have one main concern that I listed below.

src/librustc/ty/query/job.rs Outdated Show resolved Hide resolved
@@ -139,39 +149,54 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
query_blocked_prof_timer = Some(tcx.prof.query_blocked());
}

job.clone()
// Create the id of the job we're waiting for
let id = QueryJobId {
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind creating a helper method for this? This function is already rather big.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

key: &Q::Key,
token: QueryToken,
) -> TryGetJob<'a, 'tcx, Q> {
pub(super) fn try_get(tcx: TyCtxt<'tcx>, span: Span, key: &Q::Key) -> TryGetJob<'a, 'tcx, Q> {
Copy link
Member

Choose a reason for hiding this comment

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

I like how token disappears from the function signature again.

@michaelwoerister
Copy link
Member

Thanks, @Zoxc!

@bors r+ rollup=never

(This is doing some complicated changes, let's keep it out of rollups in case it breaks anything)

@bors
Copy link
Contributor

bors commented Feb 13, 2020

📌 Commit 5206827 has been approved by michaelwoerister

@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 Feb 13, 2020
@bors
Copy link
Contributor

bors commented Feb 13, 2020

⌛ Testing commit 5206827 with merge 9503b49...

bors added a commit that referenced this pull request Feb 13, 2020
@bors
Copy link
Contributor

bors commented Feb 13, 2020

💔 Test failed - checks-azure

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

Zoxc commented Feb 13, 2020

@bors retry

@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 Feb 13, 2020
@Dylan-DPC-zz
Copy link

@bors p=1

@bors
Copy link
Contributor

bors commented Feb 14, 2020

⌛ Testing commit 5206827 with merge 21ed505...

bors added a commit that referenced this pull request Feb 14, 2020
@bors
Copy link
Contributor

bors commented Feb 14, 2020

☀️ Test successful - checks-azure
Approved by: michaelwoerister
Pushing 21ed505 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 14, 2020
@bors bors merged commit 5206827 into rust-lang:master Feb 14, 2020
@rust-highfive
Copy link
Collaborator

📣 Toolstate changed by #68693!

Tested on commit 21ed505.
Direct link to PR: #68693

💔 rustc-guide on linux: test-pass → test-fail (cc @JohnTitor @amanjeev @spastorino @mark-i-m, @rust-lang/infra).

rust-highfive added a commit to rust-lang-nursery/rust-toolstate that referenced this pull request Feb 14, 2020
Tested on commit rust-lang/rust@21ed505.
Direct link to PR: <rust-lang/rust#68693>

💔 rustc-guide on linux: test-pass → test-fail (cc @JohnTitor @amanjeev @spastorino @mark-i-m, @rust-lang/infra).
@Zoxc Zoxc deleted the query-no-arc branch February 14, 2020 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants