Skip to content

[6.2] Sema: Expand isolated conformance inference to consider conformances to inherited protocols #82384

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

Open
wants to merge 1 commit into
base: release/6.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8167,16 +8167,28 @@ ActorIsolation swift::inferConformanceIsolation(
return nominalIsolation;
}

bool anyIsolatedWitness = false;
auto protocol = conformance->getProtocol();
for (auto requirement : protocol->getMembers()) {
if (isa<TypeDecl>(requirement))

// Also check the value witnesses of each implied conformance to every
// inherited protocol, recursively.
for (auto req : protocol->getRequirementSignature().getRequirements()) {
if (req.getKind() != RequirementKind::Conformance ||
!req.getFirstType()->isEqual(ctx.TheSelfType))
continue;

auto valueReq = dyn_cast<ValueDecl>(requirement);
if (!valueReq)
auto *assocConf = conformance->getAssociatedConformance(
req.getFirstType(), req.getProtocolDecl()).getConcrete();
auto isolation = assocConf->getIsolation();
if (isolation.isGlobalActor())
return isolation;
}

bool anyIsolatedWitness = false;
for (auto requirement : protocol->getProtocolRequirements()) {
if (isa<TypeDecl>(requirement))
continue;

auto valueReq = cast<ValueDecl>(requirement);
auto witness = conformance->getWitnessDecl(valueReq);
if (!witness)
continue;
Expand Down
5 changes: 5 additions & 0 deletions test/Concurrency/Inputs/isolated_conformance_other.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public protocol P {
func f()
}

public protocol PDerived: P {}
4 changes: 4 additions & 0 deletions test/Concurrency/isolated_conformance_inference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@ class InferMeDefaults {
var someGlobalActorState: any P2.Type = DifferingConformances.self // expected-error{{global actor 'SomeGlobalActor'-isolated default value in a main actor-isolated context}}
var bothState: any (P & P2).Type = DifferingConformances.self // expected-error{{default argument cannot be both main actor-isolated and global actor 'SomeGlobalActor'-isolated}}
}

protocol PDerived: P {}

@MainActor struct ImpliedConformanceInference: PDerived { func f() {} }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/isolated_conformance_other.swiftmodule %S/Inputs/isolated_conformance_other.swift -swift-version 6
// RUN: %target-typecheck-verify-swift -I %t -swift-version 6 -enable-upcoming-feature InferIsolatedConformances -default-isolation MainActor -swift-version 6

import isolated_conformance_other

struct S1: P { func f() {} }
struct S2: PDerived { func f() {} }