Skip to content

[5.7][TypeChecker] Rework type-checking of for-in statements #59261

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 4, 2022

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jun 3, 2022

Cherry-pick of #59003


Change the way how for-in statements are type-checked, where a lot of
information has to be recorded in a statement in order for SILGen to generate
appropriate calls to makeIterator and next witnesses.

Instead of just finding a witness, solver would now:

  • Synthesize:
    • Iterator variable with its initializer - $generator = <sequence>.makeIterator();
    • Call to $generator.next() which is called by each loop iteration;
  • Verify that type of pattern is convertible to type of next()

Doing so significantly simplifies SILGen, removes the need to carry type information
in ForEachStmt and enables iterating over existential types.

Resolves: rdar://92177656

@xedin xedin added the r5.7 label Jun 3, 2022
@xedin xedin requested a review from hborla June 3, 2022 21:53
@xedin xedin requested a review from a team as a code owner June 3, 2022 21:53
@xedin
Copy link
Contributor Author

xedin commented Jun 3, 2022

@swift-ci please test

@xedin xedin force-pushed the rdar-92177656-5.7 branch from e28e5be to b73f9cd Compare June 3, 2022 23:29
@xedin
Copy link
Contributor Author

xedin commented Jun 3, 2022

@swift-ci please test

Change the way how `for-in` statements are type-checked, where a lot of
information has to be recorded in a statement in order for SILGen to generate
appropriate calls to `makeIterator` and `next` witnesses.

Instead of just finding a witness, solver would now:

- Synthesize:
  - Iterator variable with its initializer - `$generator = <sequence>.makeIterator()`;
  - Call to `$generator.next()` which is called by each loop iteration;
- Verify that type of pattern is convertible to type of `next()`

Doing so significantly simplifies SILGen, removes the need to carry type information
in `ForEachStmt` and enables iterating over existential types.

Resolves: rdar://92177656
@xedin xedin force-pushed the rdar-92177656-5.7 branch from b73f9cd to 26f1647 Compare June 4, 2022 00:49
@xedin
Copy link
Contributor Author

xedin commented Jun 4, 2022

@swift-ci please test

@xedin xedin merged commit 350e87e into swiftlang:release/5.7 Jun 4, 2022
@AnthonyLatsis AnthonyLatsis added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.7 labels Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.7
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants