Skip to content
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

Allow specifying the alignment of extern structs #13009

Open
wooster0 opened this issue Sep 29, 2022 · 3 comments
Open

Allow specifying the alignment of extern structs #13009

wooster0 opened this issue Sep 29, 2022 · 3 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@wooster0
Copy link
Contributor

wooster0 commented Sep 29, 2022

This is a follow-up to #10113: #10113 (comment)
We need an addition to the language that allows us to specify the alignment of extern structs.
The UEFI libs are particularly broken because since #10113 any packed struct with an array or any extern struct in it isn't a valid packed type.
In order to make std.os.uefi work with self-hosted, #12899 was an effort to make it easier to add align(1) to every field of a struct. The problem is that it might not work that well considering that structs with decls can't be reified because of #6709.
But instead of allowing #6709 (which might be a bad idea) and then using CPacked, it's probably best to allow specifying the alignment of extern structs at the language level.

A good syntax for this would be extern struct align(alignment) {}.

See also: #12745 #12897 #12993

CC @fifty-six

@Vexu Vexu added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Sep 29, 2022
@Vexu Vexu added this to the 0.10.0 milestone Sep 29, 2022
@topolarity
Copy link
Contributor

To clarify, this would specify the default alignment of every field within the struct?
(i.e., the effective alignment of the extern struct might differ after explicit field alignments are applied?)

Somewhat related, esp. regarding syntax: #8643

@wooster0
Copy link
Contributor Author

wooster0 commented Oct 1, 2022

Yes, that's basically what it does. It's like applying that same alignment manually to every field in the struct.

Snektron added a commit to Snektron/vulkan-zig that referenced this issue Oct 6, 2022
This commit adds special cases for AccelerationStructureInstanceKHR and
VkAccelerationStructureSRTMotionInstanceNV. These types use bit-packed
fields which are not representable in the current version of the zig
stage 2 compiler. This might change when
ziglang/zig#13009 is resolved.

Fixes #56
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Oct 12, 2022
@daurnimator
Copy link
Contributor

To clarify, this would specify the default alignment of every field within the struct?

I wouldn't expect that from the syntax: i would expect it to be the minimum alignment for the entire struct (i.e. the first field of the struct)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

5 participants