Skip to content

[Concurrency] isolated fixes; ban Array<T> and handle Self in actor #70955

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

ktoso
Copy link
Contributor

@ktoso ktoso commented Jan 17, 2024

This fixes two logic isolated issues:

Seems to have been present for a long time:

  • Due to a typo in the logic "is" vs "has" TypeParameter we allowed Array which doesn't make sense.

Recent, due to #70925 being too permissive in Self handling:

  • Technically self in an actor is handled like self in classess... so @slavapestov explained that we need to handle the following differently:
// TODO: Consider making an actor's Self behave like in a struct, removing this special casing.
//       We could consider changing this, so that self is always Self because we don't allow inheritance of actors.
//       See: https://github.com/apple/swift/issues/70954 and rdar://121091417
actor A2 {
  nonisolated func f1() async {
    await { (self: isolated Self) in }(self)
    // expected-error@-1 {{cannot convert value of type 'A2' to expected argument type 'Self'}}
  }
  nonisolated func f2() async -> Self {
    await { (self: isolated Self) in }(self)
    return self
  }
}

@ktoso
Copy link
Contributor Author

ktoso commented Jan 17, 2024

@swift-ci please smoke test

if (auto ty = dyn_cast<DynamicSelfType>(type)) {
type = ty->getSelfType();
unwrappedType = ty->getSelfType();
Copy link
Member

Choose a reason for hiding this comment

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

I think this needs to happen after unwrapping the optional below, otherwise we will not allow isolated Self?. We do generally allow optional Self as a special case to the covariant Self restrictions.

Copy link
Contributor Author

@ktoso ktoso Jan 18, 2024

Choose a reason for hiding this comment

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

Nice catch, fixing that -- and added tests

@ktoso
Copy link
Contributor Author

ktoso commented Jan 18, 2024

@swift-ci please smoke test

@ktoso ktoso enabled auto-merge (squash) January 18, 2024 03:53
@ktoso ktoso merged commit 14acfb2 into swiftlang:main Jan 18, 2024
@ktoso ktoso deleted the wip-further-concurrency-self-in-actor-fixes branch January 19, 2024 07:56
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