-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Variadic Generics] Add a contextual each
keyword for pack element references in pack expansion patterns.
#62582
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
Conversation
1ce283a
to
41448ba
Compare
…he 'each' keyword.
…pack element generic signature.
… Bind constraints, vend potential bindings through PotentialBindings::infer. This allows for bidirectional binding inference from the pack type to the element type and vice versa.
…cation for PackElementExpr.
1599f43
to
9bae784
Compare
…ns followed by an unlabeled element until pack type variables are resolved.
9bae784
to
472bd1f
Compare
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
: public StoredPointerElement<GenericEnvironment> { | ||
public: | ||
OpenedPackElement(GenericEnvironment *env) | ||
: StoredPointerElement(PathElementKind::OpenedPackElement, env) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we assert that env
is never null in here?
|
||
auto *loc = constraint->getLocator(); | ||
auto openedElement = | ||
loc->getLastElementAs<LocatorPathElt::OpenedPackElement>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably castLastElementTo
is better here
This change parses a contextual
each
keyword in expressions asPackElementExpr
, and changesPackExpansionExpr
to represent pack element bindings asPackElementExpr
. The corresponding SwiftSyntax PR is swiftlang/swift-syntax#1146.In addition to clarifying for the programmer which expressions in a pack expansion are expanded, making pack elements explicit in the AST has a number of implementation benefits:
...
is a pack expansion or a postfix operator call.PackElementOf
constraint.PotentialBindings
infrastructure, and type information can flow bidirectionally (from the pack type to the element type and vice versa).