Skip to content

Add infrastructure for automated validation of syntax node structure #1748

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

Merged
merged 1 commit into from
Jun 19, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jun 8, 2023

The goal here is to generalize the API inconsistency reported by @AnthonyLatsis and automatically detect them.

There are valid reasons for nodes or children to violate these base rules. My idea is that we note these exceptions in expected failures, ideally with a sort explanation that motivates the deviation from standard naming rules.

We aren’t running these tests at the moment yet. I’d like to merge them as a starting point for API improvement ideas at the moment.

The current rules are

@ahoppen ahoppen requested review from rintaro and bnbarham June 8, 2023 23:31
@ahoppen
Copy link
Member Author

ahoppen commented Jun 8, 2023

@swift-ci Please test

Copy link
Contributor

@kimdv kimdv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good.
Maybe when it's merged we could add issues for the failures we want to be fixed as they are good first issues for newcomers who want to join the community 🙌

@ahoppen ahoppen force-pushed the ahoppen/syntax-node-validation branch from f613daf to a09e768 Compare June 9, 2023 15:32
@ahoppen
Copy link
Member Author

ahoppen commented Jun 9, 2023

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Jun 9, 2023

@swift-ci Please test Windows

@ahoppen ahoppen force-pushed the ahoppen/syntax-node-validation branch from a09e768 to b0d3092 Compare June 14, 2023 14:34
The goal here is to generalize the API inconsistency reported by @AnthonyLatsis and automatically detect them.

There are valid reasons for nodes or children to violate these base rules. My idea is that we note these exceptions in expected failures, ideally with a sort explanation that motivates the deviation from standard naming rules.

We aren’t running these tests at the moment yet. I’d like to merge them as a starting point for API improvement ideas at the moment.

The current rules are
- All nodes with base kind e.g. `ExprSyntax` should end with `ExprSyntax`.
- If a child has a single keyword as its choice, it should be named `*Keyword` (e.g. `ImportKeyword`)
- If a child has a single non-keyword token kind, name it the same as the the token choice (e.g. `LeftParen`)
- If a token only has keyword token choices, its name should end with `Keyword`.
- Children that have the same type also have the same child name.
- Every node that can conform to a trait does so
@ahoppen ahoppen force-pushed the ahoppen/syntax-node-validation branch from b0d3092 to 02a0c5d Compare June 14, 2023 14:51
@ahoppen
Copy link
Member Author

ahoppen commented Jun 14, 2023

@swift-ci Please test

@bnbarham
Copy link
Contributor

Nice, I'd say the rules generally make sense. And we can always have expected failures for when we really want to differ for some reason. Thanks Alex!

@ahoppen ahoppen merged commit e6db8ad into swiftlang:main Jun 19, 2023
@ahoppen ahoppen deleted the ahoppen/syntax-node-validation branch June 19, 2023 07:31
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.

3 participants