Uh oh!
There was an error while loading. Please reload this page.
Ignore ZST offsets when deciding whether to use Scalar/ScalarPair layout - #73453
Conversation
rust-highfive
commented
Jun 17, 2020
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @petrochenkov (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
petrochenkov
commented
Jun 17, 2020
AFAIR, this restriction was introduced to be able to do DST coercions, but I'm not sure whether this applies to tuples. r? @RalfJung |
Yep, this PR miscompiles the following code :( #![feature(unsized_tuple_coercion)]pubtypeSiz = (u8,[u32;2]);pubtypeUn = (u8,[u32]);pubfncoercion(x:&Siz) -> &Un{
x
}LLVM IRdefine { { [0 x i8], i8, [3 x i8], [0 x i32] }*, i64 } @_ZN4test8coercion17h76ca7bfe6ae8dcf2E({ [0 x i32], [2 x i32], [0 x i8], i8, [3 x i8] }* noaliasreadonlyalign4dereferenceable(12) %x) unnamed_addr #0 {
start:
%0 = bitcast { [0 x i32], [2 x i32], [0 x i8], i8, [3 x i8] }* %xto { [0 x i8], i8, [3 x i8], [0 x i32] }*
%1 = insertvalue { { [0 x i8], i8, [3 x i8], [0 x i32] }*, i64 } undef, { [0 x i8], i8, [3 x i8], [0 x i32] }* %0, 0%2 = insertvalue { { [0 x i8], i8, [3 x i8], [0 x i32] }*, i64 } %1, i642, 1ret { { [0 x i8], i8, [3 x i8], [0 x i32] }*, i64 } %2
}Should I: limit this to types that don't implement |
RalfJung
commented
Jun 18, 2020
This is way outside my league I'm afraid.^^ But AFAIK it is indeed impossible to reorder the last field due to unsizing coercions.
That would definitely be a good idea. I cannot give any advice on the other alternatives, sorry. Cc @eddyb (but they are very busy recently)... not sure whom else to ping? Cc @nikomatsakis |
r? @nikomatsakis -- I'll take a look and try to give intelligent feedback :) |
083d75a to
1882bdbCompareThere was a problem hiding this comment.
I'm not sure if this is actually okay.
nikomatsakis
commented
Jul 1, 2020
Well, the logic makes some sense to me, at least, but I'd like to hear what @eddyb thinks, as they definitely know this code best (I'm not all that familiar with it, to be honest). I guess the "other way around" here would be not to reorder fields but to make the checks and code that are failing with the current ordering more capable? I guess in any case that the logic is that we can 'permute' the offset of ZST fields arbitrarily, since there is no memory to be accessed? The offset might be visible in other ways (e.g., computing raw pointers and converting them to integers), not sure if that's a concern. I guess the layout of tuples is largely undefined... Also, just as a point of "curiosity", I think that -- in general -- it's actually plausible for us to reorder DST fields even if they are not last, so long as we can recover not only the alignment of the field but also its size, but it would then require us to do the arithmetic at runtime to compute the offsets of all other fields, something we've traditionally avoided for its complexity. |
erikdesjardins
commented
Jul 2, 2020
Yeah, it's possible that the following check could be removed instead: rust/src/librustc_middle/ty/layout.rs Lines 393 to 395 in b7856f6 The relevant parts of layout haven't changed significantly since eddyb's original #45225 so I eagerly await their comments :) |
Muirrum
commented
Jul 24, 2020
@eddyb This is a triage bump. |
nikomatsakis
commented
Jul 27, 2020
r? @eddyb Make it official we're waiting for their feedback here=) |
eddyb
commented
Aug 14, 2020
Ugh I'm really sorry, I only now got a triage PM about this, I don't recall seeing this PR before (I guess I haven't gotten around to checking the PRs assigned to me in the last 18 days - in general, feel free to PM me on Zulip). This looks fine, I guess, I'm only worried about the perf loss from sorting twice (which I'm not sure can be avoided). @bors try @rust-timer queue |
rust-timer
commented
Aug 14, 2020
Awaiting bors try build completion |
bors
commented
Aug 14, 2020
⌛ Trying commit 7336e5f48c72e3606f8e496daa21890f9415d881 with merge 9ebc0face0731b2ce4ff7382be873c6f734a0c50... |
eddyb
left a comment
There was a problem hiding this comment.
Sorry about forgetting about Abi::Vector until the last moment, but it's also important (it also has #[repr(transparent)] support etc.).
You could/should also add tests for it but I'm not sure what type to use (maybe you can find a #[repr(transparent)] test that also tests Abi::Vector using #[repr(simd)] or similar?).
eddyb
commented
Aug 18, 2020
@bors r- |
eddyb
commented
Aug 18, 2020
Also, I should say, this shouldn't cause more codegen than today, since any ZSTs that were reordered to the start, still are (that part of the code wasn't changed at all), so they will still get no offset applied. The new byte-based offset will pretty much only replace an identical offset being applied as a "struct field", but both should result in the same machine code (barring any LLVM optimizations but since this is about ZSTs, I'm not worried about that). |
This comment has been minimized.
This comment has been minimized.
RalfJung
commented
Sep 5, 2020
@eddyb this is ready for another round of review. @erikdesjardins please write a note in the PR when this is ready for review again; GitHub does not (reliably) send email notifications for force pushes. |
I messaged @eddyb on Zulip as they mentioned above, but yeah I should probably still comment so other people know what's going on. |
erikdesjardins
commented
Sep 20, 2020
@rustbot modify labels: -S-waiting-on-author, +S-waiting-on-review |
eddyb
commented
Sep 25, 2020
I got the Zulip PM but then because of how Zulip forces you to always see messages when navigating, it marked it as read, I'm really sorry. I'm still generally months behind most things on GitHub (and even waiting-on-review PRs) but trying to help where I can (don't mind repeated PMs, it helps with various platforms being all over the place). @bors r+ |
bors
commented
Sep 25, 2020
📌 Commit 24e0913 has been approved by |
bors
commented
Sep 25, 2020
bors
commented
Sep 25, 2020
☀️ Test successful - checks-actions, checks-azure |
This is important because Scalar/ScalarPair layout previously would not be used if any ZST had nonzero offset.
For example, before this change, only
((), u128)would be laid out likeu128, not(u128, ()).Fixes#63244