Skip to content

Commit 1caa0b1

Browse files
committed
[Distributed] Handle reqs on DistributedTargetInvocationEncoder
1 parent 005743c commit 1caa0b1

File tree

5 files changed

+100
-97
lines changed

5 files changed

+100
-97
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,13 +1354,6 @@ class ASTContext final {
13541354
Type getAssociatedTypeOfDistributedSystemOfActor(NominalTypeDecl *actor,
13551355
Identifier member);
13561356

1357-
// /// Find the type of SerializationRequirement on the passed nominal.
1358-
// ///
1359-
// /// This type exists as a typealias/associatedtype on all distributed actors,
1360-
// /// actor systems, and related serialization types.
1361-
// Type getDistributedSerializationRequirementType(
1362-
// NominalTypeDecl *, ProtocolDecl *protocolDecl);
1363-
13641357
/// Find the concrete invocation decoder associated with the given actor.
13651358
NominalTypeDecl *
13661359
getDistributedActorInvocationDecoder(NominalTypeDecl *);

lib/AST/DistributedDecl.cpp

Lines changed: 27 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ Type swift::getDistributedActorSystemActorIDRequirementType(NominalTypeDecl *sys
102102

103103
Type swift::getDistributedSerializationRequirementType(
104104
NominalTypeDecl *nominal, ProtocolDecl *protocol) {
105-
assert(!nominal->isDistributedActor());
106105
assert(protocol);
107106
auto &ctx = nominal->getASTContext();
108107

@@ -181,28 +180,19 @@ swift::getDistributedActorSystemSerializationRequirements(
181180
auto existentialRequirementTy =
182181
getDistributedSerializationRequirementType(nominal, protocol);
183182
if (existentialRequirementTy->hasError()) {
184-
fprintf(stderr, "[%s:%d] (%s) if (SerializationRequirementTy->hasError())\n", __FILE__, __LINE__, __FUNCTION__);
185183
return false;
186184
}
187185

188186
if (existentialRequirementTy->isAny())
189187
return true; // we're done here, any means there are no requirements
190188

191-
fprintf(stderr, "[%s:%d] (%s) existentialRequirementTy\n", __FILE__, __LINE__, __FUNCTION__);
192-
existentialRequirementTy.dump();
193-
194-
fprintf(stderr, "[%s:%d] (%s) ---------------------\n", __FILE__, __LINE__, __FUNCTION__);
195-
196189
auto serialReqType = existentialRequirementTy->castTo<ExistentialType>()
197190
->getConstraintType()
198191
->getDesugaredType();
199-
fprintf(stderr, "[%s:%d] (%s) serialReqType serialReqType serialReqType serialReqType serialReqType serialReqType\n", __FILE__, __LINE__, __FUNCTION__);
200-
serialReqType->dump();
201192
auto flattenedRequirements =
202193
flattenDistributedSerializationTypeToRequiredProtocols(
203194
serialReqType);
204195
for (auto p : flattenedRequirements) {
205-
fprintf(stderr, "[%s:%d] (%s) PROTO %s\n", __FILE__, __LINE__, __FUNCTION__, p->getNameStr().str().c_str());
206196
requirementProtos.insert(p);
207197
}
208198

@@ -254,16 +244,9 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
254244
auto &C = getASTContext();
255245
auto module = getParentModule();
256246

257-
fprintf(stderr, "[%s:%d] (%s) ====================================================\n", __FILE__, __LINE__, __FUNCTION__);
258-
fprintf(stderr, "[%s:%d] (%s) ====================================================\n", __FILE__, __LINE__, __FUNCTION__);
259-
fprintf(stderr, "[%s:%d] (%s) ====================================================\n", __FILE__, __LINE__, __FUNCTION__);
260-
fprintf(stderr, "[%s:%d] (%s) ====================================================\n", __FILE__, __LINE__, __FUNCTION__);
261-
fprintf(stderr, "[%s:%d] (%s) CHECK NAME: %s\n", __FILE__, __LINE__, __FUNCTION__, getNameStr().str().c_str());
262-
263247
// === Check the name
264248
auto callId = isVoidReturn ? C.Id_remoteCallVoid : C.Id_remoteCall;
265249
if (getBaseName() != callId) {
266-
fprintf(stderr, "[%s:%d] (%s) if (getBaseName() != callId)\n", __FILE__, __LINE__, __FUNCTION__);
267250
return false;
268251
}
269252

@@ -276,26 +259,22 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
276259
systemNominal->getDeclaredInterfaceType(), systemProto);
277260

278261
if (distSystemConformance.isInvalid()) {
279-
fprintf(stderr, "[%s:%d] (%s) if (distSystemConformance.isInvalid())\n", __FILE__, __LINE__, __FUNCTION__);
280262
return false;
281263
}
282264

283265
// === Structural Checks
284266
// -- Must be throwing
285267
if (!hasThrows()) {
286-
fprintf(stderr, "[%s:%d] (%s) if (!hasThrows())\n", __FILE__, __LINE__, __FUNCTION__);
287268
return false;
288269
}
289270

290271
// -- Must be async
291272
if (!hasAsync()) {
292-
fprintf(stderr, "[%s:%d] (%s) if (!hasAsync())\n", __FILE__, __LINE__, __FUNCTION__);
293273
return false;
294274
}
295275

296276
// === Check generics
297277
if (!isGeneric()) {
298-
fprintf(stderr, "[%s:%d] (%s) if (!isGeneric())\n", __FILE__, __LINE__, __FUNCTION__);
299278
return false;
300279
}
301280

@@ -304,7 +283,6 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
304283
unsigned int expectedGenericParamNum = isVoidReturn ? 2 : 3;
305284

306285
if (genericParams->size() != expectedGenericParamNum) {
307-
fprintf(stderr, "[%s:%d] (%s) if (genericParams->size() != expectedGenericParamNum)\n", __FILE__, __LINE__, __FUNCTION__);
308286
return false;
309287
}
310288

@@ -329,7 +307,6 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
329307
// --- Count of parameters depends on if we're void returning or not
330308
unsigned int expectedParamNum = isVoidReturn ? 4 : 5;
331309
if (!params || params->size() != expectedParamNum) {
332-
fprintf(stderr, "[%s:%d] (%s) if (!params || params->size() != expectedParamNum) {\n", __FILE__, __LINE__, __FUNCTION__);
333310
return false;
334311
}
335312

@@ -366,10 +343,6 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
366343
}
367344
}
368345

369-
fprintf(stderr, "[%s:%d] (%s) GENERIC PARAMS\n", __FILE__, __LINE__, __FUNCTION__);
370-
for (auto param : genericParams->getParams()) {
371-
param->dump();
372-
}
373346
// === Check generic parameters in detail
374347
// --- Check: Act: DistributedActor,
375348
// Act.ID == Self.ActorID
@@ -401,15 +374,6 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
401374
auto sig = getGenericSignature();
402375
auto requirements = sig.getRequirements();
403376

404-
fprintf(stderr, "[%s:%d] (%s) REQUIREMENTS requirements::::::::::::::::\n", __FILE__, __LINE__, __FUNCTION__);
405-
for (auto r : requirements) {
406-
r.dump();
407-
}
408-
fprintf(stderr, "[%s:%d] (%s) REQUIREMENT PROTOS ::::::::::::::::\n", __FILE__, __LINE__, __FUNCTION__);
409-
for (auto r : requirementProtos) {
410-
r->dump();
411-
}
412-
413377
if (requirements.size() != expectedRequirementsNum) {
414378
return false;
415379
}
@@ -486,7 +450,7 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
486450
}
487451
auto expectedActorIdTy =
488452
getDistributedActorSystemActorIDRequirementType(systemNominal);
489-
actorIdReq.dump();
453+
// actorIdReq.dump();
490454
if (!actorIdReq.getSecondType()->isEqual(expectedActorIdTy)) {
491455
return false;
492456
}
@@ -500,8 +464,9 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const
500464
auto module = getParentModule();
501465

502466
// === Check base name
503-
if (getBaseIdentifier() != C.Id_recordArgument)
467+
if (getBaseIdentifier() != C.Id_recordArgument) {
504468
return false;
469+
}
505470

506471
// === Must be declared in a 'DistributedTargetInvocationEncoder' conforming type
507472
ProtocolDecl *encoderProto =
@@ -518,19 +483,16 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const
518483
// === Check modifiers
519484
// --- must not be async
520485
if (hasAsync()) {
521-
fprintf(stderr, "[%s:%d] (%s) return false\n", __FILE__, __LINE__, __FUNCTION__);
522486
return false;
523487
}
524488

525489
// --- must be throwing
526490
if (!hasThrows()) {
527-
fprintf(stderr, "[%s:%d] (%s) return false\n", __FILE__, __LINE__, __FUNCTION__);
528491
return false;
529492
}
530493

531494
// === Check generics
532495
if (!isGeneric()) {
533-
fprintf(stderr, "[%s:%d] (%s) if (!isGeneric())\n", __FILE__, __LINE__, __FUNCTION__);
534496
return false;
535497
}
536498

@@ -539,15 +501,13 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const
539501
unsigned int expectedGenericParamNum = 1;
540502

541503
if (genericParams->size() != expectedGenericParamNum) {
542-
fprintf(stderr, "[%s:%d] (%s) if (genericParams->size() != expectedGenericParamNum)\n", __FILE__, __LINE__, __FUNCTION__);
543504
return false;
544505
}
545506

546507
// === Get the SerializationRequirement
547508
SmallPtrSet<ProtocolDecl*, 2> requirementProtos;
548509
if (!getDistributedActorSystemSerializationRequirements(
549510
encoderNominal, encoderProto, requirementProtos)) {
550-
fprintf(stderr, "[%s:%d] (%s) return false\n", __FILE__, __LINE__, __FUNCTION__);
551511
return false;
552512
}
553513

@@ -558,14 +518,12 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const
558518
// === Check all parameters
559519
auto params = getParameters();
560520
if (params->size() != 1) {
561-
fprintf(stderr, "[%s:%d] (%s) return false\n", __FILE__, __LINE__, __FUNCTION__);
562521
return false;
563522
}
564523

565524
// --- Check parameter: _ argument
566525
auto argumentParam = params->get(0);
567-
if (!argumentParam->getArgumentName().is("_")) {
568-
fprintf(stderr, "[%s:%d] (%s) return false\n", __FILE__, __LINE__, __FUNCTION__);
526+
if (!argumentParam->getArgumentName().is("")) {
569527
return false;
570528
}
571529

@@ -577,7 +535,6 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const
577535
auto requirements = sig.getRequirements();
578536

579537
if (requirements.size() != expectedRequirementsNum) {
580-
fprintf(stderr, "[%s:%d] (%s) return false\n", __FILE__, __LINE__, __FUNCTION__);
581538
return false;
582539
}
583540

@@ -589,12 +546,10 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const
589546

590547
auto func = dyn_cast<FuncDecl>(this);
591548
if (!func) {
592-
fprintf(stderr, "[%s:%d] (%s) return false\n", __FILE__, __LINE__, __FUNCTION__);
593549
return false;
594550
}
595551

596-
auto resultType = func->mapTypeIntoContext(func->getResultInterfaceType())
597-
->getMetatypeInstanceType()
552+
auto resultType = func->mapTypeIntoContext(argumentParam->getInterfaceType())
598553
->getDesugaredType();
599554
auto resultParamType = func->mapTypeIntoContext(
600555
ArgumentParam->getInterfaceType()->getMetatypeInstanceType());
@@ -606,14 +561,12 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordArgument() const
606561
for (auto requirementProto : requirementProtos) {
607562
auto conformance = module->lookupConformance(resultType, requirementProto);
608563
if (conformance.isInvalid()) {
609-
fprintf(stderr, "[%s:%d] (%s) return false\n", __FILE__, __LINE__, __FUNCTION__);
610564
return false;
611565
}
612566
}
613567

614568
// === Check result type: Void
615569
if (!func->getResultInterfaceType()->isVoid()) {
616-
fprintf(stderr, "[%s:%d] (%s) return false\n", __FILE__, __LINE__, __FUNCTION__);
617570
return false;
618571
}
619572

@@ -626,8 +579,9 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() con
626579
auto module = getParentModule();
627580

628581
// === Check base name
629-
if (getBaseIdentifier() != C.Id_recordReturnType)
582+
if (getBaseIdentifier() != C.Id_recordReturnType) {
630583
return false;
584+
}
631585

632586
// === Must be declared in a 'DistributedTargetInvocationEncoder' conforming type
633587
ProtocolDecl *encoderProto =
@@ -654,7 +608,6 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() con
654608

655609
// === Check generics
656610
if (!isGeneric()) {
657-
fprintf(stderr, "[%s:%d] (%s) if (!isGeneric())\n", __FILE__, __LINE__, __FUNCTION__);
658611
return false;
659612
}
660613

@@ -663,7 +616,6 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() con
663616
unsigned int expectedGenericParamNum = 1;
664617

665618
if (genericParams->size() != expectedGenericParamNum) {
666-
fprintf(stderr, "[%s:%d] (%s) if (genericParams->size() != expectedGenericParamNum)\n", __FILE__, __LINE__, __FUNCTION__);
667619
return false;
668620
}
669621

@@ -686,7 +638,7 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() con
686638

687639
// --- Check parameter: _ argument
688640
auto argumentParam = params->get(0);
689-
if (!argumentParam->getArgumentName().is("_")) {
641+
if (!argumentParam->getArgumentName().is("")) {
690642
return false;
691643
}
692644

@@ -708,14 +660,17 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() con
708660
// ...
709661

710662
auto func = dyn_cast<FuncDecl>(this);
711-
if (!func)
663+
if (!func) {
712664
return false;
665+
}
713666

714-
auto resultType = func->mapTypeIntoContext(func->getResultInterfaceType())
667+
auto resultType = func->mapTypeIntoContext(argumentParam->getInterfaceType())
715668
->getMetatypeInstanceType()
716669
->getDesugaredType();
670+
717671
auto resultParamType = func->mapTypeIntoContext(
718672
ArgumentParam->getInterfaceType()->getMetatypeInstanceType());
673+
719674
// The result of the function must be the `Res` generic argument.
720675
if (!resultType->isEqual(resultParamType)) {
721676
return false;
@@ -738,13 +693,13 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordReturnType() con
738693

739694
bool
740695
AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() const {
741-
742696
auto &C = getASTContext();
743697
auto module = getParentModule();
744698

745699
// === Check base name
746-
if (getBaseIdentifier() != C.Id_recordReturnType)
700+
if (getBaseIdentifier() != C.Id_recordErrorType) {
747701
return false;
702+
}
748703

749704
// === Must be declared in a 'DistributedTargetInvocationEncoder' conforming type
750705
ProtocolDecl *encoderProto =
@@ -755,26 +710,22 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() cons
755710
encoderNominal->getDeclaredInterfaceType(), encoderProto);
756711

757712
if (protocolConformance.isInvalid()) {
758-
fprintf(stderr, "[%s:%d] (%s) return false\n", __FILE__, __LINE__, __FUNCTION__);
759713
return false;
760714
}
761715

762716
// === Check modifiers
763717
// --- must not be async
764718
if (hasAsync()) {
765-
fprintf(stderr, "[%s:%d] (%s) return false\n", __FILE__, __LINE__, __FUNCTION__);
766719
return false;
767720
}
768721

769722
// --- must be throwing
770723
if (!hasThrows()) {
771-
fprintf(stderr, "[%s:%d] (%s) return false\n", __FILE__, __LINE__, __FUNCTION__);
772724
return false;
773725
}
774726

775727
// === Check generics
776728
if (!isGeneric()) {
777-
fprintf(stderr, "[%s:%d] (%s) if (!isGeneric())\n", __FILE__, __LINE__, __FUNCTION__);
778729
return false;
779730
}
780731

@@ -783,7 +734,6 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() cons
783734
unsigned int expectedGenericParamNum = 1;
784735

785736
if (genericParams->size() != expectedGenericParamNum) {
786-
fprintf(stderr, "[%s:%d] (%s) if (genericParams->size() != expectedGenericParamNum)\n", __FILE__, __LINE__, __FUNCTION__);
787737
return false;
788738
}
789739

@@ -793,9 +743,9 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() cons
793743
return false;
794744
}
795745

796-
// --- Check parameter: _ argument
746+
// --- Check parameter: _ errorType
797747
auto argumentParam = params->get(0);
798-
if (!argumentParam->getArgumentName().is("_")) {
748+
if (!argumentParam->getArgumentName().is("")) {
799749
return false;
800750
}
801751

@@ -807,7 +757,14 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() cons
807757
}
808758

809759
// === Check generic parameters in detail
810-
GenericTypeParamDecl *ArgumentParam = genericParams->getParams()[0];
760+
// --- Check: Err: Error
761+
GenericTypeParamDecl *ErrParam = genericParams->getParams()[0];
762+
auto ErrConformance = module->lookupConformance(
763+
mapTypeIntoContext(ErrParam->getDeclaredInterfaceType()),
764+
C.getProtocol(KnownProtocolKind::Error));
765+
if (ErrConformance.isInvalid()) {
766+
return false;
767+
}
811768

812769
// --- Check requirement: conforms_to: Err Error
813770
auto errorReq = requirements[0];
@@ -823,8 +780,9 @@ AbstractFunctionDecl::isDistributedTargetInvocationEncoderRecordErrorType() cons
823780

824781
// === Check result type: Void
825782
auto func = dyn_cast<FuncDecl>(this);
826-
if (!func)
783+
if (!func) {
827784
return false;
785+
}
828786

829787
if (!func->getResultInterfaceType()->isVoid()) {
830788
return false;

0 commit comments

Comments
 (0)