Skip to content

[Variadic Generics] Add a new type syntax node and parsing support for explicit pack references. #1134

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 4 commits into from
Dec 13, 2022

Conversation

hborla
Copy link
Member

@hborla hborla commented Dec 11, 2022

  • Add a new type node, PackReferenceType, for pack references spelled with a contextual each keyword.
  • Add parsing support to produce PackReferenceTypeSyntax when the contextual each keyword is applied to a type.

@hborla
Copy link
Member Author

hborla commented Dec 11, 2022

@swift-ci please test

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Could you add a couple of test cases? Interesting test cases that come to my mind are

  • the example in your PR description
  • each MyType as a parameter / return type (I assume that this should be invalid but we can/should defer diagnostic generation for this case to ASTGen since we cannot forbid each MyType in the current SwiftSyntax tree)

@@ -123,6 +123,14 @@
Child('Ellipsis', kind='EllipsisToken')
]),

# pack-reference-type -> 'each' type
Node('PackReferenceType', name_for_diagnostics='pack reference', kind='Type',
Copy link
Member

Choose a reason for hiding this comment

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

This node is identical to the ConstrainedSugarType. What do you think about using the same node type for it instead of introducing a new node? I'm open to naming suggestions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. You're right that the syntactic structure is the same (though it's parsed slightly differently), but conceptually a pack element type is very different from a constrained sugar type. Do you think that most tooling operating on these type syntax nodes would want to treat pack elements the same as constraint types? The only reason why I added a new syntax node is because I added a new TypeRepr on the Swift side to make type resolution easier, since the resolution logic is completely different.

Copy link
Member

Choose a reason for hiding this comment

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

It was an open question, maybe I should have phrased that more clearly. It was motivated because I’m merging the nodes for #available and #unavailable in #1125 and that simplified quite a few things. If you think it’s better to have different nodes for some/any and each, I’m totally fine with it.

@hborla
Copy link
Member Author

hborla commented Dec 12, 2022

Could you add a couple of test cases? Interesting test cases that come to my mind are

I have test cases in my PR to the Swift repo here: https://github.com/apple/swift/pull/62509/files#diff-b4b3fbedbd5cb01a2a671c3e6e039e0bdc87f29ae3744e6aa6a713b32bb9ad04. These should exercise this code through parser validation. Do I need to add test cases here in addition to those?

@hborla hborla requested a review from ahoppen December 12, 2022 21:51
@hborla
Copy link
Member Author

hborla commented Dec 12, 2022

@ahoppen I added some test cases in 91035df! How do they look?

@hborla hborla force-pushed the explicit-pack-reference-keyword branch from 91035df to 227fe88 Compare December 13, 2022 03:34
@hborla
Copy link
Member Author

hborla commented Dec 13, 2022

@swift-ci please test

1 similar comment
@hborla
Copy link
Member Author

hborla commented Dec 13, 2022

@swift-ci please test

Copy link
Member

@ahoppen ahoppen left a comment

Choose a reason for hiding this comment

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

Thanks for adding the test cases. LGTM 👍

@hborla hborla force-pushed the explicit-pack-reference-keyword branch from 227fe88 to ded777e Compare December 13, 2022 16:13
@hborla
Copy link
Member Author

hborla commented Dec 13, 2022

@swift-ci please test

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