Skip to content

SILGen: Canonicalize indirect return type in context [3.1] #7082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/SILGen/SILGenProlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
parameters(parameters) {}

ManagedValue getManagedValue(SILValue arg, CanType t,
SILParameterInfo parameterInfo) const {
SILParameterInfo parameterInfo) const {
switch (parameterInfo.getConvention()) {
case ParameterConvention::Direct_Guaranteed:
case ParameterConvention::Indirect_In_Guaranteed:
Expand Down Expand Up @@ -481,6 +481,11 @@ unsigned SILGenFunction::emitProlog(ArrayRef<ParameterList *> paramLists,
Type resultType, DeclContext *DC,
bool throws) {
// Create the indirect result parameters.
if (auto *genericSig = DC->getGenericSignatureOfContext()) {
resultType = genericSig->getCanonicalTypeInContext(
resultType, *SGM.M.getSwiftModule());
}

emitIndirectResultParameters(*this, resultType, DC);

// Emit the argument variables in calling convention order.
Expand Down
28 changes: 23 additions & 5 deletions test/SILGen/same_type_abstraction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,28 @@ struct S2 {}

// CHECK-LABEL: sil hidden @_TF21same_type_abstraction28callClosureWithConcreteTypes
// CHECK: function_ref @_TTR
func callClosureWithConcreteTypes<
T: Associated, U: Associated
where
T.Assoc == S1, U.Assoc == S2
>(x x: Abstracted<T, U>, arg: S1) -> S2 {
func callClosureWithConcreteTypes<T: Associated, U: Associated>(x: Abstracted<T, U>, arg: S1) -> S2 where T.Assoc == S1, U.Assoc == S2 {
return x.closure(arg)
}

// Problem when a same-type constraint makes an associated type into a tuple

protocol MyProtocol {
associatedtype ReadData
associatedtype Data

func readData() -> ReadData
}

extension MyProtocol where Data == (ReadData, ReadData) {
// 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)
func currentData() -> Data {
// CHECK: bb0(%0 : $*Self.ReadData, %1 : $*Self.ReadData, %2 : $*Self):
// 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
// CHECK: apply [[READ_FN]]<Self>(%0, %2) : $@convention(witness_method) <τ_0_0 where τ_0_0 : MyProtocol> (@in_guaranteed τ_0_0) -> @out τ_0_0.ReadData
// 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
// CHECK: apply [[READ_FN]]<Self>(%1, %2) : $@convention(witness_method) <τ_0_0 where τ_0_0 : MyProtocol> (@in_guaranteed τ_0_0) -> @out τ_0_0.ReadData
// CHECK: return
return (readData(), readData())
}
}