@@ -71,6 +71,15 @@ struct AllocationInfo {
71
71
StackAddress Addr;
72
72
};
73
73
74
+ struct ArgumentDecoderInfo {
75
+ CanSILFunctionType Type;
76
+ FunctionPointer Fn;
77
+
78
+ // / Given the decoder instance, form a callee to a
79
+ // / decode method - `decodeNextArgument`.
80
+ Callee getCallee (llvm::Value *decoder) const ;
81
+ };
82
+
74
83
class DistributedAccessor {
75
84
IRGenModule &IGM;
76
85
IRGenFunction &IGF;
@@ -83,6 +92,10 @@ class DistributedAccessor {
83
92
// / The asynchronous context associated with this accessor.
84
93
AsyncContextLayout AsyncLayout;
85
94
95
+ // / The argument decoder associated with the distributed actor
96
+ // / this accessor belong to.
97
+ ArgumentDecoderInfo ArgumentDecoder;
98
+
86
99
// / The list of all arguments that were allocated on the stack.
87
100
SmallVector<AllocationInfo, 4 > AllocatedArguments;
88
101
@@ -134,20 +147,30 @@ class DistributedAccessor {
134
147
FunctionPointer getPointerToTarget () const ;
135
148
136
149
Callee getCalleeForDistributedTarget (llvm::Value *self) const ;
150
+
151
+ // / Given a distributed thunk, find argument coder that should
152
+ // / could be used to decode argument values to pass to its invocation.
153
+ static ArgumentDecoderInfo findArgumentDecoder (IRGenModule &IGM,
154
+ SILFunction *thunk);
137
155
};
138
156
139
157
} // end namespace
140
158
159
+ static NominalTypeDecl *getDistributedActorOf (SILFunction *thunk) {
160
+ assert (thunk->isDistributed () && thunk->isThunk ());
161
+ return thunk->getDeclContext ()
162
+ ->getInnermostTypeContext ()
163
+ ->getSelfNominalTypeDecl ();
164
+ }
165
+
141
166
// / Compute a type of a distributed method accessor function based
142
167
// / on the provided distributed method.
143
168
static CanSILFunctionType getAccessorType (IRGenModule &IGM,
144
169
SILFunction *Target) {
145
170
auto &Context = IGM.Context ;
146
171
147
172
auto getInvocationDecoderParameter = [&]() {
148
- auto *actor = Target->getDeclContext ()
149
- ->getInnermostTypeContext ()
150
- ->getSelfNominalTypeDecl ();
173
+ auto *actor = getDistributedActorOf (Target);
151
174
auto *decoder = Context.getDistributedActorInvocationDecoder (actor);
152
175
auto decoderTy = decoder->getInterfaceType ()->getMetatypeInstanceType ();
153
176
auto paramType = IGM.getLoweredType (decoderTy);
@@ -235,7 +258,8 @@ DistributedAccessor::DistributedAccessor(IRGenFunction &IGF,
235
258
IGM, AccessorType, AccessorType, SubstitutionMap(),
236
259
/* suppress generics*/ true,
237
260
FunctionPointer::Kind(
238
- FunctionPointer::BasicKind::AsyncFunctionPointer))) {}
261
+ FunctionPointer::BasicKind::AsyncFunctionPointer))),
262
+ ArgumentDecoder(findArgumentDecoder(IGM, target)) {}
239
263
240
264
void DistributedAccessor::computeArguments (llvm::Value *argumentBuffer,
241
265
llvm::Value *argumentTypes,
@@ -666,3 +690,31 @@ DistributedAccessor::getCalleeForDistributedTarget(llvm::Value *self) const {
666
690
CalleeInfo info{fnType, fnType, SubstitutionMap ()};
667
691
return {std::move (info), getPointerToTarget (), self};
668
692
}
693
+
694
+ ArgumentDecoderInfo
695
+ DistributedAccessor::findArgumentDecoder (IRGenModule &IGM, SILFunction *thunk) {
696
+ auto *actor = getDistributedActorOf (thunk);
697
+
698
+ auto *decodeFn = IGM.Context .getDistributedActorArgumentDecodingMethod (actor);
699
+ assert (decodeFn && " no suitable decoder?" );
700
+
701
+ auto methodTy = IGM.getSILTypes ().getConstantFunctionType (
702
+ IGM.getMaximalTypeExpansionContext (), SILDeclRef (decodeFn));
703
+
704
+ auto *decodeSIL = IGM.getSILModule ().lookUpFunction (SILDeclRef (decodeFn));
705
+ auto *fnPtr = IGM.getAddrOfSILFunction (decodeSIL, NotForDefinition,
706
+ /* isDynamicallyReplacible=*/ false );
707
+
708
+ auto signature = IGM.getSignature (methodTy, /* useSpecialConvention=*/ false );
709
+
710
+ auto methodPtr =
711
+ FunctionPointer::forDirect (classifyFunctionPointerKind (decodeSIL), fnPtr,
712
+ /* secondaryValue=*/ nullptr , signature);
713
+
714
+ return {.Type = methodTy, .Fn = methodPtr};
715
+ }
716
+
717
+ Callee ArgumentDecoderInfo::getCallee (llvm::Value *decoder) const {
718
+ CalleeInfo info (Type, Type, SubstitutionMap ());
719
+ return {std::move (info), Fn, decoder};
720
+ }
0 commit comments