2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
5
- // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
5
+ // Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
6
6
// Licensed under Apache License v2.0 with Runtime Library Exception
7
7
//
8
8
// See https://swift.org/LICENSE.txt for license information
20
20
/// return value for the `withExtendedLifetime(_:_:)` method.
21
21
/// - Returns: The return value, if any, of the `body` closure parameter.
22
22
@inlinable
23
- public func withExtendedLifetime< T, Result> (
24
- _ x: T , _ body: ( ) throws -> Result
23
+ @_preInverseGenerics
24
+ public func withExtendedLifetime< T: ~ Copyable, Result: ~ Copyable> (
25
+ _ x: borrowing T ,
26
+ _ body: ( ) throws -> Result
25
27
) rethrows -> Result {
26
28
defer { _fixLifetime ( x) }
27
29
return try body ( )
@@ -38,6 +40,7 @@ public func withExtendedLifetime<T, Result>(
38
40
/// - Returns: The return value, if any, of the `body` closure parameter.
39
41
@inlinable
40
42
public func withExtendedLifetime< T, Result> (
43
+ // FIXME(NCG): This should have T, Result as ~Copyable, but then the closure would need to take a borrow
41
44
_ x: T , _ body: ( T ) throws -> Result
42
45
) rethrows -> Result {
43
46
defer { _fixLifetime ( x) }
@@ -47,7 +50,8 @@ public func withExtendedLifetime<T, Result>(
47
50
// Fix the lifetime of the given instruction so that the ARC optimizer does not
48
51
// shorten the lifetime of x to be before this point.
49
52
@_transparent
50
- public func _fixLifetime< T> ( _ x: T ) {
53
+ @_preInverseGenerics
54
+ public func _fixLifetime< T: ~ Copyable> ( _ x: borrowing T ) {
51
55
Builtin . fixLifetime ( x)
52
56
}
53
57
0 commit comments