-
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
Consider improving layout of this enum #24041
Comments
I'm not sure I follow. |
The layout of the Boxed variant could theoretically be altered such that I'm not sure how worthwhile this is, since it's very specific, and the algorithm to calculate the best layout for every possible scenario is at the very least non-obvious. If there is ever a rust ABI, then it would be preferable to have layouts controlled by predictable, easy to describe rules. |
If you put the box in the same space as the array, i.e. in the second half,
|
Its not necessarily a strictly better idea to put the box in the same space as the array though. fn zomg(foo: &Foo)
match *foo {
Inline(ref t, _) => t.zomg(),
Boxed(ref t) => t.zomg()
} In a function such as above, since the the data and vtable are in the same position it could be optimized to just load those positions and call the function, avoiding the discriminant test completely. I don't know if llvm performs that sort of optimization though. |
Triage: |
This could be done with @eddyb's niche-filling optimisation. It currently only applies to enums with a single dataful variant, but we could make it apply to the largest variant of the enum instead. I am pretty sure this would also improve the layout of a bunch of enums in Stylo. I've thought about this a bit and I think the niche-filling optimisation should apply to the largest variant of any Cc @rust-lang/wg-codegen |
This seems to (now) be a duplicate of #46213. |
Closing in favor of the more general #46213. |
I think the following snippet should be possible (but it fails currently). Since
&'static MyTrait
can't be 0, if the first half of the layout is 0, then the enum must be theBoxed
variant.The text was updated successfully, but these errors were encountered: