@@ -116,33 +116,55 @@ Type swift::getDistributedActorIDType(NominalTypeDecl *actor) {
116116 return C.getAssociatedTypeOfDistributedSystemOfActor (actor, C.Id_ActorID );
117117}
118118
119- Type swift::getDistributedActorSystemActorIDRequirementType (NominalTypeDecl *system) {
119+ Type swift::getDistributedActorSystemActorIDType (NominalTypeDecl *system) {
120120 assert (!system->isDistributedActor ());
121121 auto &ctx = system->getASTContext ();
122122
123- auto protocol = ctx.getDistributedActorSystemDecl ();
124- if (!protocol )
123+ auto DAS = ctx.getDistributedActorSystemDecl ();
124+ if (!DAS )
125125 return Type ();
126126
127127 // Dig out the serialization requirement type.
128128 auto module = system->getParentModule ();
129129 Type selfType = system->getSelfInterfaceType ();
130- auto conformance = module ->lookupConformance (selfType, protocol );
130+ auto conformance = module ->lookupConformance (selfType, DAS );
131131 return conformance.getTypeWitnessByName (selfType, ctx.Id_ActorID );
132132}
133133
134+ Type swift::getDistributedActorSystemResultHandlerType (
135+ NominalTypeDecl *system) {
136+ assert (!system->isDistributedActor ());
137+ auto &ctx = system->getASTContext ();
138+
139+ auto DAS = ctx.getDistributedActorSystemDecl ();
140+ if (!DAS)
141+ return Type ();
142+
143+ // Dig out the serialization requirement type.
144+ auto module = system->getParentModule ();
145+ Type selfType = system->getSelfInterfaceType ();
146+ auto conformance = module ->lookupConformance (selfType, DAS);
147+ auto witness =
148+ conformance.getTypeWitnessByName (selfType, ctx.Id_ResultHandler );
149+ if (auto alias = dyn_cast<TypeAliasType>(witness.getPointer ())) {
150+ return alias->getDecl ()->getUnderlyingType ();
151+ } else {
152+ return witness;
153+ }
154+ }
155+
134156Type swift::getDistributedActorSystemInvocationEncoderType (NominalTypeDecl *system) {
135157 assert (!system->isDistributedActor ());
136158 auto &ctx = system->getASTContext ();
137159
138- auto protocol = ctx.getDistributedActorSystemDecl ();
139- if (!protocol )
160+ auto DAS = ctx.getDistributedActorSystemDecl ();
161+ if (!DAS )
140162 return Type ();
141163
142164 // Dig out the serialization requirement type.
143165 auto module = system->getParentModule ();
144166 Type selfType = system->getSelfInterfaceType ();
145- auto conformance = module ->lookupConformance (selfType, protocol );
167+ auto conformance = module ->lookupConformance (selfType, DAS );
146168 return conformance.getTypeWitnessByName (selfType, ctx.Id_InvocationEncoder );
147169}
148170
@@ -494,8 +516,7 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
494516 if (actorIdReq.getKind () != RequirementKind::SameType) {
495517 return false ;
496518 }
497- auto expectedActorIdTy =
498- getDistributedActorSystemActorIDRequirementType (systemNominal);
519+ auto expectedActorIdTy = getDistributedActorSystemActorIDType (systemNominal);
499520 if (!actorIdReq.getSecondType ()->isEqual (expectedActorIdTy)) {
500521 return false ;
501522 }
@@ -1036,6 +1057,11 @@ AbstractFunctionDecl::isDistributedTargetInvocationResultHandlerOnReturn() const
10361057 auto &C = getASTContext ();
10371058 auto module = getParentModule ();
10381059
1060+ auto func = dyn_cast<FuncDecl>(this );
1061+ if (!func) {
1062+ return false ;
1063+ }
1064+
10391065 // === Check base name
10401066 if (getBaseIdentifier () != C.Id_onReturn ) {
10411067 return false ;
@@ -1069,7 +1095,20 @@ AbstractFunctionDecl::isDistributedTargetInvocationResultHandlerOnReturn() const
10691095 return false ;
10701096 }
10711097
1072- // TODO(distributed): check generics here
1098+ // --- Check number of generic parameters
1099+ auto genericParams = getGenericParams ();
1100+ unsigned int expectedGenericParamNum = 1 ;
1101+
1102+ if (genericParams->size () != expectedGenericParamNum) {
1103+ return false ;
1104+ }
1105+
1106+ // === Get the SerializationRequirement
1107+ SmallPtrSet<ProtocolDecl *, 2 > requirementProtos;
1108+ if (!getDistributedSerializationRequirements (decoderNominal, decoderProto,
1109+ requirementProtos)) {
1110+ return false ;
1111+ }
10731112
10741113 // === Check all parameters
10751114 auto params = getParameters ();
@@ -1083,11 +1122,27 @@ AbstractFunctionDecl::isDistributedTargetInvocationResultHandlerOnReturn() const
10831122 return false ;
10841123 }
10851124
1086- auto func = dyn_cast<FuncDecl>(this );
1087- if (!func) {
1125+ // === Check generic parameters in detail
1126+ // --- Check: Argument: SerializationRequirement
1127+ GenericTypeParamDecl *ArgumentParam = genericParams->getParams ()[0 ];
1128+ auto argumentType = func->mapTypeIntoContext (valueParam->getInterfaceType ())
1129+ ->getMetatypeInstanceType ()
1130+ ->getDesugaredType ();
1131+ auto resultParamType = func->mapTypeIntoContext (
1132+ ArgumentParam->getInterfaceType ()->getMetatypeInstanceType ());
1133+ // The result of the function must be the `Res` generic argument.
1134+ if (!argumentType->isEqual (resultParamType)) {
10881135 return false ;
10891136 }
10901137
1138+ for (auto requirementProto : requirementProtos) {
1139+ auto conformance =
1140+ module ->lookupConformance (argumentType, requirementProto);
1141+ if (conformance.isInvalid ()) {
1142+ return false ;
1143+ }
1144+ }
1145+
10911146 if (!func->getResultInterfaceType ()->isVoid ()) {
10921147 return false ;
10931148 }
@@ -1160,7 +1215,18 @@ NominalTypeDecl::getDistributedRemoteCallArgumentInitFunction() const {
11601215 auto mutableThis = const_cast <NominalTypeDecl *>(this );
11611216 return evaluateOrDefault (
11621217 getASTContext ().evaluator ,
1163- GetDistributedRemoteCallArgumentInitFunctionRequest (mutableThis), nullptr );
1218+ GetDistributedRemoteCallArgumentInitFunctionRequest (mutableThis),
1219+ nullptr );
1220+ }
1221+
1222+ FuncDecl *
1223+ NominalTypeDecl::getDistributedActorSystemInvokeHandlerOnReturnFunction ()
1224+ const {
1225+ auto mutableThis = const_cast <NominalTypeDecl *>(this );
1226+ return evaluateOrDefault (
1227+ getASTContext ().evaluator ,
1228+ GetDistributedActorSystemInvokeHandlerOnReturnRequest (mutableThis),
1229+ nullptr );
11641230}
11651231
11661232AbstractFunctionDecl *ASTContext::getRemoteCallOnDistributedActorSystem (
0 commit comments