@@ -548,13 +548,14 @@ class EmitPolymorphicParameters : public PolymorphicConvention {
548
548
// was a class-pointer source?
549
549
bool isClassPointerSource (unsigned paramIndex);
550
550
551
- // If we are building a protocol witness thunk for a
552
- // `DistributedActorSystem.remoteCall` requirement we
553
- // need to supply witness tables associated with `Res`
554
- // generic parameter which are not expressible on the
555
- // requirement because they come from `SerializationRequirement`
551
+ // If we are building a protocol witness thunks for
552
+ // `DistributedActorSystem.remoteCall` or
553
+ // `DistributedTargetInvocationEncoder.record{Argument, ReturnType}`
554
+ // requirements we need to supply witness tables associated with `Res`,
555
+ // `Argument`, `R` generic parameters which are not expressible on the
556
+ // protocol requirement because they come from `SerializationRequirement`
556
557
// associated type.
557
- void injectAdHocDistributedRemoteCallRequirements ();
558
+ void injectAdHocDistributedRequirements ();
558
559
};
559
560
560
561
} // end anonymous namespace
@@ -730,35 +731,53 @@ bool EmitPolymorphicParameters::isClassPointerSource(unsigned paramIndex) {
730
731
return false ;
731
732
}
732
733
733
- void EmitPolymorphicParameters::injectAdHocDistributedRemoteCallRequirements () {
734
+ void EmitPolymorphicParameters::injectAdHocDistributedRequirements () {
734
735
// FIXME: We need a better way to recognize that function is
735
736
// a thunk for witness of `remoteCall` requirement.
736
737
if (!Fn.hasLocation ())
737
738
return ;
738
739
739
740
auto loc = Fn.getLocation ();
740
741
742
+ Type genericParam;
743
+
741
744
auto *funcDecl = dyn_cast_or_null<FuncDecl>(loc.getAsDeclContext ());
742
- if (!(funcDecl && funcDecl->isDistributedActorSystemRemoteCall (
743
- /* isVoidReturn=*/ false )))
745
+ if (!(funcDecl && funcDecl->isGeneric ()))
746
+ return ;
747
+
748
+ // DistributedActorSystem.remoteCall
749
+ if (funcDecl->isDistributedActorSystemRemoteCall (
750
+ /* isVoidReturn=*/ false )) {
751
+ genericParam = funcDecl->getResultInterfaceType ();
752
+ }
753
+
754
+ // DistributedTargetInvocationEncoder.record{Argument, ReturnType}
755
+ if (funcDecl->isDistributedTargetInvocationEncoderRecordArgument () ||
756
+ funcDecl->isDistributedTargetInvocationEncoderRecordReturnType ()) {
757
+ auto *argParam = funcDecl->getGenericParams ()->getParams ().front ();
758
+ genericParam = argParam->getDeclaredInterfaceType ();
759
+ }
760
+
761
+ if (!genericParam)
744
762
return ;
745
763
746
764
auto sig = funcDecl->getGenericSignature ();
747
- auto resultInterfaceTy = funcDecl->getResultInterfaceType ();
748
- auto resultArchetypeTy =
749
- getTypeInContext (resultInterfaceTy->getCanonicalType ());
750
- llvm::Value *resultMetadata = IGF.emitTypeMetadataRef (resultArchetypeTy);
765
+ auto requirements = sig->getLocalRequirements (genericParam);
766
+ if (requirements.protos .empty ())
767
+ return ;
751
768
752
- auto resultRequirements = sig->getLocalRequirements (resultInterfaceTy);
753
- for (auto *proto : resultRequirements.protos ) {
769
+ auto archetypeTy = getTypeInContext (genericParam->getCanonicalType ());
770
+ llvm::Value *metadata = IGF.emitTypeMetadataRef (archetypeTy);
771
+
772
+ for (auto *proto : requirements.protos ) {
754
773
// Lookup the witness table for this protocol dynamically via
755
774
// swift_conformsToProtocol(<<archetype>>, <<protocol>>)
756
775
auto *witnessTable = IGF.Builder .CreateCall (
757
776
IGM.getConformsToProtocolFunctionPointer (),
758
- {resultMetadata , IGM.getAddrOfProtocolDescriptor (proto)});
777
+ {metadata , IGM.getAddrOfProtocolDescriptor (proto)});
759
778
760
779
IGF.setUnscopedLocalTypeData (
761
- resultArchetypeTy ,
780
+ archetypeTy ,
762
781
LocalTypeDataKind::forAbstractProtocolWitnessTable (proto),
763
782
witnessTable);
764
783
}
@@ -2617,8 +2636,9 @@ void EmitPolymorphicParameters::emit(EntryPointArgumentEmission &emission,
2617
2636
// Bind all the fulfillments we can from the formal parameters.
2618
2637
bindParameterSources (getParameter);
2619
2638
2620
- // Inject ad-hoc `remoteCall` requirements if any.
2621
- injectAdHocDistributedRemoteCallRequirements ();
2639
+ // Inject ad-hoc requirements related to `SerializationRequirement`
2640
+ // associated type.
2641
+ injectAdHocDistributedRequirements ();
2622
2642
}
2623
2643
2624
2644
MetadataResponse
0 commit comments