Skip to content

Commit 00d09f7

Browse files
authored
Merge pull request swiftlang#35901 from DougGregor/actor-isolation-swiftinterface
[Concurrency] Fix a few issues with actors and Swift interfaces
2 parents 584030b + c26c502 commit 00d09f7

File tree

5 files changed

+45
-36
lines changed

5 files changed

+45
-36
lines changed

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,7 @@ class InheritedProtocolCollector {
467467
// not extensions of that 'actor class'.
468468
if (actorClass &&
469469
inherited->isSpecificProtocol(KnownProtocolKind::Actor))
470-
return TypeWalker::Action::Continue;
471-
472-
#if false
473-
// If the protocol is a marker protocol, print it separately.
474-
if (inherited->isMarkerProtocol()) {
475-
protocolsToPrint.push_back({inherited, protoAndAvailability.second});
476470
return TypeWalker::Action::SkipChildren;
477-
}
478-
#endif
479471

480472
if (inherited->isSPI() && !printOptions.PrintSPIs)
481473
return TypeWalker::Action::Continue;

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,10 +2283,6 @@ ActorIsolation ActorIsolationRequest::evaluate(
22832283
defaultIsolation = ActorIsolation::forActorInstance(classDecl);
22842284
}
22852285

2286-
// Disable inference of actor attributes outside of normal Swift source files.
2287-
if (!shouldInferAttributeInContext(value->getDeclContext()))
2288-
return defaultIsolation;
2289-
22902286
// Function used when returning an inferred isolation.
22912287
auto inferredIsolation = [&](ActorIsolation inferred) {
22922288
// Add an implicit attribute to capture the actor isolation that was
@@ -2340,29 +2336,31 @@ ActorIsolation ActorIsolationRequest::evaluate(
23402336
return getActorIsolation(accessor->getStorage());
23412337
}
23422338

2343-
// If the declaration witnesses a protocol requirement that is isolated,
2344-
// use that.
2345-
if (auto witnessedIsolation = getIsolationFromWitnessedRequirements(value)) {
2346-
return inferredIsolation(*witnessedIsolation);
2347-
}
2339+
if (shouldInferAttributeInContext(value->getDeclContext())) {
2340+
// If the declaration witnesses a protocol requirement that is isolated,
2341+
// use that.
2342+
if (auto witnessedIsolation = getIsolationFromWitnessedRequirements(value)) {
2343+
return inferredIsolation(*witnessedIsolation);
2344+
}
2345+
2346+
// If the declaration is a class with a superclass that has specified
2347+
// isolation, use that.
2348+
if (auto classDecl = dyn_cast<ClassDecl>(value)) {
2349+
if (auto superclassDecl = classDecl->getSuperclassDecl()) {
2350+
auto superclassIsolation = getActorIsolation(superclassDecl);
2351+
if (!superclassIsolation.isUnspecified()) {
2352+
if (superclassIsolation.requiresSubstitution()) {
2353+
Type superclassType = classDecl->getSuperclass();
2354+
if (!superclassType)
2355+
return ActorIsolation::forUnspecified();
2356+
2357+
SubstitutionMap subs = superclassType->getMemberSubstitutionMap(
2358+
classDecl->getModuleContext(), classDecl);
2359+
superclassIsolation = superclassIsolation.subst(subs);
2360+
}
23482361

2349-
// If the declaration is a class with a superclass that has specified
2350-
// isolation, use that.
2351-
if (auto classDecl = dyn_cast<ClassDecl>(value)) {
2352-
if (auto superclassDecl = classDecl->getSuperclassDecl()) {
2353-
auto superclassIsolation = getActorIsolation(superclassDecl);
2354-
if (!superclassIsolation.isUnspecified()) {
2355-
if (superclassIsolation.requiresSubstitution()) {
2356-
Type superclassType = classDecl->getSuperclass();
2357-
if (!superclassType)
2358-
return ActorIsolation::forUnspecified();
2359-
2360-
SubstitutionMap subs = superclassType->getMemberSubstitutionMap(
2361-
classDecl->getModuleContext(), classDecl);
2362-
superclassIsolation = superclassIsolation.subst(subs);
2362+
return inferredIsolation(superclassIsolation);
23632363
}
2364-
2365-
return inferredIsolation(superclassIsolation);
23662364
}
23672365
}
23682366
}

test/ModuleInterface/actor_isolation.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-swift-frontend -emit-module -o %t/Test.swiftmodule -emit-module-interface-path %t/Test.swiftinterface -module-name Test -enable-experimental-concurrency %s
33
// RUN: %FileCheck %s --check-prefix FROMSOURCE --check-prefix CHECK < %t/Test.swiftinterface
4+
// RUN: %target-swift-frontend -typecheck-module-from-interface -module-name Test %t/Test.swiftinterface
5+
46
// RUN: %target-swift-frontend -emit-module -o /dev/null -merge-modules %t/Test.swiftmodule -disable-objc-attr-requires-foundation-module -emit-module-interface-path %t/TestFromModule.swiftinterface -module-name Test -enable-experimental-concurrency
57
// RUN: %FileCheck %s --check-prefix FROMMODULE --check-prefix CHECK < %t/TestFromModule.swiftinterface
8+
// RUN: %target-swift-frontend -typecheck-module-from-interface -module-name Test %t/TestFromModule.swiftinterface
69

710
// REQUIRES: concurrency
811

test/ModuleInterface/actor_objc.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o %t/Test.swiftmodule -emit-module-interface-path %t/Test.swiftinterface -module-name Test -enable-experimental-concurrency %s
3+
// RUN: %FileCheck %s --check-prefix FROMSOURCE --check-prefix CHECK < %t/Test.swiftinterface
4+
// RUN: %target-swift-frontend -typecheck-module-from-interface -module-name Test %t/Test.swiftinterface
5+
6+
// RUN: %target-swift-frontend -emit-module -o /dev/null -merge-modules %t/Test.swiftmodule -disable-objc-attr-requires-foundation-module -emit-module-interface-path %t/TestFromModule.swiftinterface -module-name Test -enable-experimental-concurrency
7+
// RUN: %FileCheck %s --check-prefix FROMMODULE --check-prefix CHECK < %t/TestFromModule.swiftinterface
8+
// RUN: %target-swift-frontend -typecheck-module-from-interface -module-name Test %t/TestFromModule.swiftinterface
9+
10+
// REQUIRES: concurrency
11+
// REQUIRES: objc_interop
12+
13+
import Foundation
14+
15+
// CHECK-LABEL: @objc @_inheritsConvenienceInitializers public actor SomeActor : ObjectiveC.NSObject {
16+
// CHECK: @objc override dynamic public init()
17+
public actor SomeActor: NSObject {
18+
}

test/ModuleInterface/features.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ public func runSomethingSomewhere(body: () async -> Void) { }
7777
// CHECK-NEXT: #endif
7878
public func stage(with actor: MyActor) { }
7979

80-
// CHECK: #if compiler(>=5.3) && $MarkerProtocol
81-
// CHECK-NEXT: extension FeatureTest.MyActor : Swift.ConcurrentValue {}
82-
// CHECK-NEXT: #endif
80+
// CHECK-NOT: extension FeatureTest.MyActor : Swift.ConcurrentValue
8381

8482
// CHECK: #if compiler(>=5.3) && $MarkerProtocol
8583
// CHECK-NEXT: extension FeatureTest.OldSchool : FeatureTest.MP {

0 commit comments

Comments
 (0)