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

Clarify Layout interning. #94690

Merged
merged 1 commit into from
Mar 7, 2022

Conversation

nnethercote
Copy link
Contributor

Layout is another type that is sometimes interned, sometimes not, and
we always use references to refer to it so we can't take any advantage
of the uniqueness properties for hashing or equality checks.

This commit renames Layout as LayoutS, and then introduces a new
Layout that is a newtype around an Interned<LayoutS>. It also
interns more layouts than before. Previously layouts within layouts
(via the variants field) were never interned, but now they are. Hence
the lifetime on the new Layout type.

Unlike other interned types, these ones are in rustc_target instead of
rustc_middle. This reflects the existing structure of the code, which
does layout-specific stuff in rustc_target while TyAndLayout is
generic over the Ty, allowing the type-specific stuff to occur in
rustc_middle.

The commit also adds a HashStable impl for Interned, which was
needed. It hashes the contents, unlike the Hash impl which hashes the
pointer.

r? @fee1-dead

`Layout` is another type that is sometimes interned, sometimes not, and
we always use references to refer to it so we can't take any advantage
of the uniqueness properties for hashing or equality checks.

This commit renames `Layout` as `LayoutS`, and then introduces a new
`Layout` that is a newtype around an `Interned<LayoutS>`. It also
interns more layouts than before. Previously layouts within layouts
(via the `variants` field) were never interned, but now they are. Hence
the lifetime on the new `Layout` type.

Unlike other interned types, these ones are in `rustc_target` instead of
`rustc_middle`. This reflects the existing structure of the code, which
does layout-specific stuff in `rustc_target` while `TyAndLayout` is
generic over the `Ty`, allowing the type-specific stuff to occur in
`rustc_middle`.

The commit also adds a `HashStable` impl for `Interned`, which was
needed. It hashes the contents, unlike the `Hash` impl which hashes the
pointer.
@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 7, 2022
@rust-highfive
Copy link
Collaborator

Some changes occured to rustc_codegen_cranelift

cc @bjorn3

Some changes occured to rustc_codegen_gcc

cc @antoyo

Some changes occurred in src/tools/clippy.

cc @rust-lang/clippy

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 7, 2022
@nnethercote
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 Mar 7, 2022
@bors
Copy link
Contributor

bors commented Mar 7, 2022

⌛ Trying commit 4f008e0 with merge 5e62d25397a820b5ad1233e0003f4c7d152ba8d9...

@bors
Copy link
Contributor

bors commented Mar 7, 2022

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

@rust-timer
Copy link
Collaborator

Queued 5e62d25397a820b5ad1233e0003f4c7d152ba8d9 with parent 8876ca3, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5e62d25397a820b5ad1233e0003f4c7d152ba8d9): comparison url.

Summary: This benchmark run did not return any relevant results. 9 results were found to be statistically significant but too small to be relevant.

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 Mar 7, 2022
@nnethercote
Copy link
Contributor Author

No notable perf effects, much as expected.

@bors rollup=iffy

@@ -1377,7 +1391,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {

let largest_niche = Niche::from_scalar(dl, Size::ZERO, tag);

let tagged_layout = Layout {
let layout_variants =
layout_variants.into_iter().map(|v| tcx.intern_layout(v)).collect();
Copy link
Member

@fee1-dead fee1-dead Mar 7, 2022

Choose a reason for hiding this comment

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

I wonder if we could intern them beforehand to avoid another loop? the perf didn't show any changes so I don't know if it matters.

@fee1-dead
Copy link
Member

LGTM. Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Mar 7, 2022

📌 Commit 4f008e0 has been approved by fee1-dead

@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 Mar 7, 2022
@bors
Copy link
Contributor

bors commented Mar 7, 2022

⌛ Testing commit 4f008e0 with merge ecb867e...

@bors
Copy link
Contributor

bors commented Mar 7, 2022

☀️ Test successful - checks-actions
Approved by: fee1-dead
Pushing ecb867e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 7, 2022
@bors bors merged commit ecb867e into rust-lang:master Mar 7, 2022
@rustbot rustbot added this to the 1.61.0 milestone Mar 7, 2022
@nnethercote nnethercote deleted the clarify-Layout-interning branch March 7, 2022 20:00
@nnethercote
Copy link
Contributor Author

Thank you for the fast review.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (ecb867e): comparison url.

Summary: This benchmark run did not return any relevant results. 14 results were found to be statistically significant but too small to be relevant.

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

@rustbot label: -perf-regression

bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Mar 26, 2022
… r=fee1-dead

Clarify `Layout` interning.

`Layout` is another type that is sometimes interned, sometimes not, and
we always use references to refer to it so we can't take any advantage
of the uniqueness properties for hashing or equality checks.

This commit renames `Layout` as `LayoutS`, and then introduces a new
`Layout` that is a newtype around an `Interned<LayoutS>`. It also
interns more layouts than before. Previously layouts within layouts
(via the `variants` field) were never interned, but now they are. Hence
the lifetime on the new `Layout` type.

Unlike other interned types, these ones are in `rustc_target` instead of
`rustc_middle`. This reflects the existing structure of the code, which
does layout-specific stuff in `rustc_target` while `TyAndLayout` is
generic over the `Ty`, allowing the type-specific stuff to occur in
`rustc_middle`.

The commit also adds a `HashStable` impl for `Interned`, which was
needed. It hashes the contents, unlike the `Hash` impl which hashes the
pointer.

r? `@fee1-dead`
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. T-rustdoc Relevant to the rustdoc 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