Skip to content
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

Proposal for C-like nested enums to become scalar data types #331

Closed
wants to merge 3 commits into from

Conversation

pczarn
Copy link

@pczarn pczarn commented Sep 28, 2014

@nrc
Copy link
Member

nrc commented Sep 28, 2014

This is related to the various proposals for efficient inheritance, in particular #245. I would very much like a general system for nested enums (whether or not we use this as a basis for efficient inheritance) and if we do that then I would not like to see something like this which does a subset of that in a different way. However, we could (and probably should) adapt the proposal here for C-like nested enums to become scalar data.

@pczarn
Copy link
Author

pczarn commented Sep 29, 2014

@nick29581 I don't think anything in this proposal is necessarily related to inheritance. Perhaps the word "nested" is inappropriate, these are transitively C-like enums.

@nrc
Copy link
Member

nrc commented Oct 1, 2014

@pczarn it is a very different use case from inheritance, but as far as data is concerned its the same. In particular #245 would allow you to a significant portion of this RFC, albeit with a different syntax.

@ghost
Copy link

ghost commented Oct 1, 2014

Enum templates seem to fall out of the scope of this proposal, which is not good given the ubiquity of Option and Result. Also, you can't add the required attribute (required for the optimization to take place) to an enum that's defined in a library you can't change the source code of.

@huonw
Copy link
Member

huonw commented Oct 2, 2014

Thanks for the RFC. We discussed this in the triage meeting and decided that while it was something that might be useful, it's not something that needs to be done for 1.0, since it is backwards compatible. Furthermore, this sort of precise layout control is related to "bit data" proposals like #327 (also postponed #346) so we would like to consider these features in a unified way.

That said, it appears there is only one "real" language changes here: allowing explicit C-like discriminants in enums with data. The layout optimisations is actually something we can do implicitly now since the layout of enums is undefined, that is to say, if we have enum Foo { X, Y, Z }, the compiler is with its rights to represent Option<Foo> as a single byte.

If you were to tune your patch to just do this (i.e. no language changes or external user control, for now), it may be landed and would not require an RFC. However, it is relatively complicated trans code, so you may wish to open a discuss post and solicit feedback from people like @luqmana and @nikomatsakis before putting effort into the code.

(cc #347)

@huonw huonw closed this Oct 2, 2014
withoutboats pushed a commit to withoutboats/rfcs that referenced this pull request Jan 15, 2017
Remove obsolete comment in join_all() docs.
@Centril Centril added A-enum Enum related proposals & ideas A-ffi FFI related proposals. A-machine Proposals relating to Rust's abstract machine. A-bitdata Proposals relating to bitdata / bitflags. A-repr #[repr(...)] related proposals & ideas T-lang Relevant to the language team, which will review and decide on the RFC. labels Nov 26, 2018
wycats pushed a commit to wycats/rust-rfcs that referenced this pull request Mar 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-bitdata Proposals relating to bitdata / bitflags. A-enum Enum related proposals & ideas A-ffi FFI related proposals. A-machine Proposals relating to Rust's abstract machine. A-repr #[repr(...)] related proposals & ideas T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants