Skip to content

Conversation

kavon
Copy link
Member

@kavon kavon commented Jan 6, 2023

Cherry-pick of #62153

@kavon
Copy link
Member Author

kavon commented Jan 6, 2023

@swift-ci please test

It's ok to drop the global-actor qualifier `@G` from a function's type if:

- the cast is happening in a context isolated to global-actor `G`
- the function value will not be `@Sendable`
- the function value is not `async`

It's primarily safe to drop the attribute because we're already in the
same isolation domain. So it's OK to simply drop the global-actor
if we prevent the value from later leaving that isolation domain.
This means we no longer need to warn about code like this:

```
@mainactor func doIt(_ x: [Int], _ f: @mainactor (Int) -> ()) {
  x.forEach(f)
// warning: converting function value of type '@mainactor (Int) -> ()' to '(Int) throws -> Void' loses global actor 'MainActor'
}
```

NOTE: this implementation is a bit gross in that the constraint solver
might emit false warnings about casts it introduced that are actually
safe. This is mainly because closure isolation is only fully determined
after constraint solving. See the FIXME's for more details.

resolves rdar://94462333
@kavon kavon force-pushed the 5.8-lose-main-actor branch from 5cfd8fd to af3995f Compare January 9, 2023 23:25
@kavon
Copy link
Member Author

kavon commented Jan 9, 2023

@swift-ci please test

1 similar comment
@kavon
Copy link
Member Author

kavon commented Jan 11, 2023

@swift-ci please test

@kavon kavon marked this pull request as ready for review January 11, 2023 22:31
@kavon kavon requested a review from DougGregor January 12, 2023 04:06
Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an important usability improvement on the way to some larger cleanups. We'll take it for 5.8

@DougGregor DougGregor merged commit 22d4414 into swiftlang:release/5.8 Jan 12, 2023
@kavon kavon deleted the 5.8-lose-main-actor branch January 17, 2023 19:42
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants