Skip to content

[Concurrency] Look for explicit 'nonisolated' when getting isolation from protocol conformances. #79893

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

simanerush
Copy link
Member

If the protocol from the conformance list explicitly strips off global actor with nonisolated, make sure to look for this explicit isolation source when computing the resulting isolation; to prevent accidental global actor inference on the conforming type.

Resolves rdar://144798727.

@simanerush
Copy link
Member Author

@swift-ci please smoke test

@simanerush simanerush force-pushed the fix-explicit-nonisolated-proto-inference branch from 0240c50 to 5825021 Compare March 11, 2025 17:18
@simanerush
Copy link
Member Author

@swift-ci please smoke test macOS

@simanerush
Copy link
Member Author

@swift-ci please smoke test

@AnthonyLatsis AnthonyLatsis self-assigned this Mar 20, 2025
@AnthonyLatsis
Copy link
Collaborator

@swift-ci please smoke test macOS

@simanerush simanerush force-pushed the fix-explicit-nonisolated-proto-inference branch 3 times, most recently from ea05478 to ce45f27 Compare March 21, 2025 21:05
@simanerush
Copy link
Member Author

@swift-ci please smoke test

@simanerush simanerush force-pushed the fix-explicit-nonisolated-proto-inference branch from ce45f27 to 5143a40 Compare March 22, 2025 06:03
@xedin xedin force-pushed the fix-explicit-nonisolated-proto-inference branch from 5143a40 to 083962d Compare June 16, 2025 22:56
@xedin xedin force-pushed the fix-explicit-nonisolated-proto-inference branch from 083962d to 82497af Compare June 16, 2025 22:58
@xedin
Copy link
Contributor

xedin commented Jun 16, 2025

@swift-ci please test

@hborla
Copy link
Member

hborla commented Jun 17, 2025

I might be missing it but I think the change is missing the motivating test case, which is something like this:

struct TestIsolated: Refined {
  func test() {
  }
}

nonisolated func callTest(t: TestIsolated) {
  t.test() // okay
}

Without this change, the explicit nonisolated on the Refined protocol would not block global actor inference on TestIsolated, inferred from GloballyIsolated (which Refined refines)

@xedin
Copy link
Contributor

xedin commented Jun 17, 2025

@hborla
Copy link
Member

hborla commented Jun 17, 2025

Is that missing a protocol requirement? NonisolatedStruct does not conform to any protocols.

@xedin
Copy link
Contributor

xedin commented Jun 17, 2025

A does conform to Refined, NonisolatedStruct just uses for nonisolated function. We can add explicitly nonisolated global as well which gets A as parameter if you'd prefer.

@hborla
Copy link
Member

hborla commented Jun 17, 2025

A does conform to Refined, NonisolatedStruct just uses for nonisolated function. We can add explicitly nonisolated global as well which gets A as parameter if you'd prefer.

Oh I see it, I overlooked A because it isn't a new type in this PR. This is fine, thank you for explaining!

…make witnesses nonisolated

Even if the requirement is stated on an isolated protocol if the
conformance is implied by a nonisolated one all of the requirements
and witnesses should be nonisolated.
@xedin
Copy link
Contributor

xedin commented Jun 17, 2025

@swift-ci please test

@xedin xedin merged commit 84cb3c8 into swiftlang:main Jun 17, 2025
5 checks passed
xedin added a commit to xedin/swift that referenced this pull request Jun 24, 2025
…override `nonisolated`.

Follow-up for swiftlang#79893.

More than one global actor isolated conformance at any level
creates a clash and conforming type should be inferred as `nonisolated`.

Resolves: rdar://154202375
xedin added a commit to xedin/swift that referenced this pull request Jun 25, 2025
…override `nonisolated`.

Follow-up for swiftlang#79893.

More than one global actor isolated conformance at any level
creates a clash and conforming type should be inferred as `nonisolated`.

Resolves: rdar://154202375
(cherry picked from commit 2e1fe44)
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.

5 participants