@@ -125,12 +125,43 @@ struct ArgumentDecoderInfo {
125
125
Callee getCallee () const ;
126
126
};
127
127
128
+ struct AccessorTarget {
129
+ private:
130
+ IRGenFunction &IGF;
131
+ SILFunction *Target;
132
+
133
+ CanSILFunctionType Type;
134
+
135
+ public:
136
+ AccessorTarget (IRGenFunction &IGF, SILFunction *target)
137
+ : IGF(IGF), Target(target), Type(target->getLoweredFunctionType ()) {}
138
+
139
+ DeclContext *getDeclContext () const { return Target->getDeclContext (); }
140
+
141
+ CanSILFunctionType getType () const { return Type; }
142
+
143
+ bool isGeneric () const { return Target->isGeneric (); }
144
+
145
+ Callee getCallee (llvm::Value *actorSelf) const ;
146
+
147
+ LinkEntity getLinking () const {
148
+ return LinkEntity::forDistributedTargetAccessor (Target);
149
+ }
150
+
151
+ WitnessMetadata *getWitnessMetadata () const {
152
+ return nullptr ;
153
+ }
154
+
155
+ public:
156
+ FunctionPointer getPointerToTarget () const ;
157
+ };
158
+
128
159
class DistributedAccessor {
129
160
IRGenModule &IGM;
130
161
IRGenFunction &IGF;
131
162
132
163
// / Underlying distributed method for this accessor.
133
- SILFunction * Target;
164
+ AccessorTarget Target;
134
165
135
166
// / The interface type of this accessor function.
136
167
CanSILFunctionType AccessorType;
@@ -178,10 +209,6 @@ class DistributedAccessor {
178
209
// / all the argument allocations.
179
210
void emitReturn (llvm::Value *errorValue);
180
211
181
- FunctionPointer getPointerToTarget () const ;
182
-
183
- Callee getCalleeForDistributedTarget (llvm::Value *self) const ;
184
-
185
212
// / Given an instance of invocation decoder, its type metadata,
186
213
// / and protocol witness table, find `decodeNextArgument`.
187
214
ArgumentDecoderInfo findArgumentDecoder (llvm::Value *decoder,
@@ -318,17 +345,17 @@ void IRGenModule::emitDistributedTargetAccessor(SILFunction *target) {
318
345
DistributedAccessor::DistributedAccessor (IRGenFunction &IGF,
319
346
SILFunction *target,
320
347
CanSILFunctionType accessorTy)
321
- : IGM(IGF.IGM), IGF(IGF), Target(target), AccessorType(accessorTy),
322
- AsyncLayout(getAsyncContextLayout(
323
- IGM, AccessorType, AccessorType, SubstitutionMap())) {
348
+ : IGM(IGF.IGM), IGF(IGF), Target(IGF, target), AccessorType(accessorTy),
349
+ AsyncLayout(getAsyncContextLayout(IGM, AccessorType, AccessorType,
350
+ SubstitutionMap ())) {
324
351
if (IGM.DebugInfo )
325
352
IGM.DebugInfo ->emitArtificialFunction (IGF, IGF.CurFn );
326
353
}
327
354
328
355
void DistributedAccessor::decodeArguments (const ArgumentDecoderInfo &decoder,
329
356
llvm::Value *argumentTypes,
330
357
Explosion &arguments) {
331
- auto fnType = Target-> getLoweredFunctionType ();
358
+ auto fnType = Target. getType ();
332
359
333
360
// Cover all of the arguments except to `self` of the actor.
334
361
auto parameters = fnType->getParameters ().drop_back ();
@@ -612,7 +639,7 @@ void DistributedAccessor::emitReturn(llvm::Value *errorValue) {
612
639
}
613
640
614
641
void DistributedAccessor::emit () {
615
- auto targetTy = Target-> getLoweredFunctionType ();
642
+ auto targetTy = Target. getType ();
616
643
SILFunctionConventions targetConv (targetTy, IGF.getSILModule ());
617
644
TypeExpansionContext expansionContext = IGM.getMaximalTypeExpansionContext ();
618
645
@@ -657,7 +684,7 @@ void DistributedAccessor::emit() {
657
684
Signature::forAsyncEntry (IGM, AccessorType, fpKind)
658
685
.getAsyncContextIndex ();
659
686
660
- auto entity = LinkEntity::forDistributedTargetAccessor ( Target);
687
+ auto entity = Target. getLinking ( );
661
688
emitAsyncFunctionEntry (IGF, AsyncLayout, entity, asyncContextIdx);
662
689
emitAsyncFunctionPointer (IGM, IGF.CurFn , entity, AsyncLayout.getSize ());
663
690
}
@@ -687,7 +714,7 @@ void DistributedAccessor::emit() {
687
714
}
688
715
689
716
// Add all of the substitutions to the explosion
690
- if (Target-> isGeneric ()) {
717
+ if (Target. isGeneric ()) {
691
718
// swift.type **
692
719
llvm::Value *substitutionBuffer =
693
720
IGF.Builder .CreateBitCast (substitutions, IGM.TypeMetadataPtrPtrTy );
@@ -726,13 +753,13 @@ void DistributedAccessor::emit() {
726
753
Explosion result;
727
754
llvm::Value *targetError = nullptr ;
728
755
729
- auto callee = getCalleeForDistributedTarget (actorSelf);
756
+ auto callee = Target. getCallee (actorSelf);
730
757
auto emission =
731
758
getCallEmission (IGF, callee.getSwiftContext (), std::move (callee));
732
759
733
760
emission->begin ();
734
761
emission->setArgs (arguments, /* isOutlined=*/ false ,
735
- /* witnessMetadata= */ nullptr );
762
+ Target. getWitnessMetadata () );
736
763
737
764
// Load result of the thunk into the location provided by the caller.
738
765
// This would only generate code for direct results, if thunk has an
@@ -763,31 +790,29 @@ void DistributedAccessor::emit() {
763
790
}
764
791
}
765
792
766
- FunctionPointer DistributedAccessor ::getPointerToTarget () const {
767
- auto fnType = Target-> getLoweredFunctionType () ;
793
+ FunctionPointer AccessorTarget ::getPointerToTarget () const {
794
+ auto &IGM = IGF. IGM ;
768
795
auto fpKind = classifyFunctionPointerKind (Target);
769
- auto signature = IGM.getSignature (fnType , fpKind);
796
+ auto signature = IGM.getSignature (Type , fpKind);
770
797
771
798
auto *fnPtr =
772
799
llvm::ConstantExpr::getBitCast (IGM.getAddrOfAsyncFunctionPointer (Target),
773
800
signature.getType ()->getPointerTo ());
774
801
775
802
return FunctionPointer::forDirect (
776
- FunctionPointer::Kind (fnType ), fnPtr,
803
+ FunctionPointer::Kind (Type ), fnPtr,
777
804
IGM.getAddrOfSILFunction (Target, NotForDefinition), signature);
778
805
}
779
806
780
- Callee
781
- DistributedAccessor::getCalleeForDistributedTarget (llvm::Value *self) const {
782
- auto fnType = Target->getLoweredFunctionType ();
783
- CalleeInfo info{fnType, fnType, SubstitutionMap ()};
784
- return {std::move (info), getPointerToTarget (), self};
807
+ Callee AccessorTarget::getCallee (llvm::Value *actorSelf) const {
808
+ CalleeInfo info{Type, Type, SubstitutionMap ()};
809
+ return {std::move (info), getPointerToTarget (), actorSelf};
785
810
}
786
811
787
812
ArgumentDecoderInfo DistributedAccessor::findArgumentDecoder (
788
813
llvm::Value *decoder, llvm::Value *decoderTy, llvm::Value *witnessTable) {
789
814
auto &C = IGM.Context ;
790
- DeclContext *targetContext = Target-> getDeclContext ();
815
+ DeclContext *targetContext = Target. getDeclContext ();
791
816
auto expansionContext = IGM.getMaximalTypeExpansionContext ();
792
817
793
818
// / If the context was a function, unwrap it and look for the decode method
@@ -796,10 +821,9 @@ ArgumentDecoderInfo DistributedAccessor::findArgumentDecoder(
796
821
FuncDecl *decodeFn = nullptr ;
797
822
if (auto func = dyn_cast<AbstractFunctionDecl>(targetContext)) {
798
823
decodeFn = C.getDistributedActorArgumentDecodingMethod (
799
- func->getDeclContext ()->getSelfNominalTypeDecl ());;
824
+ func->getDeclContext ()->getSelfNominalTypeDecl ());
800
825
}
801
826
802
-
803
827
// If distributed actor is generic over actor system, we have to
804
828
// use witness to reference `decodeNextArgument`.
805
829
if (!decodeFn) {
0 commit comments