@@ -1135,78 +1135,12 @@ class TranslateArguments {
1135
1135
outputTupleType);
1136
1136
}
1137
1137
1138
- // Tuple types are subtypes of their optionals
1139
- if (auto outputObjectType = outputSubstType.getOptionalObjectType ()) {
1140
- auto outputOrigObjectType = outputOrigType.getOptionalObjectType ();
1141
-
1142
- if (auto outputTupleType = dyn_cast<TupleType>(outputObjectType)) {
1143
- // The input is exploded and the output is an optional tuple.
1144
- // Translate values and collect them into a single optional
1145
- // payload.
1146
-
1147
- auto result =
1148
- translateAndImplodeIntoOptional (inputOrigType,
1149
- inputTupleType,
1150
- outputOrigObjectType,
1151
- outputTupleType);
1152
- Outputs.push_back (result);
1153
- return ;
1154
- }
1155
-
1156
- // Tuple types are subtypes of optionals of Any, too.
1157
- assert (outputObjectType->isAny ());
1158
-
1159
- // First, construct the existential.
1160
- auto result =
1161
- translateAndImplodeIntoAny (inputOrigType,
1162
- inputTupleType,
1163
- outputOrigObjectType,
1164
- outputObjectType);
1165
-
1166
- // Now, convert it to an optional.
1167
- translateSingle (outputOrigObjectType, outputObjectType,
1168
- outputOrigType, outputSubstType,
1169
- result, claimNextOutputType ());
1170
- return ;
1171
- }
1172
-
1173
- if (outputSubstType->isAny ()) {
1174
- claimNextOutputType ();
1175
-
1176
- auto result =
1177
- translateAndImplodeIntoAny (inputOrigType,
1178
- inputTupleType,
1179
- outputOrigType,
1180
- outputSubstType);
1181
- Outputs.push_back (result);
1182
- return ;
1183
- }
1184
-
1185
- if (outputTupleType) {
1186
- // The input is exploded and the output is not. Translate values
1187
- // and store them to a result tuple in memory.
1188
- assert (outputOrigType.isTypeParameter () &&
1189
- " Output is not a tuple and is not opaque?" );
1190
-
1191
- auto outputTy = SGF.getSILType (claimNextOutputType (),
1192
- OutputTypesFuncTy);
1193
- auto &outputTL = SGF.getTypeLowering (outputTy);
1194
- if (SGF.silConv .useLoweredAddresses ()) {
1195
- auto temp = SGF.emitTemporary (Loc, outputTL);
1196
- translateAndImplodeInto (inputOrigType, inputTupleType,
1197
- outputOrigType, outputTupleType, *temp);
1198
-
1199
- Outputs.push_back (temp->getManagedAddress ());
1200
- } else {
1201
- auto result = translateAndImplodeIntoValue (
1202
- inputOrigType, inputTupleType, outputOrigType, outputTupleType,
1203
- outputTL.getLoweredType ());
1204
- Outputs.push_back (result);
1205
- }
1206
- return ;
1207
- }
1208
-
1209
- llvm_unreachable (" Unhandled conversion from exploded tuple" );
1138
+ auto outputParam = claimNextOutputType ();
1139
+ return translateTupleIntoSingle (inputOrigType,
1140
+ inputTupleType,
1141
+ outputOrigType,
1142
+ outputSubstType,
1143
+ outputParam);
1210
1144
}
1211
1145
1212
1146
// Handle output being an exploded tuple when the input is opaque.
@@ -1238,6 +1172,85 @@ class TranslateArguments {
1238
1172
}
1239
1173
1240
1174
private:
1175
+ void translateTupleIntoSingle (AbstractionPattern inputOrigType,
1176
+ CanTupleType inputSubstType,
1177
+ AbstractionPattern outputOrigType,
1178
+ CanType outputSubstType,
1179
+ SILParameterInfo outputParam) {
1180
+ // Tuple types are subtypes of their optionals
1181
+ if (auto outputObjectType = outputSubstType.getOptionalObjectType ()) {
1182
+ auto outputOrigObjectType = outputOrigType.getOptionalObjectType ();
1183
+
1184
+ if (auto outputTupleType = dyn_cast<TupleType>(outputObjectType)) {
1185
+ // The input is exploded and the output is an optional tuple.
1186
+ // Translate values and collect them into a single optional
1187
+ // payload.
1188
+
1189
+ auto result =
1190
+ translateAndImplodeIntoOptional (inputOrigType,
1191
+ inputSubstType,
1192
+ outputOrigObjectType,
1193
+ outputTupleType,
1194
+ outputParam);
1195
+ Outputs.push_back (result);
1196
+ return ;
1197
+ }
1198
+
1199
+ // Tuple types are subtypes of optionals of Any, too.
1200
+ assert (outputObjectType->isAny ());
1201
+
1202
+ // First, construct the existential.
1203
+ auto result =
1204
+ translateAndImplodeIntoAny (inputOrigType,
1205
+ inputSubstType,
1206
+ outputOrigObjectType,
1207
+ outputObjectType);
1208
+
1209
+ // Now, convert it to an optional.
1210
+ translateSingle (outputOrigObjectType, outputObjectType,
1211
+ outputOrigType, outputSubstType,
1212
+ result, outputParam);
1213
+ return ;
1214
+ }
1215
+
1216
+ if (outputSubstType->isAny ()) {
1217
+ // We don't need outputParam on this path.
1218
+
1219
+ auto result =
1220
+ translateAndImplodeIntoAny (inputOrigType,
1221
+ inputSubstType,
1222
+ outputOrigType,
1223
+ outputSubstType);
1224
+ Outputs.push_back (result);
1225
+ return ;
1226
+ }
1227
+
1228
+ if (auto outputTupleType = dyn_cast<TupleType>(outputSubstType)) {
1229
+ // The input is exploded and the output is not. Translate values
1230
+ // and store them to a result tuple in memory.
1231
+ assert (outputOrigType.isTypeParameter () &&
1232
+ " Output is not a tuple and is not opaque?" );
1233
+
1234
+ auto outputTy = SGF.getSILType (outputParam, OutputTypesFuncTy);
1235
+ auto &outputTL = SGF.getTypeLowering (outputTy);
1236
+ if (SGF.silConv .useLoweredAddresses ()) {
1237
+ auto temp = SGF.emitTemporary (Loc, outputTL);
1238
+ translateAndImplodeInto (inputOrigType, inputSubstType,
1239
+ outputOrigType, outputTupleType, *temp);
1240
+
1241
+ Outputs.push_back (temp->getManagedAddress ());
1242
+ } else {
1243
+ auto result = translateAndImplodeIntoValue (
1244
+ inputOrigType, inputSubstType, outputOrigType, outputTupleType,
1245
+ outputTL.getLoweredType ());
1246
+ Outputs.push_back (result);
1247
+ }
1248
+ return ;
1249
+ }
1250
+
1251
+ llvm_unreachable (" Unhandled conversion from exploded tuple" );
1252
+ }
1253
+
1241
1254
// / Take a tuple that has been exploded in the input and turn it into
1242
1255
// / a tuple value in the output.
1243
1256
ManagedValue translateAndImplodeIntoValue (AbstractionPattern inputOrigType,
@@ -1309,15 +1322,15 @@ class TranslateArguments {
1309
1322
translateAndImplodeIntoOptional (AbstractionPattern inputOrigType,
1310
1323
CanTupleType inputTupleType,
1311
1324
AbstractionPattern outputOrigType,
1312
- CanTupleType outputTupleType) {
1325
+ CanTupleType outputTupleType,
1326
+ SILParameterInfo outputParam) {
1313
1327
assert (inputTupleType->getNumElements () ==
1314
1328
outputTupleType->getNumElements ());
1315
1329
1316
1330
// Collect the tuple elements.
1317
1331
auto &loweredTL = SGF.getTypeLowering (outputOrigType, outputTupleType);
1318
1332
auto loweredTy = loweredTL.getLoweredType ();
1319
- auto optionalTy = SGF.getSILType (claimNextOutputType (),
1320
- OutputTypesFuncTy);
1333
+ auto optionalTy = SGF.getSILType (outputParam, OutputTypesFuncTy);
1321
1334
auto someDecl = SGF.getASTContext ().getOptionalSomeDecl ();
1322
1335
if (loweredTL.isLoadable () || !SGF.silConv .useLoweredAddresses ()) {
1323
1336
auto payload =
0 commit comments