Skip to content

[5.5-05142021][ConstraintSystem] Detect passing sync closure to async argument early #37480

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

Conversation

xedin
Copy link
Contributor

@xedin xedin commented May 18, 2021

Cherry-pick of (main) #37430, (5.5) #37479


  • Explanation:

This helps in situations where there are multiple overloads which
differ only in async effect of their parameters. Passing sync argument
to a sync parameter is always preferred and when detected early
allows solver to avoid some of the duplicate work re-solving for
the rest of the path e.g.

func test<T>(_: () -> T) {}
func test<T>(_: () async -> T) {}

test {
  // sync work
}.op(...)

In this case since closure is synchronous first overload of test
is always preferred (when it's a match) and solver can skip re-checking
body of the closure and op call when it encounters async version.

This helps in situations where there are multiple overloads which
differ only in async effect of their parameters. Passing sync argument
to a sync parameter is always preferred and when detected early
allows solver to avoid some of the duplicate work re-solving for
the rest of the path e.g.

```swift
func test<T>(_: () -> T) {}
func test<T>(_: () async -> T) {}

test {
  // sync work
}.op(...)
```

In this case since closure is synchronous first overload of `test`
is always preferred (when it's a match) and solver can skip re-checking
body of the closure and `op` call when it encounters `async` version.

Resolves: rdar://77942193
(cherry picked from commit ace4d3a)
@xedin xedin added the r5.5 label May 18, 2021
@xedin xedin changed the title [5.5][ConstraintSystem] Detect passing sync closure to async argument early [5.5-05142021][ConstraintSystem] Detect passing sync closure to async argument early May 18, 2021
@xedin
Copy link
Contributor Author

xedin commented May 19, 2021

@swift-ci please test

@xedin xedin merged commit 17391a5 into swiftlang:release/5.5-05142021 May 19, 2021
@AnthonyLatsis AnthonyLatsis added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.5 labels Jan 8, 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.5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants