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

Import SourceFiles from crate before decoding foreign Span #92175

Merged
merged 1 commit into from
Dec 31, 2021

Conversation

Aaron1011
Copy link
Member

Fixes #92163
Fixes #92014

When writing to the incremental cache, we encode all Spans
we encounter, regardless of whether or not their SourceFile
comes from the local crate, or from a foreign crate.

When we decode a Span, we use the StableSourceFileId we encoded
to locate the matching SourceFile in the current session. If this
id corresponds to a SourceFile from another crate, then we need to
have already imported that SourceFile into our current session.

This usually happens automatically during resolution / macro expansion,
when we try to resolve definitions from other crates. In certain cases,
however, we may try to load a Span from a transitive dependency
without having ever imported the SourceFiles from that crate, leading
to an ICE.

This PR fixes the issue by enconding the SourceFile's CrateNum
when we encode a Span. During decoding, we call imported_source_files()
when we encounter a foreign CrateNum, which ensure that all
SourceFiles from that crate are imported into the current session.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 21, 2021
@rust-highfive
Copy link
Collaborator

r? @matthewjasper

(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 Dec 21, 2021
@Aaron1011
Copy link
Member 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 Dec 21, 2021
@bors
Copy link
Contributor

bors commented Dec 21, 2021

⌛ Trying commit 694cc860db597055044b55e35e074a9f5304e8d0 with merge b03e9a396b02e7285c97d453d8c0d59c7fd4d43e...

@bors
Copy link
Contributor

bors commented Dec 21, 2021

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

@rust-timer
Copy link
Collaborator

Queued b03e9a396b02e7285c97d453d8c0d59c7fd4d43e with parent e100ec5, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b03e9a396b02e7285c97d453d8c0d59c7fd4d43e): comparison url.

Summary: This change led to very large relevant mixed results 🤷 in compiler performance.

  • Very large improvement in instruction counts (up to -14.5% on incr-full builds of webrender-wrench)
  • Large regression in instruction counts (up to 4.6% on incr-unchanged builds of tuple-stress)

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 led 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

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 22, 2021
@Aaron1011
Copy link
Member Author

I think the 'improvement' is just due to the fact that that benchmark was previously broken.

@michaelwoerister
Copy link
Member

I'm tempted to r+ this but the performance regression doesn't look too good. A CrateNum is encoded as a 16-byte stable hash, if I remember correctly. It's not unexpected that adding 16 bytes to each encoded span would show up in benchmarks.

EncodedSourceFileId::translate also seems to reconstruct the CrateNum for a given source file. Can you use that to import source files before accessing the SourceMap?

Fixes rust-lang#92163
Fixes rust-lang#92014

When writing to the incremental cache, we encode all `Span`s
we encounter, regardless of whether or not their `SourceFile`
comes from the local crate, or from a foreign crate.

When we decode a `Span`, we use the `StableSourceFileId` we encoded
to locate the matching `SourceFile` in the current session. If this
id corresponds to a `SourceFile` from another crate, then we need to
have already imported that `SourceFile` into our current session.

This usually happens automatically during resolution / macro expansion,
when we try to resolve definitions from other crates. In certain cases,
however, we may try to load a `Span` from a transitive dependency
without having ever imported the `SourceFile`s from that crate, leading
to an ICE.

This PR fixes the issue by calling `imported_source_files()`
when we encounter a `SourceFile` with a foreign `CrateNum`.
This ensures that all `SourceFile`s from that crate are imported
into the current session.
@Aaron1011 Aaron1011 force-pushed the fix-missing-source-file branch from 694cc86 to d922092 Compare December 23, 2021 17:56
@Aaron1011
Copy link
Member Author

@michaelwoerister: Thanks, I didn't notice that. I've updated the PR to use the already-decoded CrateNum.

@Aaron1011
Copy link
Member 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 Dec 23, 2021
@bors
Copy link
Contributor

bors commented Dec 23, 2021

⌛ Trying commit d922092 with merge 529fa20023160e522151496a1a7fffc7b07261d1...

@bors
Copy link
Contributor

bors commented Dec 23, 2021

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

@rust-timer
Copy link
Collaborator

Queued 529fa20023160e522151496a1a7fffc7b07261d1 with parent 489296d, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (529fa20023160e522151496a1a7fffc7b07261d1): comparison url.

Summary: This change led to very large relevant improvements 🎉 in compiler performance.

  • Very large improvement in instruction counts (up to -14.6% on incr-full builds of webrender-wrench)

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 led to changes in compiler perf.

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

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 23, 2021
@rustbot rustbot removed the perf-regression Performance regression. label Dec 23, 2021
@Aaron1011
Copy link
Member Author

@michaelwoerister It looks like your suggested fixed the perf regression entirely!

@Aaron1011
Copy link
Member Author

@michaelwoerister Do you think this is now good to merge? A large number of people are hitting this on the latest nightly.

@cjgillot
Copy link
Contributor

The perf regression appears resolved. Let's go ahead and merge this.
r? @cjgillot
@bors r+

@bors
Copy link
Contributor

bors commented Dec 31, 2021

📌 Commit d922092 has been approved by cjgillot

@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 Dec 31, 2021
@bors
Copy link
Contributor

bors commented Dec 31, 2021

⌛ Testing commit d922092 with merge 984a6bf...

@bors
Copy link
Contributor

bors commented Dec 31, 2021

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing 984a6bf to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 31, 2021
@bors bors merged commit 984a6bf into rust-lang:master Dec 31, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 31, 2021
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (984a6bf): comparison url.

Summary: This change led to very large relevant improvements 🎉 in compiler performance.

  • Very large improvement in instruction counts (up to -14.5% on incr-full builds of webrender-wrench)

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

@rustbot label: -perf-regression

bors bot pushed a commit to bevyengine/bevy that referenced this pull request Jan 2, 2022
# Objective

- Nightly checks where disabled because of a bug in Rust
- Dependency checks are failing because of a new duplicate

## Solution

- Now that rust-lang/rust#92175 has been merged, re-enable nightly checks
- Add the new duplicate dependency to the known list
- Removed `Inflector` dependency as it's not used anymore


Co-authored-by: François <8672791+mockersf@users.noreply.github.com>
@michaelwoerister
Copy link
Member

I'm glad the alternative approach worked out.
Thanks for taking on the review while I was offline during the holidays, @cjgillot!

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. 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.

failed to lookup SourceFile in new context OnDiskCache cannot decode Spans with foreign files
8 participants