10
10
//
11
11
//===----------------------------------------------------------------------===//
12
12
13
+ /// Extends the lifetime of the given instance.
14
+ ///
15
+ /// - Parameters:
16
+ /// - x: An instance to preserve until this function returns.
17
+ @_alwaysEmitIntoClient
18
+ public func extendLifetime< T: ~ Copyable & ~ Escapable> (
19
+ _ x: borrowing T
20
+ ) {
21
+ Builtin . fixLifetime ( x)
22
+ }
23
+
13
24
/// Evaluates a closure while ensuring that the given instance is not destroyed
14
25
/// before the closure returns.
15
26
///
20
31
/// return value for the `withExtendedLifetime(_:_:)` method.
21
32
/// - Returns: The return value, if any, of the `body` closure parameter.
22
33
@_alwaysEmitIntoClient
23
- public func withExtendedLifetime< T: ~ Copyable, E: Error , Result: ~ Copyable> (
34
+ public func withExtendedLifetime<
35
+ T: ~ Copyable & ~ Escapable,
36
+ E: Error ,
37
+ Result: ~ Copyable
38
+ > (
24
39
_ x: borrowing T ,
25
40
_ body: ( ) throws ( E ) -> Result
26
41
) throws ( E ) -> Result {
@@ -32,7 +47,8 @@ public func withExtendedLifetime<T: ~Copyable, E: Error, Result: ~Copyable>(
32
47
@_silgen_name ( " $ss20withExtendedLifetimeyq_x_q_yKXEtKr0_lF " )
33
48
@usableFromInline
34
49
internal func __abi_withExtendedLifetime< T, Result> (
35
- _ x: T , _ body: ( ) throws -> Result
50
+ _ x: T ,
51
+ _ body: ( ) throws -> Result
36
52
) rethrows -> Result {
37
53
defer { _fixLifetime ( x) }
38
54
return try body ( )
@@ -48,7 +64,11 @@ internal func __abi_withExtendedLifetime<T, Result>(
48
64
/// return value for the `withExtendedLifetime(_:_:)` method.
49
65
/// - Returns: The return value, if any, of the `body` closure parameter.
50
66
@_alwaysEmitIntoClient
51
- public func withExtendedLifetime< T: ~ Copyable, E: Error , Result: ~ Copyable> (
67
+ public func withExtendedLifetime<
68
+ T: ~ Copyable & ~ Escapable,
69
+ E: Error ,
70
+ Result: ~ Copyable
71
+ > (
52
72
_ x: borrowing T ,
53
73
_ body: ( borrowing T ) throws ( E ) -> Result
54
74
) throws ( E ) -> Result {
@@ -70,7 +90,7 @@ internal func __abi_withExtendedLifetime<T, Result>(
70
90
// shorten the lifetime of x to be before this point.
71
91
@_transparent
72
92
@_preInverseGenerics
73
- public func _fixLifetime< T: ~ Copyable> ( _ x: borrowing T ) {
93
+ public func _fixLifetime< T: ~ Copyable & ~ Escapable > ( _ x: borrowing T ) {
74
94
Builtin . fixLifetime ( x)
75
95
}
76
96
0 commit comments