Skip to content
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

closure isolation #2322

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

sophiapoirier
Copy link
Contributor

No description provided.

@sophiapoirier sophiapoirier force-pushed the closure-isolation branch 3 times, most recently from e2315b0 to ef0d6b2 Compare February 15, 2024 21:08
```swift
actor A {
func isolate() {
Task { [isolated self] in
Copy link

Choose a reason for hiding this comment

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

Does this imply the following scenarios?

func isolate(on otherActor: some AnyActor) {
  Task { [isolated otherActor] in
      // Valid
  }
}
func isolate(on otherActor: some AnyActor) {
  Task { [isolated otherActor] in
     self.bool.toggle() // Fails compilation because `otherActor` isolation does not match `self`'s isolation
  }
}
protocol Toggleable {
  func toggle()
}

func isolate(on otherActor: some AnyActor & Toggleable) {
  Task { [isolated otherActor] in
    otherActor.toggle() // Successful, because this Task is isolated to `otherActor`'s isolation
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(Let me preface by saying that this proposal isn't fully baked yet, hence not having been pitched or added anyone to the PR yet.)

The first example, it is unclear to me what is "valid" given that the body of the closure does not do anything? But the syntax for the isolation capture is valid, and the capture will be isolated to otherActor.

The second example correct will fail.

The third example yes correct as well.

@rjmccall rjmccall added workgroup: needs implementation This proposal needs more implementation work before it can be reviewed LSG Contains topics under the domain of the Language Steering Group labels Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LSG Contains topics under the domain of the Language Steering Group workgroup: needs implementation This proposal needs more implementation work before it can be reviewed
Projects
None yet
5 participants