Skip to content

[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

Merged
merged 9 commits into from
Dec 16, 2022

Conversation

hborla
Copy link
Member

@hborla hborla commented Dec 14, 2022

This change parses a contextual each keyword in expressions as PackElementExpr, and changes PackExpansionExpr to represent pack element bindings as PackElementExpr. 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:

  • Pack expansion expressions are distinguished syntactically, meaning we don't need overload resolution to determine whether ... is a pack expansion or a postfix operator call.
  • We know exactly which type variables generated during constraint generation represent opened element types, so we can resolve those types through the PackElementOf constraint.
  • Bindings for pack elements can be produced through the standard PotentialBindings infrastructure, and type information can flow bidirectionally (from the pack type to the element type and vice versa).
  • Overall, the representation of pack expansion expressions and the amount of work done in the constraint system are both greatly simplified.

@hborla
Copy link
Member Author

hborla commented Dec 15, 2022

@swift-ci please smoke test

@hborla hborla merged commit d3bc4f5 into swiftlang:main Dec 16, 2022
@hborla hborla deleted the pack-element-expr branch December 16, 2022 16:43
Copy link
Contributor

@xedin xedin left a 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) {}
Copy link
Contributor

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>();
Copy link
Contributor

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

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