Skip to content

Commit ffb1137

Browse files
committed
Update lifetime_dependence tests for stricter diagnostics.
1 parent cc07b4b commit ffb1137

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

test/ModuleInterface/Inputs/lifetime_dependence.swift

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
@_unsafeNonescapableResult
2+
@_alwaysEmitIntoClient
3+
@_transparent
4+
@lifetime(borrow source)
5+
internal func _overrideLifetime<T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable>(
6+
_ dependent: consuming T, borrowing source: borrowing U) -> T {
7+
dependent
8+
}
9+
10+
@_unsafeNonescapableResult
11+
@_alwaysEmitIntoClient
12+
@_transparent
13+
@lifetime(source)
14+
internal func _overrideLifetime<T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable>(
15+
_ dependent: consuming T, copying source: borrowing U) -> T {
16+
dependent
17+
}
18+
119
public struct AnotherView : ~Escapable {
220
@usableFromInline let _ptr: UnsafeRawBufferPointer
321
@usableFromInline let _count: Int
@@ -21,19 +39,23 @@ public struct BufferView : ~Escapable {
2139
@inlinable
2240
@lifetime(borrow a)
2341
internal init(_ ptr: UnsafeRawBufferPointer, _ a: borrowing Array<Int>) {
24-
self.init(ptr, a.count)
42+
let bv = BufferView(ptr, a.count)
43+
self = _overrideLifetime(bv, borrowing: a)
2544
}
2645
@inlinable
2746
@lifetime(a)
2847
internal init(_ ptr: UnsafeRawBufferPointer, _ a: consuming AnotherView) {
29-
self.init(ptr, a._count)
48+
let bv = BufferView(ptr, a._count)
49+
self = _overrideLifetime(bv, copying: a)
3050
}
3151
}
3252

3353
@inlinable
3454
@lifetime(x)
3555
public func derive(_ x: consuming BufferView) -> BufferView {
36-
return BufferView(x._ptr, x._count)
56+
let pointer = x._ptr
57+
let bv = BufferView(pointer, x._count)
58+
return _overrideLifetime(bv, copying: x)
3759
}
3860

3961
@inlinable
@@ -42,7 +64,9 @@ public func use(_ x: consuming BufferView) {}
4264
@inlinable
4365
@lifetime(view)
4466
public func consumeAndCreate(_ view: consuming BufferView) -> BufferView {
45-
return BufferView(view._ptr, view._count)
67+
let pointer = view._ptr
68+
let bv = BufferView(pointer, view._count)
69+
return _overrideLifetime(bv, copying: view)
4670
}
4771

4872
@inlinable
@@ -54,14 +78,6 @@ public func deriveThisOrThat(_ this: consuming BufferView, _ that: consuming Buf
5478
return BufferView(that._ptr, that._count)
5579
}
5680

57-
@_unsafeNonescapableResult
58-
@_transparent
59-
@lifetime(borrow source)
60-
internal func _overrideLifetime<T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable>(
61-
_ dependent: consuming T, borrowing source: borrowing U) -> T {
62-
dependent
63-
}
64-
6581
public struct Container {
6682
var buffer: UnsafeRawBufferPointer
6783
var object: AnyObject

0 commit comments

Comments
 (0)