-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
?struct{ptr: *anyopaque}
is 16 bytes instead of 8 bytes
#15808
Comments
duplicate or maybe subtask of #104 |
It's a special case - there already is code for making optional pointers the same size as regular pointers. Could that be reused here for structs with a single field as a pointer? |
But null is not a valid value of Even an optimization on |
Yes that is correct. I'm not suggesting that this optimization would apply to So basically: // This
const Foo = ?struct { ptr: *anyopaque };
// Becomes the eqvuivalent of
const FooPtr = ?*anyopaque; |
That's not an issue. The contents of the
This optimization isn't quite as trivial as you're suggesting - implementing it as a special case would be quite a lot of work, and it definitely wouldn't be possible on the ZIR level as you initially suggested for a bunch of reasons (for instance, ZIR comes prior to semantic analysis so is untyped, so rewriting field accesses on the struct would be impossible). Much better is to implement a general framework for optional optimization as tracked in #104. (I would consider this a duplicate of that issue.) |
okay |
Zig Version
0.11.0-dev.2777+b95cdf0ae
Steps to Reproduce and Observed Behavior
zig test repro.zig
Expected Behavior
The type
?*anyopaque
should be the same size as the type?struct {ptr: *anyopaque}
because there are no other fields. Maybe this optimization could be done in ZIR?The text was updated successfully, but these errors were encountered: