Skip to content

Commit dd71e3d

Browse files
authored
Merge pull request #74456 from hborla/reduced-error-type
[SILGen] Compute the reduced thrown error type when emitting a function prolog and epilog.
2 parents fe8289c + 5041986 commit dd71e3d

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/SILGen/SILGenEpilog.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void SILGenFunction::prepareEpilog(
6565

6666
if (errorType) {
6767
auto genericSig = DC->getGenericSignatureOfContext();
68+
errorType = (*errorType)->getReducedType(genericSig);
6869
AbstractionPattern origErrorType = TypeContext
6970
? *TypeContext->OrigType.getFunctionThrownErrorType()
7071
: AbstractionPattern(genericSig.getCanonicalSignature(),

lib/SILGen/SILGenProlog.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,8 @@ uint16_t SILGenFunction::emitBasicProlog(
15391539
// Create the indirect result parameters.
15401540
auto genericSig = DC->getGenericSignatureOfContext();
15411541
resultType = resultType->getReducedType(genericSig);
1542+
if (errorType)
1543+
errorType = (*errorType)->getReducedType(genericSig);
15421544

15431545
std::optional<AbstractionPattern> origClosureType;
15441546
if (TypeContext) origClosureType = TypeContext->OrigType;

test/SILGen/typed_throws_generic.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,3 +378,12 @@ struct GSF2<F: Error, T>: P2 {
378378
struct GSA<T>: P2 {
379379
typealias Failure = any Error
380380
}
381+
382+
struct ReducedError<T: Error> {}
383+
384+
extension ReducedError where T == MyError {
385+
// CHECK-LABEL: sil hidden [ossa] @$s20typed_throws_generic12ReducedErrorVA2A02MyE0ORszrlE05throwfE0yyAEYKF : $@convention(method) (ReducedError<MyError>) -> @error MyError {
386+
func throwMyError() throws(T) {
387+
throw MyError.fail
388+
}
389+
}

0 commit comments

Comments
 (0)