Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upUnions interacting with Enum layout optimization #36394
Comments
This comment has been minimized.
This comment has been minimized.
|
Some specific examples: union A {
x: Box<i32>,
y: Box<i64>,
}
union B {
x: Box<i32>,
y: Box<i64>,
z: (),
}The question here is essentially, what is the size of |
This comment has been minimized.
This comment has been minimized.
|
Previous discussion (11 April - 28 May) rust-lang/rfcs#1444 (comment) |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Layout of non- |
This comment has been minimized.
This comment has been minimized.
|
This is another open question for the tracking issue: #32836 |
This comment has been minimized.
This comment has been minimized.
|
@nagisa While repr(C) fixes the representation of a type Foo, it does not say anything (that I know to be documented) about the representation of |
This comment has been minimized.
This comment has been minimized.
|
@Amanieu unions don't have a discriminant, though, so all three unions should have the size of a pointer. Adding a I don't think the enum layout optimization needs to apply here at all; the size of a union should always match the maximum size of any field type. |
This comment has been minimized.
This comment has been minimized.
Why do you care about representation of |
This comment has been minimized.
This comment has been minimized.
|
I think that this discussion has come to the conclusion that unions interact "as all other things" with enum layout optimization, and I'm going to close. |
Mark-Simulacrum
closed this
May 20, 2017
petrochenkov
referenced this issue
May 20, 2017
Open
Untagged unions (tracking issue for RFC 1444) #32836
This comment has been minimized.
This comment has been minimized.
|
I think this issue should be re-opened. It is originally about the nodrop-union crate, which is pretty much the same as
They need not only a way to inhibit automatic drop glue (which Concretely, Some(ManuallyDrop::new(uninitialized::<[String; 100]>())).is_some()More generally, we need to have principles for what to do to use |
This comment has been minimized.
This comment has been minimized.
|
Hm, okay. I'll reopen; this was (or is? Was it merged?) an unresolved question in the RFC. |
Mark-Simulacrum
reopened this
May 20, 2017
This comment has been minimized.
This comment has been minimized.
|
Could you point to a specific part of the RFC? I can’t find it in rust-lang/rfcs#1897. |
This comment has been minimized.
This comment has been minimized.
|
I don't think the original union RFC mentioned it (RFC 1444), but there was some discussion in the thread itself: rust-lang/rfcs#1444 (comment) and rust-lang/rfcs#1444 (comment) (but also just search from "enum layout") |
This comment has been minimized.
This comment has been minimized.
|
Ah, found rust-lang/rfcs#1444 (comment) which concludes that adding a |
Mark-Simulacrum commentedSep 11, 2016
•
edited
IRC (#rust) short discussion log, since I don't actually know much about this:
cc @Amanieu @bluss