Skip to content

Assert that tokens in the syntax tree match token_choices and text_choices #1180

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
Feb 2, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jan 3, 2023

We currently specify token_choices and text_choices in the Python files but don't enforce that the tokens in the syntax tree actually match these – effectively we are ignoring these properties.

Add assertions that the actual tokens in the syntax tree match the specification and fix a few cases where these assertions were violated.

rdar://103448567

@ahoppen ahoppen marked this pull request as draft January 3, 2023 16:31
@ahoppen ahoppen changed the title WIP: Assert that tokens in the syntax tree match token_choices and text_choices 🚥 #1173 WIP: Assert that tokens in the syntax tree match token_choices and text_choices Jan 14, 2023
@ahoppen ahoppen force-pushed the ahoppen/assert-token-choices branch 3 times, most recently from 897e9b7 to 3f64e22 Compare January 28, 2023 08:08
@ahoppen ahoppen changed the title WIP: Assert that tokens in the syntax tree match token_choices and text_choices Assert that tokens in the syntax tree match token_choices and text_choices 🚥 #1289 Jan 28, 2023
@ahoppen ahoppen marked this pull request as ready for review January 28, 2023 08:20
@ahoppen ahoppen requested review from rintaro and bnbarham January 28, 2023 08:20
@@ -8531,6 +8680,7 @@ public struct RawAccessorDeclSyntax: RawDeclSyntaxNodeProtocol {
_ unexpectedAfterBody: RawUnexpectedNodesSyntax? = nil,
arena: __shared SyntaxArena
) {
assert(accessorKind.tokenKind == .keyword(.get) || accessorKind.tokenKind == .keyword(.set) || accessorKind.tokenKind == .keyword(.didSet) || accessorKind.tokenKind == .keyword(.willSet) || accessorKind.tokenKind == .keyword(.unsafeAddress) || accessorKind.tokenKind == .keyword(.addressWithOwner) || accessorKind.tokenKind == .keyword(.addressWithNativeOwner) || accessorKind.tokenKind == .keyword(.unsafeMutableAddress) || accessorKind.tokenKind == .keyword(.mutableAddressWithOwner) || accessorKind.tokenKind == .keyword(.mutableAddressWithNativeOwner) || accessorKind.tokenKind == .keyword(._read) || accessorKind.tokenKind == .keyword(._modify), "Received \(accessorKind.tokenKind)")
Copy link
Contributor

Choose a reason for hiding this comment

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

These should overlap with the subset right? Wonder if we should autogenerate subsets when there's > 1 kind. I imagine that would be a lot though, maybe only > 3 and then at can have overloads for up to 3 kinds or a subset?

Copy link
Member Author

Choose a reason for hiding this comment

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

That’s the next item on my To-Do list after this PR is merge: “Generate RawTokenKindSubset”. I’m still not entirely sure how exactly we want to decide whether to generate the RawTokenKindSubset, but it’s definitely something we should do.

@_dynamicReplacement(for: <#identifier#>)
@_dynamicReplacement(for : <#identifier#>)
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the whitespace for?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I wanted to fix that. It’s because for is a keyword now and keywords always have trailing space in BasicFormat at the moment. Improving that is a slightly larger change in BasicFormat that I would like to do in a follow-up PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here we go: #1298

@ahoppen ahoppen force-pushed the ahoppen/assert-token-choices branch from 3f64e22 to d581360 Compare January 31, 2023 08:20
…oices

Previously, we specified text_choices and token_chocies in the Python files but we weren’t actually verifying that the tokens we pass into the syntax tree match these expectations. Add assertions that check the token kinds.

rdar://103448567
@ahoppen ahoppen force-pushed the ahoppen/assert-token-choices branch from d581360 to 1cde192 Compare February 2, 2023 07:39
@ahoppen ahoppen changed the title Assert that tokens in the syntax tree match token_choices and text_choices 🚥 #1289 Assert that tokens in the syntax tree match token_choices and text_choices Feb 2, 2023
@ahoppen
Copy link
Member Author

ahoppen commented Feb 2, 2023

@swift-ci Please test

@ahoppen ahoppen merged commit cc8fc77 into swiftlang:main Feb 2, 2023
@ahoppen ahoppen deleted the ahoppen/assert-token-choices branch February 3, 2023 16:39
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.

2 participants