- Notifications
You must be signed in to change notification settings - Fork 14.1k
Description
Looking at some examples in #137278 (comment) shows that Option<u128> is using a full u128 for its stored tag. That tag, of course, can only be 0 or 1.
As a result things like returning Some(…) need to write two qwords 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 unconstrained repr(Rust) we should probably stop at something reasonable for the target.)