Skip to content

[6.0][region-isolation] When determining isolation from a class_method, check for global actor isolation first. #75045

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
merged 1 commit into from
Jul 8, 2024

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Jul 7, 2024

Explanation:Before this change in the following code, we would say that message is isolated to the actor instead of the global actor isolation of the actor's method:

class Message { ... }

actor MessageHolder {
  @MainActor func hold(_ message: Message) { ... }
}

@MainActor
func sendMessage() async {
    let messageHolder = MessageHolder()
    let message = Message()
    // We identified messageHolder.hold as being MessageHolder isolated
    // instead of main actor isolated.
    messageHolder.hold(message)
    Task { @MainActor in print(message) }
}

It was just b/c we were checking the global actor bit on the field after checking for if it is apart of an actor. With this change, we swap the order and I split up/commented the logic in this part of the code to separate different cases that we are handling to make it easier to understand/prevent future errors.

Radars:

  • rdar://130980933

Original PRs:

Risk: Low. This just tweaks the behavior around how SIL isolation info identifies SILIsolationInfo of class methods. It doesn't touch the rest of the compiler... so any potential problems would be localized to class_method making this a targeted fix. Given the simplicity of the change, I do not expect any follow on problems.
Testing: Added/Ran tests
Reviewer: N/A

…eck for global actor isolation first.

Before this change in the following code, we would say that message is isolated to the actor instead of the global actor isolation of the actor's method:

```swift
class Message { ... }

actor MessageHolder {
  @mainactor func hold(_ message: Message) { ... }
}

@mainactor
func sendMessage() async {
    let messageHolder = MessageHolder()
    let message = Message()
    // We identified messageHolder.hold as being MessageHolder isolated
    // instead of main actor isolated.
    messageHolder.hold(message)
    Task { @mainactor in print(message) }
}
```

I also used this as an opportunity to simplify the logic in this part of the
code. Specifically, I had made it so that multiple interesting cases were
handled in the same conditional statement in a manner that it made it hard to
know which cases were actually being handled and why it was correct. Now I split
that into two separate if statements with comments that make it clear what we
are actually trying to pattern match against.

rdar://130980933
(cherry picked from commit 0a06c00)
@gottesmm gottesmm requested a review from a team as a code owner July 7, 2024 18:50
@gottesmm
Copy link
Contributor Author

gottesmm commented Jul 7, 2024

@swift-ci test

@@ -180,6 +180,12 @@ class ActorIsolation {
return parameterIndex;
}

/// Returns true if this actor-instance isolation appllies to the self
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: appllies -> applies

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll fix that on main. This is for a cherry-pick to 6.0.

@gottesmm gottesmm changed the title [region-isolation] When determining isolation from a class_method, check for global actor isolation first. [6.0][region-isolation] When determining isolation from a class_method, check for global actor isolation first. Jul 7, 2024
@gottesmm gottesmm merged commit 23d2b28 into swiftlang:release/6.0 Jul 8, 2024
5 checks passed
@gottesmm gottesmm deleted the releaes/6.0-rdar130980933 branch July 8, 2024 17:55
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.

4 participants