Skip to content

Commit c7a1625

Browse files
committed
Sema: Relax distributed actor typechecking for swiftinterfaces.
Some decls that are expected to be synthesized for distributed actors are printed explicitly in swiftinterfaces so diagnostics and assertions need to take that possibility into account. Resolves rdar://108533918
1 parent 5182208 commit c7a1625

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

lib/Sema/CodeSynthesisDistributedActor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ static VarDecl*
6868
if (!var->getInterfaceType()->isEqual(expectedType))
6969
return nullptr;
7070

71-
assert(var->isSynthesized() && "Expected compiler synthesized property");
7271
return var;
7372
}
7473

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6666,9 +6666,8 @@ void AttributeChecker::visitNonisolatedAttr(NonisolatedAttr *attr) {
66666666
// The synthesized "id" and "actorSystem" are the only exceptions,
66676667
// because the implementation mirrors them.
66686668
if (nominal->isDistributedActor() &&
6669-
!(var->isImplicit() &&
6670-
(var->getName() == Ctx.Id_id ||
6671-
var->getName() == Ctx.Id_actorSystem))) {
6669+
!(var->getName() == Ctx.Id_id ||
6670+
var->getName() == Ctx.Id_actorSystem)) {
66726671
diagnoseAndRemoveAttr(attr,
66736672
diag::nonisolated_distributed_actor_storage);
66746673
return;

lib/Sema/TypeCheckDistributed.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,12 @@ bool swift::checkDistributedActorProperty(VarDecl *var, bool diagnose) {
643643
void swift::checkDistributedActorProperties(const NominalTypeDecl *decl) {
644644
auto &C = decl->getASTContext();
645645

646+
auto sourceFile = decl->getDeclContext()->getParentSourceFile();
647+
if (sourceFile && sourceFile->Kind == SourceFileKind::Interface) {
648+
// Don't diagnose properties in swiftinterfaces.
649+
return;
650+
}
651+
646652
if (isa<ProtocolDecl>(decl)) {
647653
// protocols don't matter for stored property checking
648654
return;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library
3+
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
4+
// RUN: %FileCheck %s < %t/Library.swiftinterface
5+
6+
// REQUIRES: distributed
7+
8+
import Distributed
9+
10+
// CHECK: #if compiler(>=5.3) && $Actors
11+
// CHECK-NEXT: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
12+
// CHECK-NEXT: distributed public actor DA {
13+
@available(SwiftStdlib 5.7, *)
14+
public distributed actor DA {
15+
// CHECK: @_compilerInitialized nonisolated final public let id: Distributed.LocalTestingDistributedActorSystem.ActorID
16+
// CHECK: nonisolated final public let actorSystem: Library.DA.ActorSystem
17+
// CHECK: public typealias ActorSystem = Distributed.LocalTestingDistributedActorSystem
18+
public typealias ActorSystem = LocalTestingDistributedActorSystem
19+
20+
// CHECK: public static func resolve(id: Distributed.LocalTestingDistributedActorSystem.ActorID, using system: Library.DA.ActorSystem) throws -> Library.DA
21+
// CHECK: public typealias ID = Distributed.LocalTestingDistributedActorSystem.ActorID
22+
// CHECK: public typealias SerializationRequirement = any Swift.Decodable & Swift.Encodable
23+
// CHECK: {{@objc deinit|deinit}}
24+
// CHECK: nonisolated public var hashValue: Swift.Int {
25+
// CHECK-NEXT: get
26+
// CHECK-NEXT: }
27+
// CHECK: public init(actorSystem system: Library.DA.ActorSystem)
28+
// CHECK: @available(iOS 16.0, tvOS 16.0, watchOS 9.0, macOS 13.0, *)
29+
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor {
30+
// CHECK-NEXT: get
31+
// CHECK-NEXT: }
32+
}
33+
// CHECK: #endif
34+
35+
36+
// CHECK: #if compiler(>=5.3) && $Actors
37+
// CHECK-NEXT: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
38+
// CHECK-NEXT: extension Library.DA : Distributed.DistributedActor {}
39+
// CHECK-NEXT: #endif
40+
// CHECK: #if compiler(>=5.3) && $Actors
41+
// CHECK-NEXT: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
42+
// CHECK-NEXT: extension Library.DA : Swift.Encodable {}
43+
// CHECK-NEXT: #endif
44+
// CHECK: #if compiler(>=5.3) && $Actors
45+
// CHECK-NEXT: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
46+
// CHECK-NEXT: extension Library.DA : Swift.Decodable {}
47+
// CHECK-NEXT: #endif

0 commit comments

Comments
 (0)