|
3 | 3 | // Like opaque_values_Onone.swift but for code that needs to be compiled with
|
4 | 4 | // -parse-stdlib.
|
5 | 5 |
|
| 6 | +protocol Error {} |
| 7 | +enum Never : Error{} |
| 8 | + |
6 | 9 | precedencegroup AssignmentPrecedence { assignment: true }
|
7 | 10 | precedencegroup CastingPrecedence {}
|
8 | 11 |
|
@@ -97,3 +100,40 @@ func getAnotherType<T, U>(_ object: inout T, to ty: U.Type) -> U {
|
97 | 100 | func isOfTypeOfAnyObjectType(fromAny any: Any) -> Bool {
|
98 | 101 | type(of: any) is Builtin.AnyObject.Type
|
99 | 102 | }
|
| 103 | + |
| 104 | +@available(SwiftStdlib 5.1, *) |
| 105 | +struct UnsafeContinuation<T, E: Error> { |
| 106 | + @usableFromInline internal var context: Builtin.RawUnsafeContinuation |
| 107 | + |
| 108 | +// CHECK-LABEL: sil {{.*}}@unsafeContinuationResumeNoThrow : {{.*}} { |
| 109 | +// CHECK: {{bb[0-9]+}}([[VALUE:%[^,]+]] : $*T, [[CONTINUATION:%[^,]+]] : $UnsafeContinuation<T, Never>): |
| 110 | +// CHECK: [[STACK:%[^,]+]] = alloc_stack $T |
| 111 | +// CHECK: [[CONTEXT:%[^,]+]] = struct_extract [[CONTINUATION]] |
| 112 | +// CHECK: copy_addr [[VALUE]] to [init] [[STACK]] |
| 113 | +// CHECK: builtin "resumeNonThrowingContinuationReturning"<T>([[CONTEXT]] : $Builtin.RawUnsafeContinuation, [[STACK]] : $*T) |
| 114 | +// CHECK: destroy_addr [[VALUE]] |
| 115 | +// CHECK-LABEL: } // end sil function 'unsafeContinuationResumeNoThrow' |
| 116 | + @_silgen_name("unsafeContinuationResumeNoThrow") |
| 117 | + @_alwaysEmitIntoClient |
| 118 | + public func resume(returning value: __owned T) where E == Never { |
| 119 | + #if compiler(>=5.5) && $BuiltinContinuation |
| 120 | + Builtin.resumeNonThrowingContinuationReturning(context, value) |
| 121 | + #endif |
| 122 | + } |
| 123 | + |
| 124 | +// CHECK-LABEL: sil {{.*}}@unsafeContinuationResumeThrow : {{.*}} { |
| 125 | +// CHECK: {{bb[0-9]+}}([[VALUE:%[^,]+]] : $*T, [[CONTINUATION:%[^,]+]] : $UnsafeContinuation<T, E>): |
| 126 | +// CHECK: [[STACK:%[^,]+]] = alloc_stack $T |
| 127 | +// CHECK: [[CONTEXT:%[^,]+]] = struct_extract [[CONTINUATION]] |
| 128 | +// CHECK: copy_addr [[VALUE]] to [init] [[STACK]] |
| 129 | +// CHECK: builtin "resumeThrowingContinuationReturning"<T>([[CONTEXT]] : $Builtin.RawUnsafeContinuation, [[STACK]] : $*T) |
| 130 | +// CHECK: destroy_addr [[VALUE]] |
| 131 | +// CHECK-LABEL: } // end sil function 'unsafeContinuationResumeThrow' |
| 132 | + @_silgen_name("unsafeContinuationResumeThrow") |
| 133 | + @_alwaysEmitIntoClient |
| 134 | + public func resume(returning value: __owned T) { |
| 135 | + #if compiler(>=5.5) && $BuiltinContinuation |
| 136 | + Builtin.resumeThrowingContinuationReturning(context, value) |
| 137 | + #endif |
| 138 | + } |
| 139 | +} |
0 commit comments