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

Space-optimize Option<T> for integral enum T #84

Closed
wants to merge 3 commits into from
Closed

Space-optimize Option<T> for integral enum T #84

wants to merge 3 commits into from

Conversation

ghost
Copy link

@ghost ghost commented May 21, 2014

No description provided.

@ghost
Copy link
Author

ghost commented May 21, 2014

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.

@pnkfelix
Copy link
Member

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.)

@ghost
Copy link
Author

ghost commented May 21, 2014

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.
@ghost
Copy link
Author

ghost commented May 21, 2014

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 T has some invalid representation which should be used by Option<T> and the like to perform similar space optimizations. But this is extra work for the programmer which he shouldn't have to do for integral enum types. Therefore this RFC doesn't depend on what we decide to do later on with the general case. It's the same thing with Option<&U>, i.e. it does the space optimization without the programmer having to explicitly ask for it.

@pnkfelix
Copy link
Member

@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).

@SimonSapin
Copy link
Contributor

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.

@alexcrichton
Copy link
Member

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.

@huonw
Copy link
Member

huonw commented May 27, 2014

(You can/should open a bug on the main Rust repo so that this optimisation isn't forgotten.)

@ghost
Copy link
Author

ghost commented May 30, 2014

I filed this issue over here: rust-lang/rust#14540

withoutboats pushed a commit to withoutboats/rfcs that referenced this pull request Jan 15, 2017
Return A type parameter on ReadToEnd
@chorman0773 chorman0773 mentioned this pull request Nov 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants