-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
r? @davidtwco (rustbot has picked a reviewer for you, use r? to override) |
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() { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
This comment has been minimized.
This comment has been minimized.
Some changes occurred in diagnostic error codes |
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this 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. 👍
@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 |
This comment has been minimized.
This comment has been minimized.
ccf77c3
to
aaf8833
Compare
@@ -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() => { |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
@bors r=davidtwco,GuillaumeGomez |
📌 Commit 610c65f1681b166c68b36bc50543a196f6b103e2 has been approved by It is now in the queue for this repository. |
@bors r=davidtwco,GuillaumeGomez |
📌 Commit 5835c8a9510c60eb47b2a21cb3da39405d7e0c3d has been approved by It is now in the queue for this repository. |
@bors r=davidtwco |
📌 Commit 82a168b6f0b6f253e3df80d3df407e8727d6fec0 has been approved by It is now in the queue for this repository. |
This comment has been minimized.
This comment has been minimized.
@bors r=davidtwco |
☀️ Test successful - checks-actions |
Finished benchmarking commit (0b84f18): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesResultsThis 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.
Binary sizeResultsThis 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.
Bootstrap: 631.441s -> 630.165s (-0.20%) |
This fixes two bugs:
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(moved to separate PR)repr(transparent)
onstruct MyType([u16; 0])
, which is weird because a one-field struct should always be allowed to be transparent around that field.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.