Skip to content

Commit 17e6ac3

Browse files
committed
stuck
1 parent 78cbb89 commit 17e6ac3

File tree

7 files changed

+763
-97
lines changed

7 files changed

+763
-97
lines changed

lib/AST/GenericSignature.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,20 @@ GenericSignatureImpl::GenericSignatureImpl(
5353
getTrailingObjects<GenericTypeParamType *>());
5454
std::uninitialized_copy(requirements.begin(), requirements.end(),
5555
getTrailingObjects<Requirement>());
56-
56+
//fprintf(stderr, "[%s:%d](%s) ========================================\n", __FILE_NAME__, __LINE__, __FUNCTION__);
57+
//fprintf(stderr, "[%s:%d](%s) requirements -------\n", __FILE_NAME__, __LINE__, __FUNCTION__);
58+
//for (auto req : requirements) {
59+
// req.dump();
60+
//}
61+
//fprintf(stderr, "[%s:%d](%s) params -------\n", __FILE_NAME__, __LINE__, __FUNCTION__);
5762
#ifndef NDEBUG
5863
// Make sure generic parameters are in the right order, and
5964
// none are missing.
6065
unsigned depth = 0;
6166
unsigned count = 0;
6267
for (auto param : params) {
68+
// fprintf(stderr, "[%s:%d](%s) param = \n", __FILE_NAME__, __LINE__, __FUNCTION__);
69+
// param->dump();
6370
if (param->getDepth() != depth) {
6471
assert(param->getDepth() > depth && "Generic parameter depth mismatch");
6572
depth = param->getDepth();

lib/IRGen/Explosion.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ class Explosion {
6565
}
6666

6767
~Explosion() {
68+
//#ifndef NDEBUG
69+
// if (!empty()) {
70+
// fprintf(stderr, "[%s:%d](%s) remaining:::: \n", __FILE_NAME__, __LINE__, __FUNCTION__);
71+
// for (auto a : claimAll()) {
72+
// a->dump();
73+
// }
74+
// assert(false);
75+
// }
76+
//#endif
77+
6878
assert(empty() && "explosion had values remaining when destroyed!");
6979
}
7080

lib/IRGen/GenDistributed.cpp

Lines changed: 138 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
204204
SILFunction *Target) {
205205
auto &Context = IGM.Context;
206206

207-
// func __accessor__<D: DistributedTargetInvocationDecoder>(
207+
// func __accessor__<..., D: DistributedTargetInvocationDecoder>(
208+
// <... other generics ...>
208209
// inout D, <- invocation decoder
209210
// UnsafeRawPointer, <- argument types
210211
// UnsafeRawPointer, <- result buffer
@@ -216,10 +217,19 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
216217

217218
SmallVector<GenericFunctionType::Param, 8> parameters;
218219

220+
unsigned decoderTypeParamDepth = 0;
221+
if (auto genSig = Target->getGenericSignature()) {
222+
decoderTypeParamDepth = genSig.getGenericParams().back()->getDepth() + 1;
223+
}
224+
219225
// A generic parameter that represents instance of invocation decoder.
220226
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();
223233

224234
// decoder
225235
parameters.push_back(GenericFunctionType::Param(
@@ -251,6 +261,10 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
251261
auto targetTy = Target->getLoweredFunctionType();
252262
auto actorLoc = targetTy->getParameters().back();
253263

264+
// fprintf(stderr, "[%s:%d](%s) THE TARGET:\n", __FILE_NAME__, __LINE__, __FUNCTION__);
265+
// Target->dump();
266+
// targetTy.dump();
267+
254268
parameters.push_back(
255269
GenericFunctionType::Param(actorLoc.getInterfaceType()));
256270
}
@@ -269,30 +283,34 @@ static CanSILFunctionType getAccessorType(IRGenModule &IGM,
269283
auto *actor = getDistributedActorOf(Target);
270284
assert(actor);
271285

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;
288291
}
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+
// }
289305

290306
auto decoderParamTy = GenericTypeParamType::get(
291-
// /*isParameterPack=*/false, /*depth=*/1, /*index=*/1, Context);
292307
/*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
295310
Context);
311+
fprintf(stderr, "[%s:%d](%s) THE PARAM\n", __FILE_NAME__, __LINE__, __FUNCTION__);
312+
decoderParamTy->dump();
313+
296314
addedParameters.push_back(decoderParamTy);
297315

298316
// Add a requirement that decoder conforms to the expected protocol.
@@ -636,45 +654,138 @@ void DistributedAccessor::emit() {
636654
SILFunctionConventions targetConv(targetTy, IGF.getSILModule());
637655
TypeExpansionContext expansionContext = IGM.getMaximalTypeExpansionContext();
638656

657+
IGF.CurFn->dump();
658+
639659
auto params = IGF.collectParameters();
640660

641661
GenericContextScope scope(IGM, targetTy->getInvocationGenericSignature());
642662

643663
auto directResultTy = targetConv.getSILResultType(expansionContext);
644664
const auto &directResultTI = IGM.getTypeInfo(directResultTy);
645665

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+
646671
Explosion arguments;
647672

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+
648681
unsigned numAsyncContextParams =
649682
(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+
}
651688

652689
// A container that produces argument values based on the given set of
653690
// argument types (supplied as a next argument).
654691
auto *argDecoder = params.claimNext();
692+
fprintf(stderr, "[%s:%d](%s) ==== get arg decoder \n", __FILE_NAME__, __LINE__, __FUNCTION__);
693+
argDecoder->dump();
655694
// `swift.type**` that holds the argument types that correspond to values.
656695
auto *argTypes = params.claimNext();
696+
fprintf(stderr, "[%s:%d](%s) ==== get argTypes \n", __FILE_NAME__, __LINE__, __FUNCTION__);
697+
argTypes->dump();
657698
// UnsafeRawPointer that is used to store the result.
658699
auto *resultBuffer = params.claimNext();
700+
fprintf(stderr, "[%s:%d](%s) ==== get resultBuffer \n", __FILE_NAME__, __LINE__, __FUNCTION__);
701+
resultBuffer->dump();
659702
// UnsafeRawPointer that represents a list of substitutions
660703
auto *substitutions = params.claimNext();
704+
fprintf(stderr, "[%s:%d](%s) ==== get substitutions \n", __FILE_NAME__, __LINE__, __FUNCTION__);
705+
substitutions->dump();
661706
// UnsafeRawPointer that represents a list of witness tables
662707
auto *witnessTables = params.claimNext();
708+
fprintf(stderr, "[%s:%d](%s) ==== get witnessTables \n", __FILE_NAME__, __LINE__, __FUNCTION__);
709+
witnessTables->dump();
663710
// Integer that represented the number of witness tables
664711
auto *numWitnessTables = params.claimNext();
712+
fprintf(stderr, "[%s:%d](%s) ==== get numWitnessTables \n", __FILE_NAME__, __LINE__, __FUNCTION__);
713+
numWitnessTables->dump();
665714
// Reference to a `self` of the actor to be called.
666715
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+
// }
667726
// 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+
}
669742

670743
// If the distributed thunk is declared in a protocol that conforms
671744
// to `DistributedActor` protocol, there is an extract parameter that
672745
// 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+
}
675751

676752
// 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+
//// }
678789

679790
// Preliminary: Setup async context for this accessor.
680791
{

stdlib/public/Distributed/DistributedActor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ using TargetExecutorSignature =
6262
/*numWitnessTables=*/size_t,
6363
/*decoderType=*/Metadata *,
6464
/*decoderWitnessTable=*/void **),
65-
/*throws=*/true>;
65+
/*throws=*/true>;
6666

6767
SWIFT_CC(swiftasync)
6868
SWIFT_EXPORT_FROM(swiftDistributed)
@@ -89,7 +89,7 @@ using DistributedAccessorSignature =
8989
/*actor=*/HeapObject *,
9090
/*decoderType=*/Metadata *,
9191
/*decoderWitnessTable=*/void **),
92-
/*throws=*/true>;
92+
/*throws=*/true>;
9393

9494
SWIFT_CC(swiftasync)
9595
static DistributedAccessorSignature::ContinuationType
@@ -150,6 +150,7 @@ void swift_distributed_execute_target(
150150
calleeContext->ResumeParent = reinterpret_cast<TaskContinuationFunction *>(
151151
swift_distributed_execute_target_resume);
152152

153+
// TODO: we call the accessor like this... there's no variable nr of generics here
153154
accessorEntry(calleeContext,
154155
argumentDecoder,
155156
argumentTypes,

0 commit comments

Comments
 (0)