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

Move type alias attribute validation to parser #1916

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

evantypanski
Copy link
Contributor

Closes #1898

This just moves the logic from #1890 to an allow list of types that can have attributes in the parser so that we avoid a hacky check. I don't really like checks in the parser like this very much, but since this fixes a weird validation I think it's ok.

The rest of this is just on what I chose not to do, which may be interesting depending what you think. That's all on the topic/etyp/cleanup-parsing-attributes branch now.

My initial impression was that attributes should apply to types, then remove opt_attributes from the type_decl. That technically seems possible, but I'd hardly call it a cleanup. It essentially requires duplicating the attributes logic into many UnqualifiedType implementations (struct, enum, etc. but also like exception).

This goes into hilti world, so now the hilti parser needs changed, and once you get there all bets are off. You can use the &on-heap attribute on a lot of things, which is a declaration attribute. That's because what that means for a type is just that it becomes a value_ref. So now we think about these attributes on declarations as type attributes, which just doesn't intuitively make sense. I guess you could try to have both, but since there isn't a great distinction from syntax alone, it's hard.

There's a fair bit more, but I think the attribute changes should try to stay minimal unless we're going to really rework them, which I kind of advocated for in the issue this is closing... but that's a big change :)

As an added point: The branch I did that on had some positive consequences - tests like unsupported_attribute.spicy flag an error on an attribute, but the range given does not even encompass the attribute. I added a continuation of #1899 for unit's setAttributes for that case just as an added bonus.

@evantypanski evantypanski requested a review from bbannier November 5, 2024 21:12
bbannier
bbannier previously approved these changes Nov 7, 2024
spicy/toolchain/src/compiler/parser/parser.yy Show resolved Hide resolved
@evantypanski evantypanski force-pushed the topic/etyp/cleanup-parsing-attributes-2 branch from 4e9b286 to 83131ca Compare November 7, 2024 13:41
Closes #1898

This was originally in a validator, but there's some sense that this is
a parsing issue since attributes should not be allowed at all on most
constructs of that form.

Note that a lot of the cleanup here was meant to span removing the
`opt_attributes` field in `type_decl` altogether, but the fallout from
that is pretty large. It ended up being less cleanup and more
rearchitecting. This way still avoids the hacky test for type aliases in
the validator while not changing the AST structure.
@bbannier bbannier force-pushed the topic/etyp/cleanup-parsing-attributes-2 branch from 83131ca to 0744bab Compare November 7, 2024 14:38
@bbannier bbannier merged commit 99049d8 into main Nov 7, 2024
9 of 20 checks passed
@bbannier bbannier deleted the topic/etyp/cleanup-parsing-attributes-2 branch November 7, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disallow attributes on "type aliases" in parser
2 participants