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

Trying to address an incremental compilation issues #126409

Merged
merged 2 commits into from
Jun 20, 2024

Conversation

pacak
Copy link
Contributor

@pacak pacak commented Jun 13, 2024

This pull request contains two independent changes, one makes it so when try_force_from_dep_node fails to recover a query - it marks the node as "red" instead of "green" and the second one makes Debug impl for DepNode less panicky if it encounters something from the previous compilation that doesn't map to anything in the current one.

I'm not 100% confident that this is the correct approach, but so far I managed to find a bunch of comments suggesting that some things are allowed to fail in a certain way and changes I made are allowing for those things to fail this way and it fixes all the small reproducers I managed to find.

Compilation panic this pull request avoids is caused by an automatically generated code on an associated type and it is not happening if something else marks it as outdated first (or close like that, but scenario is quite obscure).

Fixes #107226
Fixes #125367

@rustbot
Copy link
Collaborator

rustbot commented Jun 13, 2024

r? @michaelwoerister

rustbot has assigned @michaelwoerister.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 13, 2024
@michaelwoerister
Copy link
Member

Thanks for the PR, @pacak! I'll take a look asap.

@pacak
Copy link
Contributor Author

pacak commented Jun 13, 2024

Looking at https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+label%3AA-incr-comp - I think this pull request should help to close quite a few of open incremental compilation issues. I'll go though the list later.

@michaelwoerister
Copy link
Member

The try_force_from_dep_node issue definitely looks like a bug that has been introduced in the commit that you point to. That's an awesome find, @pacak! Thanks for investigating this.

I'm wondering if there is an obvious way to write a test for this.

@michaelwoerister
Copy link
Member

Your test case from #107226 (comment) seems good to add.

Making the DefPathHash -> (Local)DefId mappings return an Option seems good, especially with respect to not crashing the DepNode debug impl.

I'm wondering about some of the error stack traces though, e.g. here. Normally, we should not encounter a removed DefPathHash during red-green-marking because at that point we should have come upon a red node signifying the removal and thus stopped going any further. But in these backtraces we do encounter these nodes and the query traces all have something with trait-solving in them. Trait-solving is the only area where we do manual dependency tracking and I'm wondering if this points to a bug in that manual tracking or if gracefully failing to reconstruct the dep-node is the valid way to handle this.

@pacak
Copy link
Contributor Author

pacak commented Jun 17, 2024 via email

@michaelwoerister
Copy link
Member

but not having random panic when you try to print stuff makes sense.

Agreed 🙂

The way it is implemented currently try_force_from_dep_node returns true
as long as there's a function to force the query. It wasn't this way
from the beginning, earlier version was producing forcing result and it
was changed in rust-lang#89978, I couldn't
find any comments addressing this change.

One way it can fail is by failing to recover the query in
DepNodeParams::recover - when we are trying to query something that no
longer exists in the current environment
@pacak
Copy link
Contributor Author

pacak commented Jun 19, 2024

I rebased on top of master, addressed your suggestions to naming/comments, added a test and confirmed that the test fails before changes to try_force_from_dep_node and passes after.

At some point I'll look into requests in trait solving code, but it might take time.

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.

Thank you, @pacak, this is a great find! Would you mind adding the doc comment suggested below? Then we can merge this.

compiler/rustc_hir/src/definitions.rs Show resolved Hide resolved
@michaelwoerister
Copy link
Member

At some point I'll look into requests in trait solving code, but it might take time.

Thank you! That would be great. Please ping me when you do so.

local_def_path_hash_to_def_id is used by Debug impl for DepNode and it
looks for DefPathHash inside the current compilation. During incremental
compilation we are going through nodes that belong to a previous
compilation and might not be present and a simple attempt to print such
node with tracing::debug (try_mark_parent_green does it for example)
results in a otherwise avoidable panic

Panic was added in rust-lang#82183,
specifically in 2b60338, with a comment "We only use this mapping for
cases where we know that it must succeed.", but I'm not sure if this
property holds when we traverse nodes from the old compilation in order
to figure out if they are valid or not
@pacak
Copy link
Contributor Author

pacak commented Jun 19, 2024

Would you mind adding the doc comment suggested below? Then we can merge this.

Done. I believe this pull request should close a lot of existing incremental compilation tickets, I listed two of them but there's more and they don't have reproducers so I wasn't able to test them. Do you think they can be closed as well? I don't have a concrete list, but going though tickets labeled with incremental compilation ICEs and looking at stack traces shows them.

Thank you! That would be great. Please ping me when you do so.

Sure.

@michaelwoerister
Copy link
Member

Do you think they can be closed as well?

Let's merge the PR and once it is in nightly, ask for confirmation on the respective issues.

@michaelwoerister
Copy link
Member

Let's not roll this up, for better bisectability.
@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Jun 20, 2024

📌 Commit 12f8d12 has been approved by michaelwoerister

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 Jun 20, 2024
@bors
Copy link
Contributor

bors commented Jun 20, 2024

⌛ Testing commit 12f8d12 with merge 1d96de2...

@bors
Copy link
Contributor

bors commented Jun 20, 2024

☀️ Test successful - checks-actions
Approved by: michaelwoerister
Pushing 1d96de2 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 20, 2024
@bors bors merged commit 1d96de2 into rust-lang:master Jun 20, 2024
7 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jun 20, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1d96de2): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.3% [-0.4%, -0.2%] 21
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.2%] 15
All ❌✅ (primary) -0.3% [-0.4%, -0.2%] 21

Max RSS (memory usage)

Results (primary 3.0%, secondary 3.5%)

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.

mean range count
Regressions ❌
(primary)
3.0% [2.2%, 4.1%] 3
Regressions ❌
(secondary)
3.5% [3.5%, 3.5%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.0% [2.2%, 4.1%] 3

Cycles

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

Binary size

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

Bootstrap: 690.663s -> 691.418s (0.11%)
Artifact size: 323.78 MiB -> 323.81 MiB (0.01%)

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) 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
5 participants