-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Enum layout optimizations #19536
Enum layout optimizations #19536
Conversation
Tidy error |
9b6b89b
to
fcd88dd
Compare
Great! By the way, if my understanding is correct, you cannot (yet) optimize |
CC @aturon on NonZero |
@lifthrasiir yep, though i'd imagine sharing discriminants with nested enums will require a bit of work. |
There has already been an RFC for extending the nullable pointer optimisation to library types, but it was closed & postponed. It does have a slightly different design to this pull request’s, though: it used an attribute instead of a wrapper type, and didn’t allow arbitrary types to be non-nullable—only raw pointers were allowed. |
@luqmana For now would you be ok leaving out |
These are some awesome improvements by the way, nice work! Could this also add some tests using |
218b772
to
0d7d9f7
Compare
@alexcrichton It looks like most of the gains here come from the use of |
dea1999
to
5b21ffe
Compare
5b21ffe
to
27d539f
Compare
@luqmana do you want to wait for rust-lang/rfcs#499 to land this? If so, would you be ok closing in favor of the RFC? |
@alexcrichton sure that's fine
|
Part 1: This extends the nullable enum opt to traverse beyond just the first level to find possible fields to use as the discriminant. So now, it'll work through structs, tuples, and fixed sized arrays.
Part 2: Introduce a new lang item, NonZero, that you can use to wrap raw pointers or integral types to indicate to rustc that the underlying value is known to never be 0/NULL. We then use this in Vec, Rc and Arc to have them also benefit from the nullable enum opt.
Fixes #19419.
Fixes #13194.
Fixes #9378.
Fixes #7576.