@@ -106,42 +106,6 @@ Type swift::getConcreteReplacementForProtocolActorSystemType(
106106 llvm_unreachable (" Unable to fetch ActorSystem type!" );
107107}
108108
109- Type swift::getSerializationRequirementTypesForMember (
110- ValueDecl *member,
111- llvm::SmallPtrSet<ProtocolDecl *, 2 > &serializationRequirements) {
112- auto &C = member->getASTContext ();
113- auto *DC = member->getDeclContext ();
114- auto DA = C.getDistributedActorDecl ();
115-
116- // === When declared inside an actor, we can get the type directly
117- if (auto classDecl = DC->getSelfClassDecl ()) {
118- return getDistributedSerializationRequirementType (classDecl, C.getDistributedActorDecl ());
119- }
120-
121- auto SerReqAssocType = DA->getAssociatedType (C.Id_SerializationRequirement )
122- ->getDeclaredInterfaceType ();
123-
124- if (DC->getSelfProtocolDecl ()) {
125- GenericSignature signature;
126- if (auto *genericContext = member->getAsGenericContext ()) {
127- signature = genericContext->getGenericSignature ();
128- } else {
129- signature = DC->getGenericSignatureOfContext ();
130- }
131-
132- // Also store all `SerializationRequirement : SomeProtocol` requirements
133- for (auto proto: signature->getRequiredProtocols (SerReqAssocType)) {
134- serializationRequirements.insert (proto);
135- }
136-
137- // Note that this may be null, e.g. if we're a distributed func inside
138- // a protocol that did not declare a specific actor system requirement.
139- return signature->getConcreteType (SerReqAssocType);
140- }
141-
142- llvm_unreachable (" Unable to fetch SerializationRequirement type!" );
143- }
144-
145109Type swift::getDistributedActorSystemType (NominalTypeDecl *actor) {
146110 assert (!dyn_cast<ProtocolDecl>(actor) &&
147111 " Use getConcreteReplacementForProtocolActorSystemType instead to get"
@@ -179,6 +143,53 @@ static Type getTypeWitnessByName(NominalTypeDecl *type, ProtocolDecl *protocol,
179143 return conformance.getTypeWitnessByName (selfType, member);
180144}
181145
146+ Type swift::getDistributedActorSerializationType (
147+ DeclContext *actorOrExtension) {
148+ auto &ctx = actorOrExtension->getASTContext ();
149+ auto resultTy = getAssociatedTypeOfDistributedSystemOfActor (
150+ actorOrExtension,
151+ ctx.Id_SerializationRequirement );
152+
153+ // Protocols are allowed to either not provide a `SerializationRequirement`
154+ // at all or provide it in a conformance requirement.
155+ if ((!resultTy || resultTy->hasDependentMember ()) &&
156+ actorOrExtension->getSelfProtocolDecl ()) {
157+ auto sig = actorOrExtension->getGenericSignatureOfContext ();
158+
159+ auto actorProtocol = ctx.getProtocol (KnownProtocolKind::DistributedActor);
160+ if (!actorProtocol)
161+ return Type ();
162+
163+ auto serializationTy =
164+ actorProtocol->getAssociatedType (ctx.Id_SerializationRequirement )
165+ ->getDeclaredInterfaceType ();
166+
167+ auto protocols = sig->getRequiredProtocols (serializationTy);
168+ if (protocols.empty ())
169+ return Type ();
170+
171+ SmallVector<Type, 2 > members;
172+ llvm::transform (protocols, std::back_inserter (members), [](const auto *P) {
173+ return P->getDeclaredInterfaceType ();
174+ });
175+
176+ return ExistentialType::get (
177+ ProtocolCompositionType::get (ctx, members,
178+ /* inverses=*/ {},
179+ /* HasExplicitAnyObject=*/ false ));
180+ }
181+
182+ return resultTy;
183+ }
184+
185+ Type swift::getDistributedActorSystemSerializationType (
186+ NominalTypeDecl *system) {
187+ assert (!system->isDistributedActor ());
188+ auto &ctx = system->getASTContext ();
189+ return getTypeWitnessByName (system, ctx.getDistributedActorSystemDecl (),
190+ ctx.Id_SerializationRequirement );
191+ }
192+
182193Type swift::getDistributedActorSystemActorIDType (NominalTypeDecl *system) {
183194 assert (!system->isDistributedActor ());
184195 auto &ctx = system->getASTContext ();
@@ -248,19 +259,14 @@ swift::getAssociatedDistributedInvocationDecoderDecodeNextArgumentFunction(
248259 decoderTy->getAnyNominal ());
249260}
250261
251- Type swift::getAssociatedTypeOfDistributedSystemOfActor (NominalTypeDecl *actor,
252- Identifier member) {
253- auto &ctx = actor ->getASTContext ();
262+ Type swift::getAssociatedTypeOfDistributedSystemOfActor (
263+ DeclContext *actorOrExtension, Identifier member) {
264+ auto &ctx = actorOrExtension ->getASTContext ();
254265
255266 auto actorProtocol = ctx.getProtocol (KnownProtocolKind::DistributedActor);
256267 if (!actorProtocol)
257268 return Type ();
258269
259- auto actorConformance = actor->getParentModule ()->lookupConformance (
260- actor->getDeclaredInterfaceType (), actorProtocol);
261- if (!actorConformance || actorConformance.isInvalid ())
262- return Type ();
263-
264270 AssociatedTypeDecl *actorSystemDecl =
265271 actorProtocol->getAssociatedType (ctx.Id_ActorSystem );
266272 if (!actorSystemDecl)
@@ -275,15 +281,27 @@ Type swift::getAssociatedTypeOfDistributedSystemOfActor(NominalTypeDecl *actor,
275281 if (!memberTypeDecl)
276282 return Type ();
277283
278- auto depMemTy = DependentMemberType::get (
279- DependentMemberType::get (actorProtocol->getSelfInterfaceType (),
280- actorSystemDecl),
281- memberTypeDecl);
284+ Type memberTy = DependentMemberType::get (
285+ DependentMemberType::get (actorProtocol->getSelfInterfaceType (),
286+ actorSystemDecl),
287+ memberTypeDecl);
288+
289+ auto sig = actorOrExtension->getGenericSignatureOfContext ();
290+
291+ auto *actorType = actorOrExtension->getSelfNominalTypeDecl ();
292+ if (isa<ProtocolDecl>(actorType))
293+ return memberTy->getReducedType (sig);
294+
295+ auto actorConformance =
296+ actorOrExtension->getParentModule ()->lookupConformance (
297+ actorType->getDeclaredInterfaceType (), actorProtocol);
298+ if (!actorConformance || actorConformance.isInvalid ())
299+ return Type ();
282300
283301 auto subs = SubstitutionMap::getProtocolSubstitutions (
284- actorProtocol, actor ->getDeclaredInterfaceType (), actorConformance);
302+ actorProtocol, actorType ->getDeclaredInterfaceType (), actorConformance);
285303
286- return Type (depMemTy) .subst (subs);
304+ return memberTy .subst (subs)-> getReducedType (sig );
287305}
288306
289307/* *****************************************************************************/
0 commit comments