Skip to content

Commit 69cd7b3

Browse files
committed
SILGen: Simplify reabstraction thunk emission
Now that we handle the top-level parameter list specially, we never end up with non-materializable tuples here, or other odd cases like one-element tuples, so a bunch of complexity can be eliminated.
1 parent 62a94f6 commit 69cd7b3

File tree

1 file changed

+3
-61
lines changed

1 file changed

+3
-61
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,6 @@ ManagedValue Transform::transform(ManagedValue v,
357357
AbstractionPattern outputOrigType,
358358
CanType outputSubstType,
359359
SGFContext ctxt) {
360-
// Look through inout types.
361-
inputSubstType = inputSubstType->getInOutObjectType()->getCanonicalType();
362-
363360
// Load if the result isn't address-only. All the translation routines
364361
// expect this.
365362
if (v.getType().isAddress()) {
@@ -816,16 +813,6 @@ static void emitForceInto(SILGenFunction &SGF, SILLocation loc,
816813
temp.finishInitialization(SGF);
817814
}
818815

819-
/// If the type is a single-element tuple, return the element type.
820-
static CanType getSingleTupleElement(CanType type) {
821-
if (auto tupleType = dyn_cast<TupleType>(type)) {
822-
if (tupleType->getNumElements() == 1)
823-
return tupleType.getElementType(0);
824-
}
825-
826-
return type;
827-
}
828-
829816
namespace {
830817
class TranslateIndirect : public Cleanup {
831818
AbstractionPattern InputOrigType, OutputOrigType;
@@ -1042,42 +1029,6 @@ namespace {
10421029
auto inputTupleType = dyn_cast<TupleType>(inputSubstType);
10431030
auto outputTupleType = dyn_cast<TupleType>(outputSubstType);
10441031

1045-
// Look inside one-element exploded tuples, but not if both input
1046-
// and output types are *both* one-element tuples.
1047-
if (!(inputTupleType && outputTupleType &&
1048-
inputTupleType.getElementTypes().size() == 1 &&
1049-
outputTupleType.getElementTypes().size() == 1)) {
1050-
if (inputOrigType.isTuple() &&
1051-
inputOrigType.getNumTupleElements() == 1) {
1052-
inputOrigType = inputOrigType.getTupleElementType(0);
1053-
inputSubstType = getSingleTupleElement(inputSubstType);
1054-
return translate(inputOrigType, inputSubstType,
1055-
outputOrigType, outputSubstType);
1056-
}
1057-
1058-
if (outputOrigType.isTuple() &&
1059-
outputOrigType.getNumTupleElements() == 1) {
1060-
outputOrigType = outputOrigType.getTupleElementType(0);
1061-
outputSubstType = getSingleTupleElement(outputSubstType);
1062-
return translate(inputOrigType, inputSubstType,
1063-
outputOrigType, outputSubstType);
1064-
}
1065-
}
1066-
1067-
// Special-case: tuples containing inouts, __shared or __owned,
1068-
// and one-element vararg tuples.
1069-
if (inputTupleType && shouldExpandTupleType(inputTupleType)) {
1070-
// Non-materializable tuple types cannot be bound as generic
1071-
// arguments, so none of the remaining transformations apply.
1072-
// Instead, the outermost tuple layer is exploded, even when
1073-
// they are being passed opaquely. See the comment in
1074-
// AbstractionPattern.h for a discussion.
1075-
return translateParallelExploded(inputOrigType,
1076-
inputTupleType,
1077-
outputOrigType,
1078-
outputTupleType);
1079-
}
1080-
10811032
// Case where the input type is an exploded tuple.
10821033
if (inputOrigType.isTuple()) {
10831034
if (outputOrigType.isTuple()) {
@@ -1338,11 +1289,7 @@ namespace {
13381289
CanTupleType outputSubstType) {
13391290
assert(inputOrigType.matchesTuple(inputSubstType));
13401291
assert(outputOrigType.matchesTuple(outputSubstType));
1341-
// Non-materializable input and materializable output occurs
1342-
// when witness method thunks re-abstract a non-mutating
1343-
// witness for a mutating requirement. The inout self is just
1344-
// loaded to produce a value in this case.
1345-
assert(inputSubstType->hasElementWithOwnership() ||
1292+
assert(!inputSubstType->hasElementWithOwnership() &&
13461293
!outputSubstType->hasElementWithOwnership());
13471294
assert(inputSubstType->getNumElements() ==
13481295
outputSubstType->getNumElements());
@@ -1547,13 +1494,6 @@ namespace {
15471494
translateIntoGuaranteed(inputOrigType, inputSubstType, outputOrigType,
15481495
outputSubstType, input);
15491496
return;
1550-
case ParameterConvention::Indirect_Inout:
1551-
translateInOut(inputOrigType.getWithoutSpecifierType(),
1552-
inputSubstType.getWithoutSpecifierType(),
1553-
outputOrigType.getWithoutSpecifierType(),
1554-
outputSubstType.getWithoutSpecifierType(),
1555-
input, result);
1556-
return;
15571497
case ParameterConvention::Indirect_In: {
15581498
if (SGF.silConv.useLoweredAddresses()) {
15591499
translateIndirect(inputOrigType, inputSubstType, outputOrigType,
@@ -1576,6 +1516,8 @@ namespace {
15761516
assert(Outputs.back().getType() == SGF.getSILType(result));
15771517
return;
15781518
}
1519+
case ParameterConvention::Indirect_Inout:
1520+
llvm_unreachable("inout reabstraction handled elsewhere");
15791521
case ParameterConvention::Indirect_InoutAliasable:
15801522
llvm_unreachable("abstraction difference in aliasable argument not "
15811523
"allowed");

0 commit comments

Comments
 (0)