@@ -1106,9 +1106,11 @@ class TranslateArguments {
1106
1106
auto inputValue = claimNextInput ();
1107
1107
auto outputLoweredTy = claimNextOutputType ();
1108
1108
1109
- translateInOut (inputOrigType, inputSubstType.getParameterType (),
1110
- outputOrigType, outputSubstType.getParameterType (),
1111
- inputValue, outputLoweredTy);
1109
+ ManagedValue output =
1110
+ translateInOut (inputOrigType, inputSubstType.getParameterType (),
1111
+ outputOrigType, outputSubstType.getParameterType (),
1112
+ inputValue, outputLoweredTy);
1113
+ Outputs.push_back (output);
1112
1114
} else {
1113
1115
translate (inputOrigType, inputSubstType.getParameterType (),
1114
1116
outputOrigType, outputSubstType.getParameterType ());
@@ -1136,11 +1138,13 @@ class TranslateArguments {
1136
1138
}
1137
1139
1138
1140
auto outputParam = claimNextOutputType ();
1139
- return translateTupleIntoSingle (inputOrigType,
1140
- inputTupleType,
1141
- outputOrigType,
1142
- outputSubstType,
1143
- outputParam);
1141
+ auto output = translateTupleIntoSingle (inputOrigType,
1142
+ inputTupleType,
1143
+ outputOrigType,
1144
+ outputSubstType,
1145
+ outputParam);
1146
+ Outputs.push_back (output);
1147
+ return ;
1144
1148
}
1145
1149
1146
1150
// Handle output being an exploded tuple when the input is opaque.
@@ -1166,17 +1170,19 @@ class TranslateArguments {
1166
1170
// single value.
1167
1171
auto inputElt = claimNextInput ();
1168
1172
auto outputEltType = claimNextOutputType ();
1169
- translateSingle (inputOrigType, inputSubstType,
1170
- outputOrigType, outputSubstType,
1171
- inputElt, outputEltType);
1173
+ auto output = translateSingle (inputOrigType, inputSubstType,
1174
+ outputOrigType, outputSubstType,
1175
+ inputElt, outputEltType);
1176
+ Outputs.push_back (output);
1172
1177
}
1173
1178
1174
1179
private:
1175
- void translateTupleIntoSingle (AbstractionPattern inputOrigType,
1176
- CanTupleType inputSubstType,
1177
- AbstractionPattern outputOrigType,
1178
- CanType outputSubstType,
1179
- SILParameterInfo outputParam) {
1180
+ ManagedValue
1181
+ translateTupleIntoSingle (AbstractionPattern inputOrigType,
1182
+ CanTupleType inputSubstType,
1183
+ AbstractionPattern outputOrigType,
1184
+ CanType outputSubstType,
1185
+ SILParameterInfo outputParam) {
1180
1186
// Tuple types are subtypes of their optionals
1181
1187
if (auto outputObjectType = outputSubstType.getOptionalObjectType ()) {
1182
1188
auto outputOrigObjectType = outputOrigType.getOptionalObjectType ();
@@ -1192,8 +1198,7 @@ class TranslateArguments {
1192
1198
outputOrigObjectType,
1193
1199
outputTupleType,
1194
1200
outputParam);
1195
- Outputs.push_back (result);
1196
- return ;
1201
+ return result;
1197
1202
}
1198
1203
1199
1204
// Tuple types are subtypes of optionals of Any, too.
@@ -1207,22 +1212,18 @@ class TranslateArguments {
1207
1212
outputObjectType);
1208
1213
1209
1214
// Now, convert it to an optional.
1210
- translateSingle (outputOrigObjectType, outputObjectType,
1211
- outputOrigType, outputSubstType,
1212
- result, outputParam);
1213
- return ;
1215
+ return translateSingle (outputOrigObjectType, outputObjectType,
1216
+ outputOrigType, outputSubstType,
1217
+ result, outputParam);
1214
1218
}
1215
1219
1216
1220
if (outputSubstType->isAny ()) {
1217
1221
// We don't need outputParam on this path.
1218
1222
1219
- auto result =
1220
- translateAndImplodeIntoAny (inputOrigType,
1221
- inputSubstType,
1222
- outputOrigType,
1223
- outputSubstType);
1224
- Outputs.push_back (result);
1225
- return ;
1223
+ return translateAndImplodeIntoAny (inputOrigType,
1224
+ inputSubstType,
1225
+ outputOrigType,
1226
+ outputSubstType);
1226
1227
}
1227
1228
1228
1229
if (auto outputTupleType = dyn_cast<TupleType>(outputSubstType)) {
@@ -1238,14 +1239,13 @@ class TranslateArguments {
1238
1239
translateAndImplodeInto (inputOrigType, inputSubstType,
1239
1240
outputOrigType, outputTupleType, *temp);
1240
1241
1241
- Outputs. push_back ( temp->getManagedAddress () );
1242
+ return temp->getManagedAddress ();
1242
1243
} else {
1243
1244
auto result = translateAndImplodeIntoValue (
1244
1245
inputOrigType, inputSubstType, outputOrigType, outputTupleType,
1245
1246
outputTL.getLoweredType ());
1246
- Outputs. push_back ( result) ;
1247
+ return result;
1247
1248
}
1248
- return ;
1249
1249
}
1250
1250
1251
1251
llvm_unreachable (" Unhandled conversion from exploded tuple" );
@@ -1457,12 +1457,13 @@ class TranslateArguments {
1457
1457
inputEltAddr);
1458
1458
} else {
1459
1459
auto outputType = claimNextOutputType ();
1460
- translateSingle (inputEltOrigType,
1461
- inputEltSubstType,
1462
- outputEltOrigType,
1463
- outputEltSubstType,
1464
- inputEltAddr,
1465
- outputType);
1460
+ auto output = translateSingle (inputEltOrigType,
1461
+ inputEltSubstType,
1462
+ outputEltOrigType,
1463
+ outputEltSubstType,
1464
+ inputEltAddr,
1465
+ outputType);
1466
+ Outputs.push_back (output);
1466
1467
}
1467
1468
}
1468
1469
}
@@ -1520,25 +1521,25 @@ class TranslateArguments {
1520
1521
}
1521
1522
1522
1523
// Translate into a temporary.
1523
- void translateIndirect (AbstractionPattern inputOrigType,
1524
- CanType inputSubstType,
1525
- AbstractionPattern outputOrigType,
1526
- CanType outputSubstType, ManagedValue input,
1527
- SILType resultTy) {
1524
+ ManagedValue translateIndirect (AbstractionPattern inputOrigType,
1525
+ CanType inputSubstType,
1526
+ AbstractionPattern outputOrigType,
1527
+ CanType outputSubstType, ManagedValue input,
1528
+ SILType resultTy) {
1528
1529
auto &outputTL = SGF.getTypeLowering (resultTy);
1529
1530
auto temp = SGF.emitTemporary (Loc, outputTL);
1530
1531
translateSingleInto (inputOrigType, inputSubstType, outputOrigType,
1531
1532
outputSubstType, input, *temp);
1532
- Outputs. push_back ( temp->getManagedAddress () );
1533
+ return temp->getManagedAddress ();
1533
1534
}
1534
1535
1535
1536
// Translate into an owned argument.
1536
- void translateIntoOwned (AbstractionPattern inputOrigType,
1537
- CanType inputSubstType,
1538
- AbstractionPattern outputOrigType,
1539
- CanType outputSubstType,
1540
- ManagedValue input,
1541
- SILType outputLoweredTy) {
1537
+ ManagedValue translateIntoOwned (AbstractionPattern inputOrigType,
1538
+ CanType inputSubstType,
1539
+ AbstractionPattern outputOrigType,
1540
+ CanType outputSubstType,
1541
+ ManagedValue input,
1542
+ SILType outputLoweredTy) {
1542
1543
auto output = translatePrimitive (inputOrigType, inputSubstType,
1543
1544
outputOrigType, outputSubstType,
1544
1545
input, outputLoweredTy);
@@ -1547,16 +1548,16 @@ class TranslateArguments {
1547
1548
if (output.getOwnershipKind () != OwnershipKind::Owned)
1548
1549
output = output.copyUnmanaged (SGF, Loc);
1549
1550
1550
- Outputs. push_back ( output) ;
1551
+ return output;
1551
1552
}
1552
1553
1553
1554
// Translate into a guaranteed argument.
1554
- void translateIntoGuaranteed (AbstractionPattern inputOrigType,
1555
- CanType inputSubstType,
1556
- AbstractionPattern outputOrigType,
1557
- CanType outputSubstType,
1558
- ManagedValue input,
1559
- SILType outputLoweredTy) {
1555
+ ManagedValue translateIntoGuaranteed (AbstractionPattern inputOrigType,
1556
+ CanType inputSubstType,
1557
+ AbstractionPattern outputOrigType,
1558
+ CanType outputSubstType,
1559
+ ManagedValue input,
1560
+ SILType outputLoweredTy) {
1560
1561
auto output = translatePrimitive (inputOrigType, inputSubstType,
1561
1562
outputOrigType, outputSubstType,
1562
1563
input, outputLoweredTy);
@@ -1580,16 +1581,16 @@ class TranslateArguments {
1580
1581
output = SGF.emitManagedBeginBorrow (Loc, output.getValue ());
1581
1582
}
1582
1583
1583
- Outputs. push_back ( output) ;
1584
+ return output;
1584
1585
}
1585
1586
1586
1587
// / Translate a single value and add it as an output.
1587
- void translateSingle (AbstractionPattern inputOrigType,
1588
- CanType inputSubstType,
1589
- AbstractionPattern outputOrigType,
1590
- CanType outputSubstType,
1591
- ManagedValue input,
1592
- SILParameterInfo result) {
1588
+ ManagedValue translateSingle (AbstractionPattern inputOrigType,
1589
+ CanType inputSubstType,
1590
+ AbstractionPattern outputOrigType,
1591
+ CanType outputSubstType,
1592
+ ManagedValue input,
1593
+ SILParameterInfo result) {
1593
1594
auto resultTy = SGF.getSILType (result, OutputTypesFuncTy);
1594
1595
// Easy case: we want to pass exactly this value.
1595
1596
if (input.getType () == resultTy) {
@@ -1605,46 +1606,45 @@ class TranslateArguments {
1605
1606
break ;
1606
1607
}
1607
1608
1608
- Outputs.push_back (input);
1609
- return ;
1609
+ return input;
1610
1610
}
1611
1611
1612
1612
switch (result.getConvention ()) {
1613
1613
// Direct translation is relatively easy.
1614
1614
case ParameterConvention::Direct_Owned:
1615
1615
case ParameterConvention::Direct_Unowned:
1616
- translateIntoOwned (inputOrigType, inputSubstType, outputOrigType ,
1617
- outputSubstType, input, resultTy);
1618
- return ;
1616
+ return translateIntoOwned (inputOrigType, inputSubstType,
1617
+ outputOrigType, outputSubstType,
1618
+ input, resultTy) ;
1619
1619
case ParameterConvention::Direct_Guaranteed:
1620
- translateIntoGuaranteed (inputOrigType, inputSubstType, outputOrigType ,
1621
- outputSubstType, input, resultTy);
1622
- return ;
1620
+ return translateIntoGuaranteed (inputOrigType, inputSubstType,
1621
+ outputOrigType, outputSubstType,
1622
+ input, resultTy) ;
1623
1623
case ParameterConvention::Indirect_In: {
1624
1624
if (SGF.silConv .useLoweredAddresses ()) {
1625
- translateIndirect (inputOrigType, inputSubstType, outputOrigType ,
1626
- outputSubstType, input, resultTy);
1627
- return ;
1625
+ return translateIndirect (inputOrigType, inputSubstType,
1626
+ outputOrigType, outputSubstType,
1627
+ input, resultTy) ;
1628
1628
}
1629
- translateIntoOwned (inputOrigType, inputSubstType, outputOrigType ,
1630
- outputSubstType, input, resultTy);
1631
- return ;
1629
+ return translateIntoOwned (inputOrigType, inputSubstType,
1630
+ outputOrigType, outputSubstType,
1631
+ input, resultTy) ;
1632
1632
}
1633
1633
case ParameterConvention::Indirect_In_Guaranteed: {
1634
1634
if (SGF.silConv .useLoweredAddresses ()) {
1635
- translateIndirect (inputOrigType, inputSubstType, outputOrigType ,
1636
- outputSubstType, input, resultTy);
1637
- return ;
1635
+ return translateIndirect (inputOrigType, inputSubstType,
1636
+ outputOrigType, outputSubstType,
1637
+ input, resultTy) ;
1638
1638
}
1639
- translateIntoGuaranteed (inputOrigType, inputSubstType, outputOrigType ,
1640
- outputSubstType, input, resultTy);
1641
- return ;
1639
+ return translateIntoGuaranteed (inputOrigType, inputSubstType,
1640
+ outputOrigType, outputSubstType,
1641
+ input, resultTy) ;
1642
1642
}
1643
1643
case ParameterConvention::Pack_Guaranteed:
1644
1644
case ParameterConvention::Pack_Owned:
1645
1645
SGF.SGM .diagnose (Loc, diag::not_implemented,
1646
1646
" reabstraction of pack values" );
1647
- return ;
1647
+ return SGF. emitUndef (resultTy) ;
1648
1648
case ParameterConvention::Indirect_Inout:
1649
1649
case ParameterConvention::Pack_Inout:
1650
1650
llvm_unreachable (" inout reabstraction handled elsewhere" );
@@ -1656,17 +1656,16 @@ class TranslateArguments {
1656
1656
llvm_unreachable (" Covered switch isn't covered?!" );
1657
1657
}
1658
1658
1659
- void translateInOut (AbstractionPattern inputOrigType,
1660
- CanType inputSubstType,
1661
- AbstractionPattern outputOrigType,
1662
- CanType outputSubstType,
1663
- ManagedValue input,
1664
- SILParameterInfo result) {
1659
+ ManagedValue translateInOut (AbstractionPattern inputOrigType,
1660
+ CanType inputSubstType,
1661
+ AbstractionPattern outputOrigType,
1662
+ CanType outputSubstType,
1663
+ ManagedValue input,
1664
+ SILParameterInfo result) {
1665
1665
auto resultTy = SGF.getSILType (result, OutputTypesFuncTy);
1666
1666
assert (input.isLValue ());
1667
1667
if (input.getType () == resultTy) {
1668
- Outputs.push_back (input);
1669
- return ;
1668
+ return input;
1670
1669
}
1671
1670
1672
1671
// Create a temporary of the right type.
@@ -1705,7 +1704,7 @@ class TranslateArguments {
1705
1704
input.getLValueAddress ());
1706
1705
1707
1706
// Add the temporary as an l-value argument.
1708
- Outputs. push_back ( ManagedValue::forLValue (temporaryAddr) );
1707
+ return ManagedValue::forLValue (temporaryAddr);
1709
1708
}
1710
1709
1711
1710
// / Translate a single value and initialize the given temporary with it.
@@ -1745,6 +1744,11 @@ class TranslateArguments {
1745
1744
return claimNext (Inputs);
1746
1745
}
1747
1746
1747
+ // / Claim the next lowered parameter in the output. The conventions in
1748
+ // / this class are set up such that the place that claims an output type
1749
+ // / is also responsible for adding the output to Outputs. This allows
1750
+ // / readers to easily verify that this is done on all paths. (It'd
1751
+ // / sure be nice if we had better language mode for that, though.)
1748
1752
SILParameterInfo claimNextOutputType () {
1749
1753
return claimNext (OutputTypes);
1750
1754
}
0 commit comments