Skip to content

Commit a37146c

Browse files
committed
[NFC] Return a result from all the single-result translators
We'll be using these results with packs.
1 parent 23ccbfd commit a37146c

File tree

1 file changed

+98
-94
lines changed

1 file changed

+98
-94
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 98 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,9 +1106,11 @@ class TranslateArguments {
11061106
auto inputValue = claimNextInput();
11071107
auto outputLoweredTy = claimNextOutputType();
11081108

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);
11121114
} else {
11131115
translate(inputOrigType, inputSubstType.getParameterType(),
11141116
outputOrigType, outputSubstType.getParameterType());
@@ -1136,11 +1138,13 @@ class TranslateArguments {
11361138
}
11371139

11381140
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;
11441148
}
11451149

11461150
// Handle output being an exploded tuple when the input is opaque.
@@ -1166,17 +1170,19 @@ class TranslateArguments {
11661170
// single value.
11671171
auto inputElt = claimNextInput();
11681172
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);
11721177
}
11731178

11741179
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) {
11801186
// Tuple types are subtypes of their optionals
11811187
if (auto outputObjectType = outputSubstType.getOptionalObjectType()) {
11821188
auto outputOrigObjectType = outputOrigType.getOptionalObjectType();
@@ -1192,8 +1198,7 @@ class TranslateArguments {
11921198
outputOrigObjectType,
11931199
outputTupleType,
11941200
outputParam);
1195-
Outputs.push_back(result);
1196-
return;
1201+
return result;
11971202
}
11981203

11991204
// Tuple types are subtypes of optionals of Any, too.
@@ -1207,22 +1212,18 @@ class TranslateArguments {
12071212
outputObjectType);
12081213

12091214
// 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);
12141218
}
12151219

12161220
if (outputSubstType->isAny()) {
12171221
// We don't need outputParam on this path.
12181222

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);
12261227
}
12271228

12281229
if (auto outputTupleType = dyn_cast<TupleType>(outputSubstType)) {
@@ -1238,14 +1239,13 @@ class TranslateArguments {
12381239
translateAndImplodeInto(inputOrigType, inputSubstType,
12391240
outputOrigType, outputTupleType, *temp);
12401241

1241-
Outputs.push_back(temp->getManagedAddress());
1242+
return temp->getManagedAddress();
12421243
} else {
12431244
auto result = translateAndImplodeIntoValue(
12441245
inputOrigType, inputSubstType, outputOrigType, outputTupleType,
12451246
outputTL.getLoweredType());
1246-
Outputs.push_back(result);
1247+
return result;
12471248
}
1248-
return;
12491249
}
12501250

12511251
llvm_unreachable("Unhandled conversion from exploded tuple");
@@ -1457,12 +1457,13 @@ class TranslateArguments {
14571457
inputEltAddr);
14581458
} else {
14591459
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);
14661467
}
14671468
}
14681469
}
@@ -1520,25 +1521,25 @@ class TranslateArguments {
15201521
}
15211522

15221523
// 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) {
15281529
auto &outputTL = SGF.getTypeLowering(resultTy);
15291530
auto temp = SGF.emitTemporary(Loc, outputTL);
15301531
translateSingleInto(inputOrigType, inputSubstType, outputOrigType,
15311532
outputSubstType, input, *temp);
1532-
Outputs.push_back(temp->getManagedAddress());
1533+
return temp->getManagedAddress();
15331534
}
15341535

15351536
// 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) {
15421543
auto output = translatePrimitive(inputOrigType, inputSubstType,
15431544
outputOrigType, outputSubstType,
15441545
input, outputLoweredTy);
@@ -1547,16 +1548,16 @@ class TranslateArguments {
15471548
if (output.getOwnershipKind() != OwnershipKind::Owned)
15481549
output = output.copyUnmanaged(SGF, Loc);
15491550

1550-
Outputs.push_back(output);
1551+
return output;
15511552
}
15521553

15531554
// 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) {
15601561
auto output = translatePrimitive(inputOrigType, inputSubstType,
15611562
outputOrigType, outputSubstType,
15621563
input, outputLoweredTy);
@@ -1580,16 +1581,16 @@ class TranslateArguments {
15801581
output = SGF.emitManagedBeginBorrow(Loc, output.getValue());
15811582
}
15821583

1583-
Outputs.push_back(output);
1584+
return output;
15841585
}
15851586

15861587
/// 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) {
15931594
auto resultTy = SGF.getSILType(result, OutputTypesFuncTy);
15941595
// Easy case: we want to pass exactly this value.
15951596
if (input.getType() == resultTy) {
@@ -1605,46 +1606,45 @@ class TranslateArguments {
16051606
break;
16061607
}
16071608

1608-
Outputs.push_back(input);
1609-
return;
1609+
return input;
16101610
}
16111611

16121612
switch (result.getConvention()) {
16131613
// Direct translation is relatively easy.
16141614
case ParameterConvention::Direct_Owned:
16151615
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);
16191619
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);
16231623
case ParameterConvention::Indirect_In: {
16241624
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);
16281628
}
1629-
translateIntoOwned(inputOrigType, inputSubstType, outputOrigType,
1630-
outputSubstType, input, resultTy);
1631-
return;
1629+
return translateIntoOwned(inputOrigType, inputSubstType,
1630+
outputOrigType, outputSubstType,
1631+
input, resultTy);
16321632
}
16331633
case ParameterConvention::Indirect_In_Guaranteed: {
16341634
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);
16381638
}
1639-
translateIntoGuaranteed(inputOrigType, inputSubstType, outputOrigType,
1640-
outputSubstType, input, resultTy);
1641-
return;
1639+
return translateIntoGuaranteed(inputOrigType, inputSubstType,
1640+
outputOrigType, outputSubstType,
1641+
input, resultTy);
16421642
}
16431643
case ParameterConvention::Pack_Guaranteed:
16441644
case ParameterConvention::Pack_Owned:
16451645
SGF.SGM.diagnose(Loc, diag::not_implemented,
16461646
"reabstraction of pack values");
1647-
return;
1647+
return SGF.emitUndef(resultTy);
16481648
case ParameterConvention::Indirect_Inout:
16491649
case ParameterConvention::Pack_Inout:
16501650
llvm_unreachable("inout reabstraction handled elsewhere");
@@ -1656,17 +1656,16 @@ class TranslateArguments {
16561656
llvm_unreachable("Covered switch isn't covered?!");
16571657
}
16581658

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) {
16651665
auto resultTy = SGF.getSILType(result, OutputTypesFuncTy);
16661666
assert(input.isLValue());
16671667
if (input.getType() == resultTy) {
1668-
Outputs.push_back(input);
1669-
return;
1668+
return input;
16701669
}
16711670

16721671
// Create a temporary of the right type.
@@ -1705,7 +1704,7 @@ class TranslateArguments {
17051704
input.getLValueAddress());
17061705

17071706
// Add the temporary as an l-value argument.
1708-
Outputs.push_back(ManagedValue::forLValue(temporaryAddr));
1707+
return ManagedValue::forLValue(temporaryAddr);
17091708
}
17101709

17111710
/// Translate a single value and initialize the given temporary with it.
@@ -1745,6 +1744,11 @@ class TranslateArguments {
17451744
return claimNext(Inputs);
17461745
}
17471746

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.)
17481752
SILParameterInfo claimNextOutputType() {
17491753
return claimNext(OutputTypes);
17501754
}

0 commit comments

Comments
 (0)