Should Option<u128>
use a smaller (maybe usize) tag?
#138332
Labels
A-layout
Area: Memory layout of types
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Looking at some examples in #137278 (comment) shows that
Option<u128>
is using a fullu128
for its stored tag. That tag, of course, can only be0
or1
.As a result things like returning
Some(…)
need to write twoqword
s on x64 into the return value, even though of course one of them is only ever all-zeroes.Could we maybe give it a layout equivalent to
(usize, u128)
instead?Or, in general, can we cap the size of tags to a native machine word, given a small discriminant that could fit in just about any type?
(Aside: It's good for
Option<u32>
to still be(u32, MaybeUninit<u32>)
, since that has more niches than(u8, MaybeUninit<u32>)
. But going so big that it takes multiple instructions to write the tag seems like overkill, and for unconstrainedrepr(Rust)
we should probably stop at something reasonable for the target.)The text was updated successfully, but these errors were encountered: