-
Notifications
You must be signed in to change notification settings - Fork 15
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
Use empty alignment bits of pointers to store Result state #401
Comments
First, an optimization for pointer/reference T:What we can do for We can do the same for This can be done by choosing a separate implementation of storage for the Result here: Lines 927 to 930 in f9bede0
Next, an optimization for pointer E:Errors are not raw pointers normally, but can be Dawn does this by taking the raw pointer out and storing it as an intptr: https://source.chromium.org/chromium/chromium/src/+/main:third_party/dawn/src/dawn/common/Result.h;l=315-316;drc=8e78783dc1f7007bad46d657c9f332614e240fd8;bpv=1;bpt=1?q=f:dawn%20result&ss=chromium We could unwrap the Box into a raw pointer and use the low bits when alignment of Once we see this, we can do the same for These can also be done by choosing a separate implementation of storage for the Result here: Lines 927 to 930 in f9bede0
Single pointer storageAs noted, we want Result to be constexpr, so static_cast only. If T and E are both pointers (or are T* and Box) and they are compatible then we can make a single storage field if the type also provides a disambiguator function though the Result template. This seems the least likely to happen in practice as error types are not raw pointers, and would grow the type signature like |
Please assign me this task! |
For Dawn, a Result<ptr, ptr> can be stored in a single pointer (cc: @Kangz) when their values are known to never overlap.
While we can't hold two different newtype wrappers in the same storage, and drop the boolean. We can drop the
E
storage if it can be held in theT
.This is similar to Option representation but it requires two types, and they must share compatible storage. We may not need the types to opt in at all even, just compatible storage. To be constexpr we can't use reinterpret_cast, so for pointers they would need to be the same or related (static_cast).
The text was updated successfully, but these errors were encountered: