Skip to content

Commit 17f2c10

Browse files
authored
Merge pull request swiftlang#75252 from hborla/6.0-isolation-inference-inherited-conformance
[6.0][Concurrency] Don't infer actor isolation from inherited conformances.
2 parents 7765fd6 + 4ee1ee1 commit 17f2c10

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4878,12 +4878,30 @@ getIsolationFromWitnessedRequirements(ValueDecl *value) {
48784878
/// are directly specified on the type.
48794879
static std::optional<ActorIsolation>
48804880
getIsolationFromConformances(NominalTypeDecl *nominal) {
4881+
auto &ctx = nominal->getASTContext();
4882+
48814883
if (isa<ProtocolDecl>(nominal))
48824884
return std::nullopt;
48834885

48844886
std::optional<ActorIsolation> foundIsolation;
4885-
for (auto proto :
4886-
nominal->getLocalProtocols(ConformanceLookupKind::NonStructural)) {
4887+
for (auto conformance :
4888+
nominal->getLocalConformances(ConformanceLookupKind::NonStructural)) {
4889+
4890+
// Don't include inherited conformances. If a conformance is inherited
4891+
// from a superclass, the isolation of the subclass should be inferred
4892+
// from the superclass, which is done directly in ActorIsolationRequest.
4893+
// If the superclass has opted out of global actor inference, such as
4894+
// by conforming to the protocol in an extension, then the subclass should
4895+
// not infer isolation from the protocol.
4896+
//
4897+
// Gate this change behind an upcoming feature flag; isolation inference
4898+
// changes can break source in language modes < 6.
4899+
if (conformance->getKind() == ProtocolConformanceKind::Inherited &&
4900+
ctx.LangOpts.hasFeature(Feature::GlobalActorIsolatedTypesUsability)) {
4901+
continue;
4902+
}
4903+
4904+
auto *proto = conformance->getProtocol();
48874905
switch (auto protoIsolation = getActorIsolation(proto)) {
48884906
case ActorIsolation::ActorInstance:
48894907
case ActorIsolation::Unspecified:

test/Concurrency/global_actor_inference_swift6.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,13 @@ class C2: MainActorSuperclass, InferenceConflictWithSuperclass {
213213
}
214214

215215

216+
class ConformInExtension {}
217+
extension ConformInExtension: InferMainActor {}
218+
219+
class InheritConformance: ConformInExtension {
220+
func f() {}
221+
}
222+
223+
func testInheritedMainActorConformance() {
224+
InheritConformance().f() // okay; this is not main actor isolated
225+
}

0 commit comments

Comments
 (0)