@@ -892,11 +892,102 @@ namespace {
892
892
AnyFunctionType::CanParamArrayRef inputSubstTypes,
893
893
AbstractionPattern outputOrigFunctionType,
894
894
AnyFunctionType::CanParamArrayRef outputSubstTypes) {
895
+ // FIXME: Do we ever do opaque-to-opaque reabstractions?
896
+ assert (!inputOrigFunctionType.isTypeParameter () ||
897
+ !outputOrigFunctionType.isTypeParameter ());
898
+
899
+ auto getSubstTupleType = [&](AnyFunctionType::CanParamArrayRef params) {
900
+ return cast<TupleType>(
901
+ AnyFunctionType::composeInput (SGF.getASTContext (),
902
+ params, /* canonicalVararg=*/ true )
903
+ ->getCanonicalType ());
904
+ };
905
+
906
+ auto getOrigParamTypes = [&](AbstractionPattern origFunctionType) {
907
+ SmallVector<AbstractionPattern, 8 > origTypes;
908
+ for (unsigned i = 0 , e = origFunctionType.getNumFunctionParams ();
909
+ i < e; ++i) {
910
+ origTypes.push_back (origFunctionType.getFunctionParamType (i));
911
+ }
912
+
913
+ return origTypes;
914
+ };
915
+
916
+ if (inputOrigFunctionType.isTypeParameter () &&
917
+ !outputOrigFunctionType.isTypeParameter () &&
918
+ inputSubstTypes.size () != 1 &&
919
+ !shouldExpandParams (inputSubstTypes)) {
920
+ // The output is exploded and the input is not. Decompose an
921
+ // input tuple and translate the elements.
922
+ auto inputTupleType = getSubstTupleType (inputSubstTypes);
923
+ auto outputTupleType = getSubstTupleType (outputSubstTypes);
924
+
925
+ auto outputOrigTypes = getOrigParamTypes (outputOrigFunctionType);
926
+ auto outputOrigType = AbstractionPattern::getTuple (outputOrigTypes);
927
+
928
+ translateAndExplodeOutOf (AbstractionPattern::getOpaque (),
929
+ inputTupleType,
930
+ outputOrigType,
931
+ outputTupleType,
932
+ claimNextInput ());
933
+ return ;
934
+ }
935
+
936
+ if (!inputOrigFunctionType.isTypeParameter () &&
937
+ outputOrigFunctionType.isTypeParameter () &&
938
+ outputSubstTypes.size () != 1 &&
939
+ !shouldExpandParams (outputSubstTypes)) {
940
+ // The input is exploded and the output is not. Translate values
941
+ // and store them to a result tuple in memory.
942
+ auto inputTupleType = getSubstTupleType (inputSubstTypes);
943
+ auto outputTupleType = getSubstTupleType (outputSubstTypes);
944
+
945
+ auto inputOrigTypes = getOrigParamTypes (inputOrigFunctionType);
946
+ auto inputOrigType = AbstractionPattern::getTuple (inputOrigTypes);
947
+
948
+ auto outputTy = SGF.getSILType (claimNextOutputType ());
949
+ auto &outputTL = SGF.getTypeLowering (outputTy);
950
+ if (SGF.silConv .useLoweredAddresses ()) {
951
+ auto temp = SGF.emitTemporary (Loc, outputTL);
952
+ translateAndImplodeInto (
953
+ inputOrigType,
954
+ inputTupleType,
955
+ AbstractionPattern::getOpaque (),
956
+ outputTupleType,
957
+ *temp);
958
+ Outputs.push_back (temp->getManagedAddress ());
959
+ } else {
960
+ auto result = translateAndImplodeIntoValue (
961
+ inputOrigType,
962
+ inputTupleType,
963
+ AbstractionPattern::getOpaque (),
964
+ outputTupleType,
965
+ outputTL.getLoweredType ());
966
+ Outputs.push_back (result);
967
+ }
968
+ return ;
969
+ }
970
+
971
+ if (inputSubstTypes.size () == 1 &&
972
+ outputSubstTypes.size () != 1 ) {
973
+ // SE-0110 tuple splat. Turn the output into a single value of tuple
974
+ // type, and translate.
975
+ auto inputOrigType = inputOrigFunctionType.getFunctionParamType (0 );
976
+ auto inputSubstType = inputSubstTypes[0 ].getPlainType ();
977
+
978
+ auto outputOrigTypes = getOrigParamTypes (outputOrigFunctionType);
979
+ auto outputOrigType = AbstractionPattern::getTuple (outputOrigTypes);
980
+ auto outputSubstType = getSubstTupleType (outputSubstTypes);
981
+
982
+ translate (inputOrigType, inputSubstType,
983
+ outputOrigType, outputSubstType);
984
+ return ;
985
+ }
986
+
895
987
assert (inputSubstTypes.size () == outputSubstTypes.size ());
896
988
897
989
SmallVector<AbstractionPattern, 8 > inputOrigTypes;
898
990
SmallVector<AbstractionPattern, 8 > outputOrigTypes;
899
-
900
991
for (auto i : indices (inputSubstTypes)) {
901
992
inputOrigTypes.push_back (inputOrigFunctionType.getFunctionParamType (i));
902
993
outputOrigTypes.push_back (outputOrigFunctionType.getFunctionParamType (i));
@@ -2854,10 +2945,10 @@ static void buildThunkBody(SILGenFunction &SGF, SILLocation loc,
2854
2945
// like a normal Int when calling the inner function).
2855
2946
SmallVector<ManagedValue, 8 > args;
2856
2947
TranslateArguments (SGF, loc, params, args, argTypes)
2857
- .translate (outputOrigType. getFunctionInputType () ,
2858
- outputSubstType.getInput (),
2859
- inputOrigType. getFunctionInputType () ,
2860
- inputSubstType.getInput ());
2948
+ .translate (outputOrigType,
2949
+ outputSubstType.getParams (),
2950
+ inputOrigType,
2951
+ inputSubstType.getParams ());
2861
2952
2862
2953
SmallVector<SILValue, 8 > argValues;
2863
2954
0 commit comments