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

Store a DefId instead of an AdtDef in AggregateKind::Adt #92203

Merged
merged 1 commit into from
Dec 23, 2021

Conversation

Aaron1011
Copy link
Member

The AggregateKind enum ends up in the final mir Body. Currently,
any changes to AdtDef (regardless of how significant they are)
will legitimately cause the overall result of optimized_mir to change,
invalidating any codegen re-use involving that mir.

This will get worse once we start hashing the Span inside FieldDef
(which is itself contained in AdtDef).

To try to reduce these kinds of invalidations, this commit changes
AggregateKind::Adt to store just the DefId, instead of the full
AdtDef. This allows the result of optimized_mir to be unchanged
if the AdtDef changes in a way that doesn't actually affect any
of the MIR we build.

The `AggregateKind` enum ends up in the final mir `Body`. Currently,
any changes to `AdtDef` (regardless of how significant they are)
will legitimately cause the overall result of `optimized_mir` to change,
invalidating any codegen re-use involving that mir.

This will get worse once we start hashing the `Span` inside `FieldDef`
(which is itself contained in `AdtDef`).

To try to reduce these kinds of invalidations, this commit changes
`AggregateKind::Adt` to store just the `DefId`, instead of the full
`AdtDef`. This allows the result of `optimized_mir` to be unchanged
if the `AdtDef` changes in a way that doesn't actually affect any
of the MIR we build.
@rust-highfive
Copy link
Collaborator

Some changes occured to the CTFE / Miri engine

cc @rust-lang/miri

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

r? @oli-obk

(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 22, 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 22, 2021
@bors
Copy link
Contributor

bors commented Dec 22, 2021

⌛ Trying commit cac431b with merge f525b58008e58fa0b4809a7102f4ebd2e14c1047...

@bors
Copy link
Contributor

bors commented Dec 22, 2021

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

@rust-timer
Copy link
Collaborator

Queued f525b58008e58fa0b4809a7102f4ebd2e14c1047 with parent e100ec5, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f525b58008e58fa0b4809a7102f4ebd2e14c1047): comparison url.

Summary: This benchmark run did not return any relevant changes.

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
@oli-obk
Copy link
Contributor

oli-obk commented Dec 23, 2021

@bors r+ rollup

I think we should try and follow up on this by attempting to reduce the number of tcx.adt_def calls where possible. It may be unnecessary in const checking and other places, even if the function signatures currently require it. We could check how the AdtDef is used later. All the is_enum cases could potentially obtain this information from local caches (e.g. in mir interpret we can ask for the type of the local)

@bors
Copy link
Contributor

bors commented Dec 23, 2021

📌 Commit cac431b has been approved by oli-obk

@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 23, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Dec 23, 2021

@bors r-

Ah what I forgot: is it now possible to write incremental tests that show that this causes fewer recompiles of optimized_mir?

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 23, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Dec 23, 2021

r=me with an answer to that

@Aaron1011
Copy link
Member Author

@oli-obk Since we currently skip hashing the FieldDef span, I dont know if this will curreny prevent any invalidations. Once we start hashing spans in #92210, this will become important

@oli-obk
Copy link
Contributor

oli-obk commented Dec 23, 2021

I thought so, thanks for confirming

@bors r+

@bors
Copy link
Contributor

bors commented Dec 23, 2021

📌 Commit cac431b has been approved by oli-obk

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 23, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 23, 2021
…askrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#90625 (Add `UnwindSafe` to `Once`)
 - rust-lang#92121 (disable test with self-referential generator on Miri)
 - rust-lang#92166 (Fixed a small typo in ui test comments)
 - rust-lang#92203 (Store a `DefId` instead of an `AdtDef` in `AggregateKind::Adt`)
 - rust-lang#92231 (Update books)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8a61ae0 into rust-lang:master Dec 23, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants