Skip to content

[Experiment] One-way closure parameters #32215

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 6, 2020

Conversation

DougGregor
Copy link
Member

Introduce an experimental mode (behind the flag
experimental-one-way-closure-params) that places one-way
constraints between closure parameter types and references to those
parameters within the body of the closure. The intent here is to
break up constraint systems further, potentially improving type
checking performance and making way for larger closure bodies to be
supported.

This is a source-breaking change when the body of a single-expression
closure is used to determine the parameter types. One obvious example
is when there is no contextual type, e.g.,

let _ = { $0 + 1 }

this type-checks today because 1 becomes Int, which matches the
+ overload with the type (Int, Int) -> Int, determining the
parameter type Int for the closure. Such code would not type-check
with one-way constraints.

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@xedin
Copy link
Contributor

xedin commented Jun 6, 2020

@DougGregor This failure is actually want is preventing my PR for BindParam as well because currently it's possible to infer inout from @lvalue used in the body e.g. _ = { $0 = 1 }. I managed to make that one work but there are more complicated examples of the behavior is SwiftPM and in the test suite.

@DougGregor
Copy link
Member Author

@DougGregor This failure is actually want is preventing my PR for BindParam as well because currently it's possible to infer inout from @lvalue used in the body e.g. _ = { $0 = 1 }. I managed to make that one work but there are more complicated examples of the behavior is SwiftPM and in the test suite.

Ah, tricky, tricky. Maybe we can (temporarily?) patch things up in SwiftDriver and SwiftPM to at least get a complete set of results, but it might be that one-way constraints cannot be used for single-expression closures. Or maybe for closures involving $ variables.

@xedin
Copy link
Contributor

xedin commented Jun 6, 2020

Yeah, if I remember correctly there were some compatibility suite failures with that as well.

Introduce an experimental mode (behind the flag
`experimental-one-way-closure-params`) that places one-way
constraints between closure parameter types and references to those
parameters within the body of the closure. The intent here is to
break up constraint systems further, potentially improving type
checking performance and making way for larger closure bodies to be
supported.

This is a source-breaking change when the body of a single-expression
closure is used to determine the parameter types. One obvious example
is when there is no contextual type, e.g.,

    let _ = { $0 + 1 }

this type-checks today because `1` becomes `Int`, which matches the
`+` overload with the type `(Int, Int) -> Int`, determining the
parameter type `Int` for the closure. Such code would not type-check
with one-way constraints.
@DougGregor DougGregor force-pushed the one-way-closure-params branch from 49f3ab3 to 6b2dfad Compare June 6, 2020 05:48
@DougGregor DougGregor marked this pull request as ready for review June 6, 2020 05:48
@DougGregor DougGregor marked this pull request as draft June 6, 2020 05:49
@DougGregor DougGregor force-pushed the one-way-closure-params branch from 6b2dfad to 64f903f Compare June 6, 2020 05:55
@DougGregor DougGregor marked this pull request as ready for review June 6, 2020 05:56
@DougGregor
Copy link
Member Author

Here's just the experimental flag, which includes the semantics we're going to need elsewhere. The "one way by default" experiment is over at #32222.

@DougGregor
Copy link
Member Author

@swift-ci please smoke test

1 similar comment
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci smoke test Linux

@DougGregor DougGregor merged commit 62b2570 into swiftlang:master Jun 6, 2020
@DougGregor DougGregor deleted the one-way-closure-params branch June 6, 2020 18:59
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