Skip to content

Commit e744e35

Browse files
authored
Merge pull request #82384 from slavapestov/implied-isolated-conformance-6.2
[6.2] Sema: Expand isolated conformance inference to consider conformances to inherited protocols
2 parents 484d7c7 + f9a6432 commit e744e35

File tree

4 files changed

+35
-5
lines changed

4 files changed

+35
-5
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8250,16 +8250,28 @@ ActorIsolation swift::inferConformanceIsolation(
82508250
return nominalIsolation;
82518251
}
82528252

8253-
bool anyIsolatedWitness = false;
82548253
auto protocol = conformance->getProtocol();
8255-
for (auto requirement : protocol->getMembers()) {
8256-
if (isa<TypeDecl>(requirement))
8254+
8255+
// Also check the value witnesses of each implied conformance to every
8256+
// inherited protocol, recursively.
8257+
for (auto req : protocol->getRequirementSignature().getRequirements()) {
8258+
if (req.getKind() != RequirementKind::Conformance ||
8259+
!req.getFirstType()->isEqual(protocol->getSelfInterfaceType()))
82578260
continue;
82588261

8259-
auto valueReq = dyn_cast<ValueDecl>(requirement);
8260-
if (!valueReq)
8262+
auto *assocConf = conformance->getAssociatedConformance(
8263+
req.getFirstType(), req.getProtocolDecl()).getConcrete();
8264+
auto isolation = assocConf->getIsolation();
8265+
if (isolation.isGlobalActor())
8266+
return isolation;
8267+
}
8268+
8269+
bool anyIsolatedWitness = false;
8270+
for (auto requirement : protocol->getProtocolRequirements()) {
8271+
if (isa<TypeDecl>(requirement))
82618272
continue;
82628273

8274+
auto valueReq = cast<ValueDecl>(requirement);
82638275
auto witness = conformance->getWitnessDecl(valueReq);
82648276
if (!witness)
82658277
continue;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public protocol P {
2+
func f()
3+
}
4+
5+
public protocol PDerived: P {}

test/Concurrency/isolated_conformance_inference.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,7 @@ class InferMeDefaults {
9292
var someGlobalActorState: any P2.Type = DifferingConformances.self // expected-error{{global actor 'SomeGlobalActor'-isolated default value in a main actor-isolated context}}
9393
var bothState: any (P & P2).Type = DifferingConformances.self // expected-error{{default argument cannot be both main actor-isolated and global actor 'SomeGlobalActor'-isolated}}
9494
}
95+
96+
protocol PDerived: P {}
97+
98+
@MainActor struct ImpliedConformanceInference: PDerived { func f() {} }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/isolated_conformance_other.swiftmodule %S/Inputs/isolated_conformance_other.swift -swift-version 6
3+
// RUN: %target-typecheck-verify-swift -I %t -swift-version 6 -enable-upcoming-feature InferIsolatedConformances -default-isolation MainActor -swift-version 6
4+
// REQUIRES: swift_feature_InferIsolatedConformances
5+
6+
import isolated_conformance_other
7+
8+
struct S1: P { func f() {} }
9+
struct S2: PDerived { func f() {} }

0 commit comments

Comments
 (0)