-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Represent equivalent enum
s the same as bool
, make bool
an enum
#330
Conversation
If we're doing this, which I am in favor of, we should probably changed the type to Precedence: Haskell |
Yeah, making them |
But it would be inconsistent with the C family of languages whose practitioners we are trying to look familiar to. And in any case the two things, naming and implementation, are almost completely orthogonal. I would rather have the capitalization debate separately. |
Represent all `enum`s which have two variants, both of which have either no data | ||
or zero-sized data, the same way as `bool` is currently represented. Guarantee | ||
that this will be so. (This includes any user-defined `enum` with two nullary | ||
variants, `Result<(), ()>`, and so on.) |
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 don't think we should force this - we currently reserve the right to change all our default data representations and that is nice flexibility to have. You can request this using the c-repr annotation, and of course you could put that on the bool enum, which fulfils your use case, I think.
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 tried to address this under "Arguments against". Do you have a counter-counterargument? I know we do currently reserve this right, but I don't see how the flexibility is at all useful in this case.
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 are certainly things we might want to do - e..g, represent an array of enums as a bit field or something. I think just because we can't think of something now doesn't mean we won't think of something in the future. In particular in this case, because even if we take the rest of this RFC I see essentially no downside in having to annotate bool-like enums with C-repr
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.
represent an array of enums as a bit field or something
This specifically would break interior references.
But in general, as noted by another comment, any representation change you'd want to do for bool
s, you would also want to do for the equivalent types. They only differ, after all, in naming. If you like, this is a specific case of the more general property that representations of types which differ only in their names and the names of their fields/variants should always be the same. (Because there is absolutely no reason the compiler would ever want to choose different representations based on just names.)
This syntax might better achieve the desired goals:
|
@bill-myers The current way of specifying what type to represent an enum with is using the #[repr(u8)]
enum Foo {
Bar = 1,
Baz = 2,
} Simply allowing |
|
Again, something I thought of proposing once but never got around to. Thank you, @glaebhoerl! @liigo they would go in Core, which is really minimal and should be usable in all projects. I agree the representation shouldn't be forced, but I think that strengthens the case for this. Any optimizations that could be done with bools (bitvectors, bitfields, control-flow vs data-flow tricks, conditional mov, etc) ought to be available to all isomorphic types. Most of those optimizations should be handled by LLVM anyways, so I'd hope this might actually not be too complex. I'd like to also make all if-relating things macros around pattern matching so we don't need the |
Also +1 for upper case identifiers. I'd like to do upper case names for the integer types too, C/C++/Java be damned, but if this becomes library defined then upper casing it should be given special priority. |
@glaebhoerl At a first glance, it seems like this change could be done post-1.0, backwards-compatibly, but I could easily be wrong. Have you given that any thought? |
I assumed it couldn't be, because keywords are "always in scope" whereas |
True, although I suspect this could be worked around if need be. But it also seems like the aspect of the proposal involving keywords is separable from the part dealing with the (FWIW, I'm in principle in favor of most of the proposal, but we only have so much time before 1.0, so I'm trying to see what the tradeoffs are if we postpone consideration.) |
Concerns about representation came up last time this was discussed (can't remember where that was), which is why I took these together. |
Remove `true` and `false` as keywords. | ||
|
||
|
||
# Arguments for |
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.
Another argument for is improved documentation, since things can be attached to bool
directly & it would get its own doc page in the normal way.
We discussed this RFC at the triage meeting today, and decided:
Therefore, we are postponing (the |
CLICKME