-
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
Space-optimize Option<T>
for integral enum T
#84
Conversation
Actually, I'd like to change this proposal so that instead of the invalid bit pattern being implementation defined, the compiler should be forced to pick the one with the largest value. |
Previously proposed RFC's that seem related: #36, #41. I would recommend participants skim over the discussion of those RFC's, especially why they were closed. (Note that at least one was marked as "postponed", which means we approve of the overall notion but want to hold off on trying to adopt the approach outlined in that RFC.) |
The difference between this and the previous, more general, proposals is that this one doesn't require a change in the language or the standard library. This is just a change in the compiler and all existing code gets this optimization for free. For this reason I figured this proposal had a considerably larger change of getting accepted sooner rather than later. |
Changed the invalid bit pattern from being implementation defined to being defined by the language.
I would also argue that the programmer shouldn't have to do anything extra to get this optimization. In the future, users will be able to declare that their type |
@tommit good point. It is possible that a change like this actually does not require an RFC per-se, since it should be implementable as a compiler optimization (with perhaps some little bits of runtime support in isolated parts of the runtime). |
Note that the memory representation of enums is already undefined, precisely to allow adding this kind of optimization without changing the semantics of the language. |
Thanks for the RFC! As @pnkfelix and @SimonSapin have noted, enum representation is undefined to allow for optimizations such as this. In the light of that, it's ok to not have an RFC to implement an optimization. In that case, I'm closing this. |
(You can/should open a bug on the main Rust repo so that this optimisation isn't forgotten.) |
I filed this issue over here: rust-lang/rust#14540 |
Return A type parameter on ReadToEnd
No description provided.