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 upDocument #[repr] on non-C-like enums #25651
Conversation
rust-highfive
assigned
steveklabnik
May 20, 2015
This comment has been minimized.
This comment has been minimized.
|
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @steveklabnik (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. 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 CONTRIBUTING.md for more information. |
This comment has been minimized.
This comment has been minimized.
|
This documents current behavior. Is repr(X) on non-C-like enums is a bug? In that case we need to fix that by rejecting code instead. |
bluss
force-pushed the
bluss:doc-enum-repr
branch
from
32391fd
to
608e57c
May 20, 2015
This comment has been minimized.
This comment has been minimized.
josephglanville
commented
May 22, 2015
|
I hope it's not a bug, it would be a breaking change if so. I am using the behaviour and I would assume others are to. The main reason was that the collections::enum_set::CLike is marked unstable and this seemed to do what I need anyways. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Great to have that clear! @SimonSapin and I discovered that this is quite crucial for arrayvec and smallvec -- see issue servo/rust-smallvec#5 |
This comment has been minimized.
This comment has been minimized.
|
It seems very fragile to relay on on |
This comment has been minimized.
This comment has been minimized.
|
The idea of this PR was to make it non-fragile: The needed guarantee is written into the reference and a test to prove it added to the testsuite. |
This comment has been minimized.
This comment has been minimized.
|
I made a PR into your PR to add another test for the behavior that arrayvec relies on: bluss#1 |
This comment has been minimized.
This comment has been minimized.
|
I never knew you could submit PRs to PRs, that's neat. arrayvec uses |
This comment has been minimized.
This comment has been minimized.
|
I think it tests a slightly different case, but feel free to take it or not. |
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
May 27, 2015
This comment has been minimized.
This comment has been minimized.
|
Oh, my tests are actually completely wrong |
bluss
force-pushed the
bluss:doc-enum-repr
branch
from
e57f69f
to
42e29fa
May 27, 2015
This comment has been minimized.
This comment has been minimized.
|
Updated PR. Included @SimonSapin's testcase (thanks!), and fixed mine, which were embarrassingly completely incorrect the first time. |
bors
added a commit
that referenced
this pull request
May 27, 2015
bors
added a commit
that referenced
this pull request
May 27, 2015
alexcrichton
reviewed
May 27, 2015
| assert!(size_of::<EC<&i32>>() > ptrsize); | ||
|
|
||
| // test that a zero payload does not influence the discriminant | ||
| let zero: &i32 = unsafe { zeroed() }; |
This comment has been minimized.
This comment has been minimized.
alexcrichton
May 27, 2015
Member
Is... this not undefined behavior? We explicitly tell LLVM that all &T references are not null, and this is making a null one?
This comment has been minimized.
This comment has been minimized.
bluss
May 28, 2015
Author
Contributor
Right. It should never load the value in the zero variable or in its location inside the enum though, can it be safe that way?
This comment has been minimized.
This comment has been minimized.
alexcrichton
May 28, 2015
Member
Instead of inspecting the payload, could this just assert that the size of the enum is twice the size of a word?
This comment has been minimized.
This comment has been minimized.
bluss
May 28, 2015
Author
Contributor
Well that's basically what the tests above already do. They are less specific maybe.
So we should remove this?
This comment has been minimized.
This comment has been minimized.
bluss
force-pushed the
bluss:doc-enum-repr
branch
from
42e29fa
to
d0e6396
May 28, 2015
This comment has been minimized.
This comment has been minimized.
|
Thanks, PR updated. Only tests sizes now. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Thanks! |
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this pull request
May 29, 2015
bors
added a commit
that referenced
this pull request
May 29, 2015
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this pull request
May 29, 2015
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this pull request
May 29, 2015
bors
added a commit
that referenced
this pull request
May 29, 2015
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
May 29, 2015
This comment has been minimized.
This comment has been minimized.
|
|
bluss
reviewed
May 29, 2015
| assert_eq!(size_of::<Eu16<()>>(), 2); | ||
| assert_eq!(size_of::<Ei32<()>>(), 4); | ||
| assert_eq!(size_of::<Eu32<()>>(), 4); | ||
| assert_eq!(size_of::<Ei64<()>>(), 8); |
This comment has been minimized.
This comment has been minimized.
bluss
May 29, 2015
Author
Contributor
thread '<main>' panicked at 'assertion failed:(left == right)(left:4, right:8)', /Users/rustbuild/src/rust-buildbot/slave/auto-mac-32-opt/build/src/test/run-pass/enum-discrim-manual-sizing-2.rs:89
on 32-bit. Looks like there is a bug in #[repr]?
This comment has been minimized.
This comment has been minimized.
steveklabnik
added a commit
to steveklabnik/rust
that referenced
this pull request
May 29, 2015
bors
added a commit
that referenced
this pull request
May 29, 2015
This comment has been minimized.
This comment has been minimized.
|
We need to scrub this PR until the bug is fixed. I'll see what I can do though |
This comment has been minimized.
This comment has been minimized.
|
@bors: r- |
bluss
referenced this pull request
Jun 8, 2015
Closed
repr(i64) picks 32-bit discriminant on 32-bit platform #26114
This comment has been minimized.
This comment has been minimized.
|
Closing for now, reported a bug. |
bluss commentedMay 20, 2015
Document #[repr] on non-C-like enums
rustc accepts the following today:
and it has a good use (it appears to me): this inhibits the non-nullable
pointer optimization that the regular Option and similar enums allow.
Document this in the reference, and add tests to make sure it compiles.
This means that we guarantee with
reprthat the discriminant will bepresent and with that size, but not sure if we want to guarantee
anything more (no guarantee on placement in struct).