Skip to content

[6.2][sil-isolation-info] When determining isolation of a function arg, use its VarDecl. #80953

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
Apr 24, 2025

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Apr 21, 2025

Explanation: What this patch does is it changes the way that we determine the SILIsolationInfo that we derive from function arguments that are isolated parameters. Previously, we would incorrectly just use self + nom decl to create a SILIsolationInfo... which is obviously wrong. Now instead, we use the correct formulation which is to construct the isolation info frmo the VarDecl of the SILFunctionArgument. This ensures that in cases like the following we correctly realize that the closure's isolation (which is the VarDecl) is the same as self whose isolation is derived from the isolated parameter's VarDecl preventing an error from being emitted:

class S : @unchecked Sendable {}

final class B {
  var s = S()
  var b: Bool = false

  func foo(isolation: isolated Actor = #isolation) async {
    while !b {
      await withTaskGroup(of: Int.self) { group in
        _ = isolation
        self.s = S()
      }
    }
  }
}

Scope: Changes how we compute SILIsolationInfo from SILFunctionArguments that are isolated parameters.

Resolves: rdar://135459885

Main PR: #80905

Risk: Low. This just tweaks how we compute isolation. It shouldn't affect anything beyond situations that use isolated parameters.

Testing: Added tests that show that we emit the correct diagnostic and added a SIL level test that directly shows that we infer the isolation correctly.

Reviewer: @ktoso

…e its VarDecl.

Otherwise, we can be inconsistent with isolations returned by other parts of the
code. Previously we were just treating it always as self + nom decl, which is
clearly wrong if a type is not self (e.x.: if it is an isolated parameter).

rdar://135459885
(cherry picked from commit 0ece31e)
@gottesmm gottesmm requested a review from a team as a code owner April 21, 2025 17:58
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm gottesmm changed the title [sil-isolation-info] When determining isolation of a function arg, use its VarDecl. [6.2][sil-isolation-info] When determining isolation of a function arg, use its VarDecl. Apr 21, 2025
@@ -13,9 +13,6 @@ actor Test {
func withTaskLocal(isolation: isolated (any Actor)? = #isolation,
_ body: (consuming NonSendableValue, isolated (any Actor)?) -> Void) async {
Self.$local.withValue(12) {
// Unexpected errors here:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

NOTE: We already did not emit this error. But this PR exercised the code in this area and when I was working on it the error came back, so I looked at it. The comment here is from when we still emitted the error here (and I put in my previous fix), so I removed it to prevent any confusion.

if (getKind() != Kind::Actor)
return false;
return getActorIsolation() == actorIsolation;
return getActorIsolation() == other;
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 did this renaming since SILIsolationInfo has a field called actorIsolation. It can get confusing what one is referring to int he debugger.

@gottesmm
Copy link
Contributor Author

@swift-ci test macOS platform

@gottesmm
Copy link
Contributor Author

@swift-ci test macOS platform

@gottesmm
Copy link
Contributor Author

@swift-ci clean test macOS platform

@gottesmm gottesmm merged commit da57f96 into swiftlang:release/6.2 Apr 24, 2025
5 checks passed
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.

3 participants