|
| 1 | +// RUN: %target-swift-frontend -primary-file %s -emit-irgen -enable-experimental-feature TypedThrows -disable-availability-checking -runtime-compatibility-version none -target %module-target-future -enable-library-evolution | %FileCheck %s --check-prefix=CHECK |
| 2 | + |
| 3 | +// REQUIRES: PTRSIZE=64 |
| 4 | +// UNSUPPORTED: CPU=arm64e |
| 5 | + |
| 6 | +@frozen |
| 7 | +public struct FixedSize : Error { |
| 8 | + var x = 0 |
| 9 | + var y = 0 |
| 10 | +} |
| 11 | + |
| 12 | +public protocol P { |
| 13 | + associatedtype Failure: Error = any Error |
| 14 | + |
| 15 | + func f(body: () throws -> Void) async rethrows |
| 16 | + func f2(body: () throws -> Void) rethrows |
| 17 | + |
| 18 | + func g(body: () throws(Failure) -> Void) async throws(Failure) |
| 19 | + func g4(body: () throws(FixedSize) -> Void) async throws(FixedSize) |
| 20 | + |
| 21 | + func g2(body: () throws(Failure) -> Void) throws(Failure) |
| 22 | + func g3(body: () throws(FixedSize) -> Void) throws(FixedSize) |
| 23 | +} |
| 24 | + |
| 25 | +extension P { |
| 26 | + // CHECK-LABEL: define{{.*}} swifttailcc void @"$s19typed_throws_thunks1PP1g4bodyyyy7FailureQzYKXE_tYaAGYKFTj"(ptr swiftasync %0, ptr %1, ptr %2, ptr noalias swiftself %3, ptr %4, ptr %5, ptr %6) |
| 27 | + // CHECK-NOT: ret |
| 28 | + // CHECK: call { ptr, ptr } (i32, ptr, ptr, ...) @llvm.coro.suspend.async.sl_p0p0s({{.*}}, ptr %1, ptr %2, ptr %3, ptr %4, ptr %5, ptr %6) |
| 29 | + public func g(body: () throws(Failure) -> Void) async throws(Failure) { |
| 30 | + do { |
| 31 | + return try await f(body: body) |
| 32 | + } catch { |
| 33 | + throw error as! Failure |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + // CHECK-LABEL: define{{.*}} swifttailcc void @"$s19typed_throws_thunks1PP2g44bodyyyyAA9FixedSizeVYKXE_tYaAGYKFTj"(ptr swiftasync %0, ptr %1, ptr %2, ptr noalias swiftself %3, ptr %4, ptr %5, ptr %6) |
| 38 | + // CHECK-NOT: ret |
| 39 | + // CHECK: call { ptr, ptr } (i32, ptr, ptr, ...) @llvm.coro.suspend.async.sl_p0p0s({{.*}} ptr %1, ptr %2, ptr %3, ptr %4, ptr %5, ptr %6) |
| 40 | + public func g4(body: () throws(FixedSize) -> Void) async throws(FixedSize) { |
| 41 | + do { |
| 42 | + return try await f(body: body) |
| 43 | + } catch { |
| 44 | + throw error as! FixedSize |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + // CHECK-LABEL: define{{.*}} swiftcc void @"$s19typed_throws_thunks1PP2g24bodyyyy7FailureQzYKXE_tAGYKFTj"(ptr %0, ptr %1, ptr noalias swiftself %2, ptr noalias nocapture swifterror dereferenceable(8) %3, ptr %4, ptr %5, ptr %6) |
| 49 | + // CHECK-NOT: ret |
| 50 | + // CHECK: call swiftcc void {{.*}}(ptr %0, ptr %1, ptr noalias swiftself %2, ptr noalias nocapture swifterror dereferenceable(8) %3, ptr %4, ptr %5, ptr %6) |
| 51 | + |
| 52 | + public func g2(body: () throws(Failure) -> Void) throws(Failure) { |
| 53 | + do { |
| 54 | + return try f2(body: body) |
| 55 | + } catch { |
| 56 | + throw error as! Failure |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + // CHECK-LABEL: define{{.*}} swiftcc void @"$s19typed_throws_thunks1PP2g34bodyyyyAA9FixedSizeVYKXE_tAGYKFTj"(ptr %0, ptr %1, ptr noalias swiftself %2, ptr noalias nocapture swifterror dereferenceable(8) %3, ptr %4, ptr %5, ptr %6) |
| 61 | + // CHECK-NOT: ret |
| 62 | + // CHECK: call swiftcc void {{.*}}(ptr %0, ptr %1, ptr noalias swiftself %2, ptr noalias nocapture swifterror dereferenceable(8) %3, ptr %4, ptr %5, ptr %6) |
| 63 | + |
| 64 | + |
| 65 | + public func g3(body: () throws(FixedSize) -> Void) throws(FixedSize) { |
| 66 | + } |
| 67 | +} |
0 commit comments