@@ -735,6 +735,16 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM,
735
735
// Create a new explosion for potentially reabstracted parameters.
736
736
Explosion args;
737
737
738
+ // SWIFT_ENABLE_TENSORFLOW
739
+ // The witness method self argument comes after polymorphic arguments (and is
740
+ // followed by the self type and the witness table). However, we may encounter
741
+ // the witness method self value before reaching the polymorphic arguments. So
742
+ // we create a special explosion for storing the witness method self value
743
+ // until it's time to add it to 'args'.
744
+ bool isWitnessMethodCallee = origType->getRepresentation () ==
745
+ SILFunctionTypeRepresentation::WitnessMethod;
746
+ Explosion witnessMethodSelfValue;
747
+
738
748
Address resultValueAddr;
739
749
740
750
{
@@ -775,6 +785,10 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM,
775
785
776
786
// Reemit the parameters as unsubstituted.
777
787
for (unsigned i = 0 ; i < outType->getParameters ().size (); ++i) {
788
+ // SWIFT_ENABLE_TENSORFLOW
789
+ bool isWitnessMethodCalleeSelf =
790
+ (isWitnessMethodCallee && i + 1 == origType->getParameters ().size ());
791
+
778
792
auto origParamInfo = origType->getParameters ()[i];
779
793
auto &ti = IGM.getTypeInfoForLowered (origParamInfo.getType ());
780
794
auto schema = ti.getSchema ();
@@ -788,16 +802,19 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM,
788
802
if (addr->getType () != ti.getStorageType ()->getPointerTo ())
789
803
addr = subIGF.Builder .CreateBitCast (addr,
790
804
ti.getStorageType ()->getPointerTo ());
791
- args.add (addr);
805
+ // SWIFT_ENABLE_TENSORFLOW
806
+ (isWitnessMethodCalleeSelf ? witnessMethodSelfValue : args).add (addr);
792
807
continue ;
793
808
}
794
809
795
810
auto outTypeParamInfo = outType->getParameters ()[i];
796
811
// Indirect parameters need no mapping through the native calling
797
812
// convention.
798
813
if (isIndirectParam) {
799
- emitApplyArgument (subIGF, origParamInfo, outTypeParamInfo, origParams,
800
- args);
814
+ emitApplyArgument (
815
+ subIGF, origParamInfo, outTypeParamInfo, origParams,
816
+ // SWIFT_ENABLE_TENSORFLOW
817
+ (isWitnessMethodCalleeSelf ? witnessMethodSelfValue : args));
801
818
continue ;
802
819
}
803
820
@@ -824,7 +841,10 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM,
824
841
Explosion nativeApplyArg = nativeSchemaOrigParam.mapIntoNative (
825
842
subIGF.IGM , subIGF, nonNativeApplyArg, origParamSILType, false );
826
843
assert (nonNativeApplyArg.empty ());
827
- nativeApplyArg.transferInto (args, nativeApplyArg.size ());
844
+ // SWIFT_ENABLE_TENSORFLOW
845
+ nativeApplyArg.transferInto (
846
+ (isWitnessMethodCalleeSelf ? witnessMethodSelfValue : args),
847
+ nativeApplyArg.size ());
828
848
}
829
849
}
830
850
@@ -934,13 +954,6 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM,
934
954
auto haveContextArgument =
935
955
calleeHasContext || hasSelfContextParameter (origType);
936
956
937
- // Witness method calls expect self, followed by the self type followed by,
938
- // the witness table at the end of the parameter list. But polymorphic
939
- // arguments come before this.
940
- bool isWitnessMethodCallee = origType->getRepresentation () ==
941
- SILFunctionTypeRepresentation::WitnessMethod;
942
- Explosion witnessMethodSelfValue;
943
-
944
957
// If there's a data pointer required, but it's a swift-retainable
945
958
// value being passed as the context, just forward it down.
946
959
if (!layout) {
0 commit comments