Implement the special repr(C)-non-clike-enum layout#46123
Implement the special repr(C)-non-clike-enum layout#46123bors merged 4 commits intorust-lang:masterfrom
Conversation
|
(rust_highfive has picked a reviewer for you, use r? to override) |
|
r? @eddyb |
src/librustc/ty/layout.rs
Outdated
|
Changed impl to reflect discussion in IRC. Also fixed a test that was asserting the old behaviour. |
src/librustc/ty/layout.rs
Outdated
src/librustc/ty/layout.rs
Outdated
There was a problem hiding this comment.
I think I prefer naming this optimize, making it mutable, and &=-ing it below instead.
src/librustc/ty/layout.rs
Outdated
There was a problem hiding this comment.
What I meant was that you wouldn't need special discriminant vs union semantics, just applying a size&align prefix.
src/librustc/ty/layout.rs
Outdated
There was a problem hiding this comment.
Rename this to prefix_align, I guess.
There was a problem hiding this comment.
But it's not how aligned the prefix should be, it's how aligned the suffix should be.
There was a problem hiding this comment.
It's the alignment imposed by the prefix, the logic looking at it need not know why it's chosen the way it is.
src/librustc/ty/layout.rs
Outdated
|
Comments addressed |
src/librustc/ty/layout.rs
Outdated
There was a problem hiding this comment.
Can you change the comment to say "with a prefix of an arbitrary size & alignment (e.g. enum tag)" instead of "but part of an enum"?
src/librustc/ty/layout.rs
Outdated
There was a problem hiding this comment.
prefix_size instead of discr_size should do nicely.
src/librustc/ty/layout.rs
Outdated
There was a problem hiding this comment.
This comment could be expanded to describe how increasing the prefix alignment produces the same variant layouts as if they were separately computed as structs and then had some space inserted in the front.
|
cc @rust-lang/compiler @rust-lang/lang LGTM, should this wait on the RFC / have a FCP? |
|
Comments addressed. |
soooo do I hear an r+ @eddyb? or an fcp merge? :) |
|
@carols10cents But nobody answered... |
I do expect the RFC to be accepted, but I don't believe we have to block on it. I believe the current behavior is undefined, so we are within our rights to adjust it. FCP might be reasonable, though I think not really necessary, I don't feel like major controversy is expected here. |
|
@bors r+ |
|
📌 Commit 904ccbc has been approved by |
|
⌛ Testing commit 904ccbc9c2b1f8f24664a7ef89071738954f0028 with merge 2e0fd271c40ec90c0d6fa5b99929b81f12413d63... |
|
💔 Test failed - status-travis |
|
uhhh so apparently is 16 bytes on i586-gnu-i686-musl, but u64 is only aligned to 4 bytes? wat |
|
nevermind, I'm dumb. |
|
@bors r+ |
|
📌 Commit 0e63d27 has been approved by |
Implement the special repr(C)-non-clike-enum layout This is the second half of rust-lang/rfcs#2195 which specifies that ```rust #[repr(C, u8)] #[derive(Copy, Clone, Eq, PartialEq, Debug)] enum MyEnum { A(u32), // Single primitive value B { x: u8, y: i16 }, // Composite, and the offset of `y` depends on tag being internal C, // Empty D(Option<u32>), // Contains an enum E(Duration), // Contains a struct } ``` Has the same layout as ```rust #[repr(C)] struct MyEnumRepr { tag: MyEnumTag, payload: MyEnumPayload, } #[repr(C)] #[allow(non_snake_case)] union MyEnumPayload { A: MyEnumVariantA, B: MyEnumVariantB, D: MyEnumVariantD, E: MyEnumVariantE, } #[repr(u8)] #[derive(Copy, Clone)] enum MyEnumTag { A, B, C, D, E } #[repr(C)] #[derive(Copy, Clone)] struct MyEnumVariantA(u32); #[repr(C)] #[derive(Copy, Clone)] struct MyEnumVariantB {x: u8, y: i16 } #[repr(C)] #[derive(Copy, Clone)] struct MyEnumVariantD(Option<u32>); #[repr(C)] #[derive(Copy, Clone)] struct MyEnumVariantE(Duration); ```
|
☀️ Test successful - status-appveyor, status-travis |
This is the second half of rust-lang/rfcs#2195
which specifies that
Has the same layout as