-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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
[TypeChecker] SE-0326: Enable multi-statement closure inference by default #39989
[TypeChecker] SE-0326: Enable multi-statement closure inference by default #39989
Conversation
@hborla This is a draft because I'd like to wait for the Core Team decision on this and if everything goes fine I'm just going to drop frontend flag in a follow-up commit... |
@swift-ci please clean test |
@swift-ci please test source compatibility |
Build failed |
1d84a6d
to
3ddd414
Compare
@swift-ci please clean test |
@swift-ci please test source compatibility |
3ddd414
to
fa78540
Compare
@swift-ci please test source compatibility |
@swift-ci please clean test |
Build failed |
Infra issues, both source compat and macOS failed with |
@swift-ci please test macOS platform |
@swift-ci please test source compatibility |
Build failed |
@swift-ci please clean test macOS platform |
…ambiguous If there are multiple overloads and all of them require closure to have a parameter, let's diagnose that as such instead of ambiguity.
…d code While building a closure to inject `checkExpect` code, clone member references associated with assignment. Re-using AST nodes is generally invalid. This is visible with multi-statement closure inference enabled, because the body is type-checked together with enclosing context and both elements end up sharing `DeclRefExpr` and `MemberRefExpr`s.
This preserves previous behavior where multi-statement closures where always type-checked without context.
…Unchecked` flag Propagate `LeaveClosureBodyUnchecked` flag from `typeCheckASTNodeAtLoc` down to declaration checker to skip checking closures associated with pattern binding entry initializers. This is no-op until multi-statement inference becomes enabled by default.
…es when inference is enabled When multi-statement closure inference is enabled it's body is type-checked together with enclosing context, so they could be walked directly just like single-expressions ones.
… closures Extract diagnostic into a method and use it while type-checking `for-in` in top-level code and in closures.
…t inference is enabled Scope down previous check to avoid walking into patterns that appear in multi-statement closures if the inference is enabled.
Preserve pre SE-0326 for code completion, so it could be ported gradually.
Put some common logic related to local declaration to the base class and refactor other walkers to use it instead of `ASTWalker`.
…ic parameter holes Closure result type or generic parameter associated with such a location could bw inferred from a body of a multi-statement closure (when inference is enabled), so we need to give closure a chance to run before attemtping a hole for such positions in diagnostic mode.
Each of the elements in the result builder has to be fully pre-checked now that multi-statement inference has been enabled.
fa78540
to
b231cde
Compare
@hborla I dropped two commits that removed the frontend, instead for the time being it would just be enabled by default. We can clean it up later. |
@swift-ci please clean 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.
The diagnostic changes in the test suite look awesome 👍🏻
@swift-ci please test Windows platform |
3 similar comments
@swift-ci please test Windows platform |
@swift-ci please test Windows platform |
@swift-ci please test Windows platform |
.self
use, local declarations etc.)LeaveClosureBodyUnchecked
flagDebuggerTestingTransform
to avoid re-using AST nodes