Skip to content

Commit 251bbbb

Browse files
committed
Fix the definition of SILFunctionConventions::isTypedError()
This needs to identify typed errors that aren't passed indirectly at the SIL level.
1 parent 0ba605a commit 251bbbb

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4946,5 +4946,7 @@ CanSILFunctionType SILFunction::getLoweredFunctionTypeInContext(
49464946

49474947
bool SILFunctionConventions::isTypedError() const {
49484948
return !funcTy->getErrorResult()
4949-
.getInterfaceType()->isExistentialWithError();
4949+
.getInterfaceType()->isEqual(
4950+
funcTy->getASTContext().getErrorExistentialType()) ||
4951+
getNumIndirectSILResults() > 0;
49504952
}

test/IRGen/typed_throws.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
// RUN: %target-swift-frontend -primary-file %s -emit-ir -enable-experimental-feature TypedThrows -disable-availability-checking -runtime-compatibility-version 5.8 -disable-concrete-type-metadata-mangled-name-accessors | %FileCheck %s --check-prefix=CHECK-NOMANGLE
44

5+
// RUN: %target-swift-frontend -primary-file %s -emit-ir -enable-experimental-feature TypedThrows | %FileCheck %s --check-prefix=CHECK
6+
57
// XFAIL: CPU=arm64e
68

79
enum MyBigError: Error {
@@ -35,3 +37,31 @@ func buildMetatype() -> Any.Type {
3537
protocol P {
3638
associatedtype A
3739
}
40+
41+
// The following ensures that we lower
42+
func passthroughCall<T, E>(_ body: () throws(E) -> T) throws(E) -> T {
43+
try body()
44+
}
45+
46+
func five() -> Int { 5 }
47+
48+
func fiveOrBust() throws -> Int { 5 }
49+
50+
func fiveOrTypedBust() throws(MyBigError) -> Int { 5 }
51+
52+
func reabstractAsNonthrowing() -> Int {
53+
passthroughCall(five)
54+
}
55+
56+
func reabstractAsThrowing() throws -> Int {
57+
try passthroughCall(fiveOrBust)
58+
}
59+
60+
61+
func reabstractAsConcreteThrowing() throws -> Int {
62+
try passthroughCall(fiveOrTypedBust)
63+
}
64+
65+
// CHECK-LABEL: define {{.*}} swiftcc void @"$sSi12typed_throws10MyBigErrorOIgdzo_SiACIegrzr_TR"(ptr noalias nocapture sret(%TSi) %0, ptr %1, ptr %2, ptr swiftself %3, ptr noalias nocapture swifterror dereferenceable(8) %4, ptr %5)
66+
// CHECK: call swiftcc i64 %1
67+
// CHECK: br i1 %8, label %typed.error.load, label %10

0 commit comments

Comments
 (0)