Skip to content

Commit 7e8a171

Browse files
authored
Merge pull request #7082 from slavapestov/silgen-indirect-return-canonicalization-3.1
SILGen: Canonicalize indirect return type in context [3.1]
2 parents 5f15bf4 + 7d6247f commit 7e8a171

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/SILGen/SILGenProlog.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
8686
parameters(parameters) {}
8787

8888
ManagedValue getManagedValue(SILValue arg, CanType t,
89-
SILParameterInfo parameterInfo) const {
89+
SILParameterInfo parameterInfo) const {
9090
switch (parameterInfo.getConvention()) {
9191
case ParameterConvention::Direct_Guaranteed:
9292
case ParameterConvention::Indirect_In_Guaranteed:
@@ -481,6 +481,11 @@ unsigned SILGenFunction::emitProlog(ArrayRef<ParameterList *> paramLists,
481481
Type resultType, DeclContext *DC,
482482
bool throws) {
483483
// Create the indirect result parameters.
484+
if (auto *genericSig = DC->getGenericSignatureOfContext()) {
485+
resultType = genericSig->getCanonicalTypeInContext(
486+
resultType, *SGM.M.getSwiftModule());
487+
}
488+
484489
emitIndirectResultParameters(*this, resultType, DC);
485490

486491
// Emit the argument variables in calling convention order.

test/SILGen/same_type_abstraction.swift

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,28 @@ struct S2 {}
1313

1414
// CHECK-LABEL: sil hidden @_TF21same_type_abstraction28callClosureWithConcreteTypes
1515
// CHECK: function_ref @_TTR
16-
func callClosureWithConcreteTypes<
17-
T: Associated, U: Associated
18-
where
19-
T.Assoc == S1, U.Assoc == S2
20-
>(x x: Abstracted<T, U>, arg: S1) -> S2 {
16+
func callClosureWithConcreteTypes<T: Associated, U: Associated>(x: Abstracted<T, U>, arg: S1) -> S2 where T.Assoc == S1, U.Assoc == S2 {
2117
return x.closure(arg)
2218
}
19+
20+
// Problem when a same-type constraint makes an associated type into a tuple
21+
22+
protocol MyProtocol {
23+
associatedtype ReadData
24+
associatedtype Data
25+
26+
func readData() -> ReadData
27+
}
28+
29+
extension MyProtocol where Data == (ReadData, ReadData) {
30+
// CHECK-LABEL: sil hidden @_TFe21same_type_abstractionRxS_10MyProtocolwx4DatazTwx8ReadDatawxS2__rS0_11currentDatafT_wxS1_ : $@convention(method) <Self where Self : MyProtocol, Self.Data == (Self.ReadData, Self.ReadData)> (@in_guaranteed Self) -> (@out Self.ReadData, @out Self.ReadData)
31+
func currentData() -> Data {
32+
// CHECK: bb0(%0 : $*Self.ReadData, %1 : $*Self.ReadData, %2 : $*Self):
33+
// CHECK: [[READ_FN:%.*]] = witness_method $Self, #MyProtocol.readData!1 : $@convention(witness_method) <τ_0_0 where τ_0_0 : MyProtocol> (@in_guaranteed τ_0_0) -> @out τ_0_0.ReadData
34+
// CHECK: apply [[READ_FN]]<Self>(%0, %2) : $@convention(witness_method) <τ_0_0 where τ_0_0 : MyProtocol> (@in_guaranteed τ_0_0) -> @out τ_0_0.ReadData
35+
// CHECK: [[READ_FN:%.*]] = witness_method $Self, #MyProtocol.readData!1 : $@convention(witness_method) <τ_0_0 where τ_0_0 : MyProtocol> (@in_guaranteed τ_0_0) -> @out τ_0_0.ReadData
36+
// CHECK: apply [[READ_FN]]<Self>(%1, %2) : $@convention(witness_method) <τ_0_0 where τ_0_0 : MyProtocol> (@in_guaranteed τ_0_0) -> @out τ_0_0.ReadData
37+
// CHECK: return
38+
return (readData(), readData())
39+
}
40+
}

0 commit comments

Comments
 (0)