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

fix some issues around ZST handling #115277

Merged
merged 4 commits into from
Aug 29, 2023
Merged

fix some issues around ZST handling #115277

merged 4 commits into from
Aug 29, 2023

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Aug 27, 2023

This fixes two bugs:

  • We used to entirely skip enum variants like B([u16; 0], !), even failing to properly align the enum! Honoring the alignment of uninhabited variants is important for the same reason that we must reserve space for their fields -- see here for why.
  • We uses to reject repr(transparent) on struct MyType([u16; 0]), which is weird because a one-field struct should always be allowed to be transparent around that field. (moved to separate PR)

I also found two places in the layout code that did something special for ZST without explaining why, and removing those special cases doesn't seem to have any effect except for reordering some zero-sized fields which shouldn't be an issue... maybe PR CI will explain why those cases were needed, or maybe they became obsolete at some point.

@rustbot
Copy link
Collaborator

rustbot commented Aug 27, 2023

r? @davidtwco

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added 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 Aug 27, 2023
@rustbot
Copy link
Collaborator

rustbot commented Aug 27, 2023

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

@@ -357,10 +359,8 @@ pub trait LayoutCalculator {
// It'll fit, but we need to make some adjustments.
match layout.fields {
FieldsShape::Arbitrary { ref mut offsets, .. } => {
for (j, offset) in offsets.iter_enumerated_mut() {
if !variants[i][j].0.is_zst() {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is one of these places special-casing ZST that I removed

Copy link
Member Author

Choose a reason for hiding this comment

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

This got added in d7a750b by @mikebenfield. But their tests still pass after removing the if. So... maybe it just was never needed?

@@ -954,9 +957,6 @@ fn univariant(
};

(
// Place ZSTs first to avoid "interesting offsets", especially with only one
// or two non-ZST fields. This helps Scalar/ScalarPair layouts.
!f.0.is_zst(),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the other place special-casing ZST that I removed

Copy link
Member Author

Choose a reason for hiding this comment

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

This was present since #45225 by @eddyb. Maybe at the time Scalar/ScalarPair computation still worked differently and the "interesting" offsets were an issue? It doesn't seem to be an issue any more today... 🤷

Copy link
Contributor

Choose a reason for hiding this comment

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

This was likely obviated by #73453

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Aug 27, 2023

Some changes occurred in diagnostic error codes

cc @GuillaumeGomez

@rust-log-analyzer

This comment was marked as resolved.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

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

The error code change looks good to me. 👍

@RalfJung
Copy link
Member Author

@GuillaumeGomez it seems to be running the doctest even for the removed error code? That doesn't make sense, does it? I'll mark it as ignore but I wouldn't think I should have to.

@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the is_1zst branch 2 times, most recently from ccf77c3 to aaf8833 Compare August 28, 2023 07:13
@rustbot
Copy link
Collaborator

rustbot commented Aug 28, 2023

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@@ -311,7 +311,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
}
// only wide pointer boxes are handled as pointers
// thin pointer boxes with scalar allocators are handled by the general logic below
ty::Adt(def, args) if def.is_box() && cx.layout_of(args.type_at(1)).is_zst() => {
ty::Adt(def, args) if def.is_box() && cx.layout_of(args.type_at(1)).is_1zst() => {
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is also a bugfix -- a Box with an allocator that is ZST but highly aligned (more aligned than a pointer) cannot just be treated like a raw pointer.

Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

This looks good to me, one small typo then r=me.

compiler/rustc_abi/src/lib.rs Outdated Show resolved Hide resolved
@RalfJung
Copy link
Member Author

@bors r=davidtwco,GuillaumeGomez

@bors
Copy link
Contributor

bors commented Aug 28, 2023

📌 Commit 610c65f1681b166c68b36bc50543a196f6b103e2 has been approved by davidtwco,GuillaumeGomez

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 28, 2023
@RalfJung
Copy link
Member Author

@bors r=davidtwco,GuillaumeGomez

@bors
Copy link
Contributor

bors commented Aug 29, 2023

📌 Commit 5835c8a9510c60eb47b2a21cb3da39405d7e0c3d has been approved by davidtwco,GuillaumeGomez

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 29, 2023
@RalfJung
Copy link
Member Author

@bors r=davidtwco
(There are no longer any diagnostic changes here)

@bors
Copy link
Contributor

bors commented Aug 29, 2023

📌 Commit 82a168b6f0b6f253e3df80d3df407e8727d6fec0 has been approved by davidtwco

It is now in the queue for this repository.

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member Author

@bors r=davidtwco

@bors
Copy link
Contributor

bors commented Aug 29, 2023

📌 Commit b2ebf1c has been approved by davidtwco

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 29, 2023

⌛ Testing commit b2ebf1c with merge 0b84f18...

@bors
Copy link
Contributor

bors commented Aug 29, 2023

☀️ Test successful - checks-actions
Approved by: davidtwco
Pushing 0b84f18 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 29, 2023
@bors bors merged commit 0b84f18 into rust-lang:master Aug 29, 2023
@rustbot rustbot added this to the 1.74.0 milestone Aug 29, 2023
@RalfJung RalfJung deleted the is_1zst branch August 29, 2023 12:05
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0b84f18): 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
Improvements ✅
(secondary)
-0.8% [-0.8%, -0.8%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

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)
0.4% [0.4%, 0.4%] 1
Regressions ❌
(secondary)
2.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.4% [-2.4%, -2.4%] 1
All ❌✅ (primary) 0.4% [0.4%, 0.4%] 1

Cycles

Results

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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.8% [-2.8%, -2.8%] 1
All ❌✅ (primary) - - 0

Binary size

Results

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)
0.0% [0.0%, 0.0%] 5
Regressions ❌
(secondary)
0.0% [0.0%, 0.0%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [0.0%, 0.0%] 5

Bootstrap: 631.441s -> 630.165s (-0.20%)
Artifact size: 316.24 MiB -> 316.28 MiB (0.01%)

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.

8 participants