Skip to content

Commit f9129bf

Browse files
authored
Merge pull request swiftlang#30372 from rjmccall/result-siltype-silgen-transform
2 parents afa2440 + 585c28d commit f9129bf

12 files changed

+208
-60
lines changed

lib/SILGen/ArgumentSource.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ ManagedValue ArgumentSource::getAsSingleValue(SILGenFunction &SGF,
7878

7979
ManagedValue ArgumentSource::getAsSingleValue(SILGenFunction &SGF,
8080
AbstractionPattern origFormalType,
81+
SILType loweredTy,
8182
SGFContext C) && {
8283
auto substFormalType = getSubstRValueType();
83-
auto conversion = Conversion::getSubstToOrig(origFormalType, substFormalType);
84+
auto conversion =
85+
Conversion::getSubstToOrig(origFormalType, substFormalType, loweredTy);
8486
return std::move(*this).getConverted(SGF, conversion, C);
8587
}
8688

@@ -209,6 +211,7 @@ void ArgumentSource::forwardInto(SILGenFunction &SGF,
209211
SILLocation loc = getLocation();
210212
ManagedValue outputValue =
211213
std::move(*this).getAsSingleValue(SGF, origFormalType,
214+
destTL.getLoweredType(),
212215
SGFContext(dest));
213216

214217
if (outputValue.isInContext()) return;

lib/SILGen/ArgumentSource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ class ArgumentSource {
242242
SGFContext C = SGFContext()) &&;
243243
ManagedValue getAsSingleValue(SILGenFunction &SGF,
244244
AbstractionPattern origFormalType,
245+
SILType loweredResultTy,
245246
SGFContext C = SGFContext()) &&;
246247

247248
ManagedValue getConverted(SILGenFunction &SGF, const Conversion &conversion,

lib/SILGen/Conversion.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Conversion {
7373
struct ReabstractionTypes {
7474
AbstractionPattern OrigType;
7575
CanType SubstType;
76+
SILType LoweredResultType;
7677
};
7778

7879
using Members = ExternalUnionMembers<BridgingTypes, ReabstractionTypes>;
@@ -104,20 +105,24 @@ class Conversion {
104105
loweredResultTy, isExplicit);
105106
}
106107

107-
Conversion(KindTy kind, AbstractionPattern origType, CanType substType)
108+
Conversion(KindTy kind, AbstractionPattern origType, CanType substType,
109+
SILType loweredResultTy)
108110
: Kind(kind) {
109-
Types.emplaceAggregate<ReabstractionTypes>(kind, origType, substType);
111+
Types.emplaceAggregate<ReabstractionTypes>(kind, origType, substType,
112+
loweredResultTy);
110113
}
111114

112115
public:
113116
static Conversion getOrigToSubst(AbstractionPattern origType,
114-
CanType substType) {
115-
return Conversion(OrigToSubst, origType, substType);
117+
CanType substType,
118+
SILType loweredResultTy) {
119+
return Conversion(OrigToSubst, origType, substType, loweredResultTy);
116120
}
117121

118122
static Conversion getSubstToOrig(AbstractionPattern origType,
119-
CanType substType) {
120-
return Conversion(SubstToOrig, origType, substType);
123+
CanType substType,
124+
SILType loweredResultTy) {
125+
return Conversion(SubstToOrig, origType, substType, loweredResultTy);
121126
}
122127

123128
static Conversion getBridging(KindTy kind, CanType origType,
@@ -143,6 +148,10 @@ class Conversion {
143148
return Types.get<ReabstractionTypes>(Kind).SubstType;
144149
}
145150

151+
SILType getReabstractionLoweredResultType() const {
152+
return Types.get<ReabstractionTypes>(Kind).LoweredResultType;
153+
}
154+
146155
bool isBridgingExplicit() const {
147156
return Types.get<BridgingTypes>(Kind).IsExplicit;
148157
}

lib/SILGen/ResultPlan.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ class ScalarResultPlan final : public ResultPlan {
249249
origType.getType(), substType,
250250
loweredResultTy);
251251
} else {
252-
return Conversion::getOrigToSubst(origType, substType);
252+
return Conversion::getOrigToSubst(origType, substType,
253+
loweredResultTy);
253254
}
254255
}();
255256

lib/SILGen/SILGenApply.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2950,7 +2950,8 @@ class ArgEmitter {
29502950
switch (getSILFunctionLanguage(Rep)) {
29512951
case SILFunctionLanguage::Swift:
29522952
return Conversion::getSubstToOrig(origParamType,
2953-
arg.getSubstRValueType());
2953+
arg.getSubstRValueType(),
2954+
param.getSILStorageInterfaceType());
29542955
case SILFunctionLanguage::C:
29552956
return Conversion::getBridging(Conversion::BridgeToObjC,
29562957
arg.getSubstRValueType(),
@@ -4789,7 +4790,8 @@ ManagedValue SILGenFunction::emitInjectEnum(SILLocation loc,
47894790
if (!payloadMV) {
47904791
// If the payload was indirect, we already evaluated it and
47914792
// have a single value. Otherwise, evaluate the payload.
4792-
payloadMV = std::move(payload).getAsSingleValue(*this, origFormalType);
4793+
payloadMV = std::move(payload).getAsSingleValue(*this, origFormalType,
4794+
loweredPayloadType);
47934795
}
47944796

47954797
SILValue argValue = payloadMV.forward(*this);
@@ -4812,7 +4814,9 @@ ManagedValue SILGenFunction::emitInjectEnum(SILLocation loc,
48124814
} else if (payloadTL.isLoadable()) {
48134815
// The payload of this specific enum case might be loadable
48144816
// even if the overall enum is address-only.
4815-
payloadMV = std::move(payload).getAsSingleValue(*this, origFormalType);
4817+
payloadMV =
4818+
std::move(payload).getAsSingleValue(*this, origFormalType,
4819+
loweredPayloadType);
48164820
B.emitStoreValueOperation(loc, payloadMV.forward(*this), resultData,
48174821
StoreOwnershipQualifier::Init);
48184822
} else {

lib/SILGen/SILGenBridging.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ static ManagedValue emitUnabstractedCast(SILGenFunction &SGF, SILLocation loc,
3737
ManagedValue value,
3838
CanType sourceFormalType,
3939
CanType targetFormalType) {
40-
if (value.getType() == SGF.getLoweredType(targetFormalType))
40+
SILType loweredResultTy = SGF.getLoweredType(targetFormalType);
41+
if (value.getType() == loweredResultTy)
4142
return value;
4243

4344
return SGF.emitTransformedValue(loc, value,
4445
AbstractionPattern(sourceFormalType),
4546
sourceFormalType,
4647
AbstractionPattern(targetFormalType),
47-
targetFormalType);
48+
targetFormalType,
49+
loweredResultTy);
4850
}
4951

5052
static bool shouldBridgeThroughError(SILGenModule &SGM, CanType type,

lib/SILGen/SILGenConvert.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,12 +1164,14 @@ ManagedValue Conversion::emit(SILGenFunction &SGF, SILLocation loc,
11641164
case SubstToOrig:
11651165
return SGF.emitSubstToOrigValue(loc, value,
11661166
getReabstractionOrigType(),
1167-
getReabstractionSubstType(), C);
1167+
getReabstractionSubstType(),
1168+
getReabstractionLoweredResultType(), C);
11681169

11691170
case OrigToSubst:
11701171
return SGF.emitOrigToSubstValue(loc, value,
11711172
getReabstractionOrigType(),
1172-
getReabstractionSubstType(), C);
1173+
getReabstractionSubstType(),
1174+
getReabstractionLoweredResultType(), C);
11731175
}
11741176
llvm_unreachable("bad kind");
11751177
}
@@ -1231,6 +1233,8 @@ static void printReabstraction(const Conversion &conversion,
12311233
conversion.getReabstractionOrigType().print(out);
12321234
out << ", subst: ";
12331235
conversion.getReabstractionSubstType().print(out);
1236+
out << ", loweredResult: ";
1237+
conversion.getReabstractionLoweredResultType().print(out);
12341238
out << ')';
12351239
}
12361240

lib/SILGen/SILGenFunction.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,10 +1778,20 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
17781778
AbstractionPattern origType,
17791779
CanType substType,
17801780
SGFContext ctx = SGFContext());
1781+
ManagedValue emitOrigToSubstValue(SILLocation loc, ManagedValue input,
1782+
AbstractionPattern origType,
1783+
CanType substType,
1784+
SILType loweredResultTy,
1785+
SGFContext ctx = SGFContext());
17811786
RValue emitOrigToSubstValue(SILLocation loc, RValue &&input,
17821787
AbstractionPattern origType,
17831788
CanType substType,
17841789
SGFContext ctx = SGFContext());
1790+
RValue emitOrigToSubstValue(SILLocation loc, RValue &&input,
1791+
AbstractionPattern origType,
1792+
CanType substType,
1793+
SILType loweredResultTy,
1794+
SGFContext ctx = SGFContext());
17851795

17861796
/// Convert a value with the abstraction patterns of the substituted
17871797
/// type to a value with the abstraction patterns of the original type.
@@ -1793,6 +1803,16 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
17931803
AbstractionPattern origType,
17941804
CanType substType,
17951805
SGFContext ctx = SGFContext());
1806+
ManagedValue emitSubstToOrigValue(SILLocation loc, ManagedValue input,
1807+
AbstractionPattern origType,
1808+
CanType substType,
1809+
SILType loweredResultTy,
1810+
SGFContext ctx = SGFContext());
1811+
RValue emitSubstToOrigValue(SILLocation loc, RValue &&input,
1812+
AbstractionPattern origType,
1813+
CanType substType,
1814+
SILType loweredResultTy,
1815+
SGFContext ctx = SGFContext());
17961816

17971817
/// Transform the AST-level types in the function signature without an
17981818
/// abstraction or representation change.
@@ -1807,12 +1827,14 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
18071827
CanType inputSubstType,
18081828
AbstractionPattern outputOrigType,
18091829
CanType outputSubstType,
1830+
SILType loweredResultTy,
18101831
SGFContext ctx = SGFContext());
18111832
RValue emitTransformedValue(SILLocation loc, RValue &&input,
18121833
AbstractionPattern inputOrigType,
18131834
CanType inputSubstType,
18141835
AbstractionPattern outputOrigType,
18151836
CanType outputSubstType,
1837+
SILType loweredResultTy,
18161838
SGFContext ctx = SGFContext());
18171839

18181840
/// Used for emitting SILArguments of bare functions, such as thunks.

lib/SILGen/SILGenLValue.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,8 +1969,11 @@ namespace {
19691969
keyPathTy->getGenericArgs(),
19701970
ArrayRef<ProtocolConformanceRef>());
19711971

1972+
auto origType = AbstractionPattern::getOpaque();
1973+
auto loweredTy = SGF.getLoweredType(origType, value.getSubstRValueType());
1974+
19721975
auto setValue =
1973-
std::move(value).getAsSingleValue(SGF, AbstractionPattern::getOpaque());
1976+
std::move(value).getAsSingleValue(SGF, origType, loweredTy);
19741977
if (!setValue.getType().isAddress()) {
19751978
setValue = setValue.materialize(SGF, loc);
19761979
}
@@ -3523,7 +3526,8 @@ ManagedValue SILGenFunction::emitLoad(SILLocation loc, SILValue addr,
35233526
? Conversion::getBridging(Conversion::BridgeFromObjC,
35243527
origFormalType.getType(),
35253528
substFormalType, rvalueTL.getLoweredType())
3526-
: Conversion::getOrigToSubst(origFormalType, substFormalType);
3529+
: Conversion::getOrigToSubst(origFormalType, substFormalType,
3530+
rvalueTL.getLoweredType());
35273531

35283532
return emitConvertedRValue(loc, conversion, C,
35293533
[&](SILGenFunction &SGF, SILLocation loc, SGFContext C) {

0 commit comments

Comments
 (0)