Skip to content

Commit 8c3d1fb

Browse files
committed
Make sure we don't provide duplicate synthesized conformance table entries.
This was benign with `Sendable`, but is not benign for the `Encodable` and `Decodable` synthesis for distributed actors, which results in a crash in TBD generation. Fixes rdar://92008955.
1 parent a1a8dd7 commit 8c3d1fb

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

lib/AST/Module.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,13 +1051,6 @@ static bool shouldCreateMissingConformances(Type type, ProtocolDecl *proto) {
10511051
return true;
10521052
}
10531053

1054-
// A 'distributed actor' may have to create missing Codable conformances.
1055-
if (auto nominal = dyn_cast_or_null<ClassDecl>(type->getAnyNominal())) {
1056-
return nominal->isDistributedActor() &&
1057-
(proto->isSpecificProtocol(swift::KnownProtocolKind::Decodable) ||
1058-
proto->isSpecificProtocol(swift::KnownProtocolKind::Encodable));
1059-
}
1060-
10611054
return false;
10621055
}
10631056

lib/AST/ProtocolConformance.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1532,8 +1532,16 @@ IterableDeclContext::getLocalConformances(ConformanceLookupKind lookupKind)
15321532
// Look for a Sendable conformance globally. If it is synthesized
15331533
// and matches this declaration context, use it.
15341534
auto dc = getAsGenericContext();
1535+
1536+
SmallPtrSet<ProtocolConformance *, 4> known;
15351537
for (auto conformance : findSynthesizedConformances(dc)) {
1536-
result.push_back(conformance);
1538+
// Compute the known set of conformances for the first time.
1539+
if (known.empty()) {
1540+
known.insert(result.begin(), result.end());
1541+
}
1542+
1543+
if (known.insert(conformance).second)
1544+
result.push_back(conformance);
15371545
}
15381546
break;
15391547
}

test/Distributed/distributed_actor_layout.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,18 @@ class MyClass { }
1717
// Ensure that the actor layout is (metadata pointer, default actor, id, system,
1818
// <user fields>)
1919

20+
protocol HasActorSystem {
21+
var actorSystem: FakeActorSystem { get }
22+
}
23+
24+
extension MyActor: HasActorSystem { }
25+
2026
// CHECK: %T27distributed_actor_accessors7MyActorC = type <{ %swift.refcounted, %swift.defaultactor, %T27FakeDistributedActorSystems0C7AddressV, %T27FakeDistributedActorSystems0aC6SystemV, %T27distributed_actor_accessors7MyClassC* }>
2127
@available(SwiftStdlib 5.7, *)
2228
public distributed actor MyActor {
2329
var field: MyClass = MyClass()
30+
31+
init(actorSystem: FakeActorSystem) {
32+
self.actorSystem = actorSystem
33+
}
2434
}

0 commit comments

Comments
 (0)