-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
optional type optimization #104
Comments
Also, if you do |
Based on @LemonBoy 's suggestion copying the relevant parts of #5162 to here. Though it seems you called this proposal out already above. Edited the parts below to be more concise. Optional
Since Zig doesn't have a stable ABI for its own structs it should be possible to optimize an optional type's layout and size to use the generated padding to host the extra optional field. This would effectively bring the @sizeof(?S) in the example down to 64 and shouldn't have any issues with e.g. var set_of_s: [100]S = undefined; as the type S would stay properly aligned. Of course it won't always be possible to do this optimization, in which case the optional type would have to add the additional field as normal. |
Also to highlight since it's relevant to this issue - @SpexGuy 's suggestion of Explicit Sentinel Optionals from: #3806 (comment) |
This is accepted which means that:
|
Track which values are used when data sizes are bigger than necessary and use those states for maybe types. For example,
?bool
could use value2
of the bool as the null value, and??bool
can use value3
for the null value, and so on.If we have spaces in structs for alignment purposes, that space could be used for the null value, or if any of the fields have null space available, such as a struct with a bool field in it somewhere.
The text was updated successfully, but these errors were encountered: