Skip to content

closure isolation#2322

Open
sophiapoirier wants to merge 17 commits intoswiftlang:mainfrom
sophiapoirier:closure-isolation
Open

closure isolation#2322
sophiapoirier wants to merge 17 commits intoswiftlang:mainfrom
sophiapoirier:closure-isolation

Conversation

@sophiapoirier
Copy link
Copy Markdown
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
Copy Markdown
Member

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
Copy Markdown
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

class New {
public init(@inheritsIsolation operation: () async)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These two examples both have a tiny typo in them. They are missing a -> Void.

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

Development

Successfully merging this pull request may close these issues.

5 participants