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

Proposal: strict ordering of PtrTypeStart and ArrayTypeStart qualifiers #2992

Open
andersfr opened this issue Aug 2, 2019 · 2 comments
Open
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@andersfr
Copy link
Contributor

andersfr commented Aug 2, 2019

The pointer and array types can be qualified with align, const, volatile and allowzero.

In the current grammar they are specified as any amount and no specific ordering. The reality is that they can only occur once.

Having relaxed ordering gives no particular benefit to the language and can potentially confuse users into believing the order carries meaning.

Parsing can also be performed more efficiently with strict ordering.

I propose that we fix the order changing them into the following:

PrefixTypeOp
     / ArrayTypeStart KEYWORD_allowzero? ByteAlign? KEYWORD_const? KEYWORD_volatile?
     / PtrTypeStart KEYWORD_allowzero? (KEYWORD_align LPAREN Expr (COLON INTEGER COLON INTEGER)? RPAREN)? KEYWORD_const? KEYWORD_volatile?

EDIT: Moved KEYWORD_allowzero? first to be consistent with zig fmt

@daurnimator daurnimator added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Aug 2, 2019
@hryx
Copy link
Sponsor Contributor

hryx commented Aug 2, 2019

See a brief previous discussion of this here: #2405 (comment)

@andrewrk andrewrk added this to the 0.6.0 milestone Aug 2, 2019
@andersfr
Copy link
Contributor Author

andersfr commented Aug 3, 2019

If you run your code through zig fmt you will automatically get a strict ordering of these qualifiers. This is afaik the only place you will observe a reordering.

All existing code can thus be made into compliance with this chance by simply running the formatter once.

Notable examples of strict ordering are FnProto and VarDecl with both pre and post qualifiers (even more so in a TopDecl context).

@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Feb 10, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 27, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jul 9, 2023
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

4 participants