@@ -204,7 +204,8 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
204
204
SILFunction *Target) {
205
205
auto &Context = IGM.Context ;
206
206
207
- // func __accessor__<D: DistributedTargetInvocationDecoder>(
207
+ // func __accessor__<..., D: DistributedTargetInvocationDecoder>(
208
+ // <... other generics ...>
208
209
// inout D, <- invocation decoder
209
210
// UnsafeRawPointer, <- argument types
210
211
// UnsafeRawPointer, <- result buffer
@@ -216,10 +217,19 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
216
217
217
218
SmallVector<GenericFunctionType::Param, 8 > parameters;
218
219
220
+ unsigned decoderTypeParamDepth = 0 ;
221
+ if (auto genSig = Target->getGenericSignature ()) {
222
+ decoderTypeParamDepth = genSig.getGenericParams ().back ()->getDepth () + 1 ;
223
+ }
224
+
219
225
// A generic parameter that represents instance of invocation decoder.
220
226
auto *decoderType =
221
- GenericTypeParamType::get (/* isParameterPack=*/ false ,
222
- /* depth=*/ 1 , /* index=*/ 0 , Context);
227
+ GenericTypeParamType::get (
228
+ /* isParameterPack=*/ false ,
229
+ /* depth=*/ decoderTypeParamDepth,
230
+ /* index=*/ 0 , Context);
231
+ fprintf (stderr, " [%s:%d](%s) FIND the decoder type at: \n " , __FILE_NAME__, __LINE__, __FUNCTION__);
232
+ decoderType->dump ();
223
233
224
234
// decoder
225
235
parameters.push_back (GenericFunctionType::Param (
@@ -251,6 +261,10 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
251
261
auto targetTy = Target->getLoweredFunctionType ();
252
262
auto actorLoc = targetTy->getParameters ().back ();
253
263
264
+ // fprintf(stderr, "[%s:%d](%s) THE TARGET:\n", __FILE_NAME__, __LINE__, __FUNCTION__);
265
+ // Target->dump();
266
+ // targetTy.dump();
267
+
254
268
parameters.push_back (
255
269
GenericFunctionType::Param (actorLoc.getInterfaceType ()));
256
270
}
@@ -269,30 +283,34 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
269
283
auto *actor = getDistributedActorOf (Target);
270
284
assert (actor);
271
285
272
- unsigned targetDepth = 1 ;
273
- unsigned targetIndex = 0 ;
274
-
275
- if (Target->getGenericSignature ()) {
276
- for (auto param: Target->getGenericSignature ().getGenericParams ()) {
277
- targetDepth = std::max (targetDepth, param->getDepth ());
278
- targetIndex = std::max (targetIndex, param->getIndex ());
279
- }
280
- // Target->getGenericSignature().getInnermostGenericParams().size();
281
- for (auto param: Target->getGenericSignature ().getInnermostGenericParams ()) {
282
- targetDepth = std::max (targetDepth, param->getDepth ());
283
- targetIndex = std::max (targetIndex, param->getIndex ());
284
- }
285
- if (!Target->getGenericSignature ().getInnermostGenericParams ().empty ()) {
286
- targetIndex += 1 ;
287
- }
286
+ unsigned decoderTypeParamDepth = 0 ;
287
+
288
+ if (auto genericSig = Target->getGenericSignature ()) {
289
+ decoderTypeParamDepth = genericSig.getGenericParams ().back ()->getDepth () + 1 ;
290
+ // targetIndex = genericSig.getGenericParams().back()->getIndex() + 1;
288
291
}
292
+ // for (auto param: Target->getGenericSignature().getGenericParams()) {
293
+ // targetDepth = std::max(targetDepth, param->getDepth());
294
+ // targetIndex = std::max(targetIndex, param->getIndex());
295
+ // }
296
+ // // Target->getGenericSignature().getInnermostGenericParams().size();
297
+ // for (auto param: Target->getGenericSignature().getInnermostGenericParams()) {
298
+ // targetDepth = std::max(targetDepth, param->getDepth());
299
+ // targetIndex = std::max(targetIndex, param->getIndex());
300
+ // }
301
+ // if (!Target->getGenericSignature().getInnermostGenericParams().empty()) {
302
+ // targetIndex += 1;
303
+ // }
304
+ // }
289
305
290
306
auto decoderParamTy = GenericTypeParamType::get (
291
- // /*isParameterPack=*/false, /*depth=*/1, /*index=*/1, Context);
292
307
/* isParameterPack=*/ false ,
293
- targetDepth ,
294
- targetIndex,
308
+ /* depth= */ decoderTypeParamDepth ,
309
+ /* index= */ 0 , // since we're always at depth+1, we can assume we'll be the first
295
310
Context);
311
+ fprintf (stderr, " [%s:%d](%s) THE PARAM\n " , __FILE_NAME__, __LINE__, __FUNCTION__);
312
+ decoderParamTy->dump ();
313
+
296
314
addedParameters.push_back (decoderParamTy);
297
315
298
316
// Add a requirement that decoder conforms to the expected protocol.
@@ -636,45 +654,138 @@ void DistributedAccessor::emit() {
636
654
SILFunctionConventions targetConv (targetTy, IGF.getSILModule ());
637
655
TypeExpansionContext expansionContext = IGM.getMaximalTypeExpansionContext ();
638
656
657
+ IGF.CurFn ->dump ();
658
+
639
659
auto params = IGF.collectParameters ();
640
660
641
661
GenericContextScope scope (IGM, targetTy->getInvocationGenericSignature ());
642
662
643
663
auto directResultTy = targetConv.getSILResultType (expansionContext);
644
664
const auto &directResultTI = IGM.getTypeInfo (directResultTy);
645
665
666
+ // fprintf(stderr, "[%s:%d](%s) target ------------------------\n", __FILE_NAME__, __LINE__, __FUNCTION__);
667
+ // Target->dump();
668
+ // fprintf(stderr, "[%s:%d](%s) target ^^^^^^^^^^^^^^^^^^^^^^^^\n", __FILE_NAME__, __LINE__, __FUNCTION__);
669
+ fprintf (stderr, " [%s:%d](%s) ==== params size: %d\n " , __FILE_NAME__, __LINE__, __FUNCTION__, params.size ());
670
+
646
671
Explosion arguments;
647
672
673
+ if (auto genSig = Target->getGenericSignature ()) {
674
+ fprintf (stderr, " [%s:%d](%s) signature [%d] =======\n " , __FILE_NAME__, __LINE__, __FUNCTION__,
675
+ genSig.getGenericParams ().size ());
676
+ genSig.dump ();
677
+ fprintf (stderr, " [%s:%d](%s) signature [%d] ^^^^^^^^\n " , __FILE_NAME__, __LINE__, __FUNCTION__,
678
+ genSig.getGenericParams ().size ());
679
+ }
680
+
648
681
unsigned numAsyncContextParams =
649
682
(unsigned )AsyncFunctionArgumentIndex::Context + 1 ;
650
- (void )params.claim (numAsyncContextParams);
683
+ auto ignore1 = params.claim (numAsyncContextParams);
684
+ fprintf (stderr, " [%s:%d](%s) ==== ignore FIRST N: %d\n " , __FILE_NAME__, __LINE__, __FUNCTION__, numAsyncContextParams);
685
+ for (auto a: ignore1) {
686
+ a->dump ();
687
+ }
651
688
652
689
// A container that produces argument values based on the given set of
653
690
// argument types (supplied as a next argument).
654
691
auto *argDecoder = params.claimNext ();
692
+ fprintf (stderr, " [%s:%d](%s) ==== get arg decoder \n " , __FILE_NAME__, __LINE__, __FUNCTION__);
693
+ argDecoder->dump ();
655
694
// `swift.type**` that holds the argument types that correspond to values.
656
695
auto *argTypes = params.claimNext ();
696
+ fprintf (stderr, " [%s:%d](%s) ==== get argTypes \n " , __FILE_NAME__, __LINE__, __FUNCTION__);
697
+ argTypes->dump ();
657
698
// UnsafeRawPointer that is used to store the result.
658
699
auto *resultBuffer = params.claimNext ();
700
+ fprintf (stderr, " [%s:%d](%s) ==== get resultBuffer \n " , __FILE_NAME__, __LINE__, __FUNCTION__);
701
+ resultBuffer->dump ();
659
702
// UnsafeRawPointer that represents a list of substitutions
660
703
auto *substitutions = params.claimNext ();
704
+ fprintf (stderr, " [%s:%d](%s) ==== get substitutions \n " , __FILE_NAME__, __LINE__, __FUNCTION__);
705
+ substitutions->dump ();
661
706
// UnsafeRawPointer that represents a list of witness tables
662
707
auto *witnessTables = params.claimNext ();
708
+ fprintf (stderr, " [%s:%d](%s) ==== get witnessTables \n " , __FILE_NAME__, __LINE__, __FUNCTION__);
709
+ witnessTables->dump ();
663
710
// Integer that represented the number of witness tables
664
711
auto *numWitnessTables = params.claimNext ();
712
+ fprintf (stderr, " [%s:%d](%s) ==== get numWitnessTables \n " , __FILE_NAME__, __LINE__, __FUNCTION__);
713
+ numWitnessTables->dump ();
665
714
// Reference to a `self` of the actor to be called.
666
715
auto *actorSelf = params.claimNext ();
716
+ fprintf (stderr, " [%s:%d](%s) ==== get actorSelf \n " , __FILE_NAME__, __LINE__, __FUNCTION__);
717
+ actorSelf->dump ();
718
+
719
+ // if (auto genSig = Target->getGenericSignature()) {
720
+ // fprintf(stderr, "[%s:%d](%s) ==== drop generic params size: %d \n", __FILE_NAME__, __LINE__, __FUNCTION__,
721
+ // genSig.getGenericParams().size());
722
+ // for (auto a : params.claim(genSig.getGenericParams().size())) {
723
+ // a->dump();
724
+ // }
725
+ // }
667
726
// Metadata that represents passed in the invocation decoder.
668
- auto *decoderType = params.claimNext ();
727
+ llvm::Value *decoderType;
728
+ if (auto genSig = Target->getGenericSignature ()) {
729
+ auto genericParams = params.claim (genSig.getGenericParams ().size ());
730
+ fprintf (stderr, " [%s:%d](%s) ==== get decoder type; SKIP \n " , __FILE_NAME__, __LINE__, __FUNCTION__);
731
+ for (auto a : genericParams) {
732
+ a->dump ();
733
+ }
734
+ fprintf (stderr, " [%s:%d](%s) ==== get decoder type \n " , __FILE_NAME__, __LINE__, __FUNCTION__);
735
+ decoderType = genericParams.back ();
736
+ decoderType->dump ();
737
+ } else {
738
+ decoderType = params.claimNext ();
739
+ fprintf (stderr, " [%s:%d](%s) ==== get decoder type RAW \n " , __FILE_NAME__, __LINE__, __FUNCTION__);
740
+ decoderType->dump ();
741
+ }
669
742
670
743
// If the distributed thunk is declared in a protocol that conforms
671
744
// to `DistributedActor` protocol, there is an extract parameter that
672
745
// represents a type of protocol witness.
673
- if (isa<ProtocolDecl>(actor))
674
- (void )params.claimNext ();
746
+ if (isa<ProtocolDecl>(actor)) {
747
+ auto a = params.claimNext ();
748
+ fprintf (stderr, " [%s:%d](%s) ==== dump protocol self\n " , __FILE_NAME__, __LINE__, __FUNCTION__);
749
+ a->dump ();
750
+ }
675
751
676
752
// Witness table for decoder conformance to DistributedTargetInvocationDecoder
677
- auto *decoderProtocolWitness = params.claimNext ();
753
+ llvm::Value *decoderProtocolWitness = params.claimNext ();
754
+
755
+ // fprintf(stderr, "[%s:%d](%s) ==== ignore all remaining\n", __FILE_NAME__, __LINE__, __FUNCTION__);
756
+ // auto allRemaining = params.claimAll();
757
+ // for (auto a : allRemaining) {
758
+ // a->dump();
759
+ // }
760
+ //
761
+ // auto *decoderProtocolWitness = allRemaining.back();
762
+ // fprintf(stderr, "[%s:%d](%s) ==== get witness === \n", __FILE_NAME__, __LINE__, __FUNCTION__);
763
+
764
+
765
+ // decoderProtocolWitness->dump();
766
+ // auto genSig = Target->getGenericSignature();
767
+ // assert(genSig && "Accessor must be generic, because we always have a generic Decoder");
768
+ //
769
+ // fprintf(stderr, "[%s:%d](%s) signature [%d] =======\n", __FILE_NAME__, __LINE__, __FUNCTION__,
770
+ // genSig.getGenericParams().size());
771
+ // genSig.dump();
772
+ //
773
+ // fprintf(stderr, "[%s:%d](%s) drop more size %d \n", __FILE_NAME__, __LINE__, __FUNCTION__,
774
+ // genSig.getGenericParams().size());
775
+ // params.claimAll();
776
+
777
+
778
+ // for (int i = 0; i < genSig.getGenericParams().size(); ++i) {
779
+ // }
780
+ // auto ps = params.claim(genSig.getGenericParams().size());
781
+ // // decoderProtocolWitness = ps.back();
782
+ // for (auto a : ps) {
783
+ // fprintf(stderr, "[%s:%d](%s) === ignore witness param:\n", __FILE_NAME__, __LINE__, __FUNCTION__);
784
+ // a->dump();
785
+ // // for (auto a : params.claim(genSig.getGenericParams().size())) {
786
+ // // fprintf(stderr, "[%s:%d](%s) ignore more param:\n", __FILE_NAME__, __LINE__, __FUNCTION__);
787
+ // // a->dump();
788
+ // // }
678
789
679
790
// Preliminary: Setup async context for this accessor.
680
791
{
0 commit comments