Skip to content

Commit 06a9e13

Browse files
authored
Merge pull request #70633 from DougGregor/sil-witness-lowering-thrown-error
2 parents dba3498 + ad75dae commit 06a9e13

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

lib/SIL/IR/AbstractionPattern.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,12 +1280,10 @@ AbstractionPattern::getFunctionThrownErrorType(
12801280
}
12811281

12821282
if (!substErrorType) {
1283-
Type origErrorSubstType;
1284-
if (auto errorSubs = optOrigErrorType->getGenericSubstitutions()) {
1285-
substErrorType = optOrigErrorType->getType().subst(errorSubs);
1286-
} else {
1283+
if (optOrigErrorType->getType()->hasTypeParameter())
1284+
substErrorType = ctx.getNeverType();
1285+
else
12871286
substErrorType = optOrigErrorType->getType();
1288-
}
12891287
}
12901288

12911289
return std::make_pair(*optOrigErrorType,

test/SILGen/typed_throws_generic.swift

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,50 @@ struct UntypedRes<Success>: P {
313313
}
314314

315315
struct InfallibleRes<Success>: P {
316-
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s20typed_throws_generic13InfallibleResVyxGAA1PA2aEP1fyy1EQzYKFTW : $@convention(witness_method: P) <τ_0_0> (@in_guaranteed InfallibleRes<τ_0_0>) -> @error_indirect τ_0_0.E
317-
// CHECK: bb0(%0 : $*@error_type τ_0_0.E, %1 : $*InfallibleRes<τ_0_0>):
316+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s20typed_throws_generic13InfallibleResVyxGAA1PA2aEP1fyy1EQzYKFTW : $@convention(witness_method: P) <τ_0_0> (@in_guaranteed InfallibleRes<τ_0_0>) -> @error_indirect Never
317+
// CHECK: bb0(%0 : $*Never, %1 : $*InfallibleRes<τ_0_0>):
318318
// CHECK: [[SELF:%.*]] = load [trivial] %1 : $*InfallibleRes<τ_0_0>
319319
// CHECK: [[WITNESS:%.*]] = function_ref @$s20typed_throws_generic13InfallibleResV1fyyF : $@convention(method) <τ_0_0> (InfallibleRes<τ_0_0>) -> ()
320320
// CHECK: = apply [[WITNESS]]<τ_0_0>([[SELF]]) : $@convention(method) <τ_0_0> (InfallibleRes<τ_0_0>)
321321
func f() { }
322322
}
323+
324+
// Protocol with a default implementation of its function with a
325+
// thrown error type.
326+
protocol P2 {
327+
associatedtype Failure: Error
328+
func f() throws(Failure)
329+
}
330+
331+
extension P2 {
332+
func f() throws(Failure) { }
333+
}
334+
335+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s20typed_throws_generic1SVAA2P2A2aDP1fyy7FailureQzYKFTW : $@convention(witness_method: P2) (@in_guaranteed S) -> @error_indirect Never
336+
// CHECK: bb0(%0 : $*Never, %1 : $*S)
337+
struct S: P2 {
338+
typealias Failure = Never
339+
}
340+
341+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s20typed_throws_generic2GSVyxGAA2P2A2aEP1fyy7FailureQzYKFTW : $@convention(witness_method: P2) <τ_0_0> (@in_guaranteed GS<τ_0_0>) -> @error_indirect Never {
342+
// CHECK: bb0(%0 : $*Never, %1 : $*GS<τ_0_0>):
343+
struct GS<T>: P2 {
344+
typealias Failure = Never
345+
}
346+
347+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s20typed_throws_generic3GSFVyxq_GAA2P2A2aEP1fyy7FailureQzYKFTW : $@convention(witness_method: P2) <τ_0_0, τ_0_1 where τ_0_1 : Error> (@in_guaranteed GSF<τ_0_0, τ_0_1>) -> @error_indirect τ_0_1 {
348+
// CHECK: bb0(%0 : $*τ_0_1, %1 : $*GSF<τ_0_0, τ_0_1>):
349+
struct GSF<T, Failure: Error>: P2 {
350+
}
351+
352+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s20typed_throws_generic4GSF2Vyxq_GAA2P2A2aEP1fyy7FailureQzYKFTW : $@convention(witness_method: P2) <τ_0_0, τ_0_1 where τ_0_0 : Error> (@in_guaranteed GSF2<τ_0_0, τ_0_1>) -> @error_indirect τ_0_0 {
353+
// CHECK: bb0(%0 : $*τ_0_0, %1 : $*GSF2<τ_0_0, τ_0_1>):
354+
struct GSF2<F: Error, T>: P2 {
355+
typealias Failure = F
356+
}
357+
358+
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s20typed_throws_generic3GSAVyxGAA2P2A2aEP1fyy7FailureQzYKFTW : $@convention(witness_method: P2) <τ_0_0> (@in_guaranteed GSA<τ_0_0>) -> @error_indirect any Error {
359+
// CHECK: bb0(%0 : $*any Error, %1 : $*GSA<τ_0_0>):
360+
struct GSA<T>: P2 {
361+
typealias Failure = any Error
362+
}

0 commit comments

Comments
 (0)