Skip to content

Commit 921c6a0

Browse files
committed
[OpaqueValues] Map back-deploy thunk results.
When a throwing function which returns a generic (this is the simplest example) is back deployed, it gets a back deploy thunk. This back deploy thunk calls one of two variations of the function, depending on availability, both which have the same signature and in particular both return a generic. The result type of that function signature is an unbound generic. Previously, that result type was used as is. Consequently the success blocks for the try_apply instructions in these thunks had arguments of unbound generic type. Here, that type is mapped into the context of the function being emitted. The thunks now have the appropriate bound generic type.
1 parent 0d52c41 commit 921c6a0

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/SILGen/SILGenBackDeploy.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,16 @@ static void emitBackDeployForwardApplyAndReturnOrThrow(
133133

134134
// Emit error block.
135135
SGF.B.emitBlock(errorBB);
136-
SILValue error = errorBB->createPhiArgument(fnConv.getSILErrorType(TEC),
137-
OwnershipKind::Owned);
136+
SILValue error = errorBB->createPhiArgument(
137+
SGF.F.mapTypeIntoContext(fnConv.getSILErrorType(TEC)),
138+
OwnershipKind::Owned);
138139
SGF.B.createBranch(loc, SGF.ThrowDest.getBlock(), {error});
139140

140141
// Emit normal block.
141142
SGF.B.emitBlock(normalBB);
142-
SILValue result = normalBB->createPhiArgument(fnConv.getSILResultType(TEC),
143-
OwnershipKind::Owned);
143+
SILValue result = normalBB->createPhiArgument(
144+
SGF.F.mapTypeIntoContext(fnConv.getSILResultType(TEC)),
145+
OwnershipKind::Owned);
144146
SmallVector<SILValue, 4> directResults;
145147
extractAllElements(result, loc, SGF.B, directResults);
146148

test/SILGen/opaque_values_silgen.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,3 +636,12 @@ func takeKeyPathString<T>(_ kp: KeyPath<T, String>) {
636636
func giveKeyPathString() {
637637
takeKeyPathString(\StructWithAReadableStringProperty.s)
638638
}
639+
640+
// CHECK-LABEL: sil {{.*}}@$s20opaque_values_silgen29backDeployingReturningGenericyxxKlFTwb : {{.*}} <T> {{.*}} {
641+
// Ensure that there aren't any "normal" (in the sense of try_apply) blocks that
642+
// take unbound generic parameters (τ_0_0).
643+
// CHECK-NOT: {{bb[0-9]+}}({{%[^,]+}} : @owned $τ_0_0):
644+
// CHECK-LABEL: } // end sil function '$s20opaque_values_silgen29backDeployingReturningGenericyxxKlFTwb'
645+
@available(SwiftStdlib 5.1, *)
646+
@_backDeploy(before: SwiftStdlib 5.8)
647+
public func backDeployingReturningGeneric<T>(_ t: T) throws -> T { t }

0 commit comments

Comments
 (0)