-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathimplicit_lifetime_dependence.swift
71 lines (60 loc) · 2.73 KB
/
implicit_lifetime_dependence.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t %S/Inputs/def_implicit_lifetime_dependence.swift \
// RUN: -enable-experimental-feature LifetimeDependence \
// RUN: -disable-lifetime-dependence-diagnostics
// RUN: llvm-bcanalyzer %t/def_implicit_lifetime_dependence.swiftmodule
// RUN: %target-swift-frontend -module-name lifetime-dependence -emit-sil -I %t %s \
// RUN: -enable-experimental-feature LifetimeDependence \
// RUN: | %FileCheck %s
// REQUIRES: swift_feature_LifetimeDependence
import def_implicit_lifetime_dependence
func use(_ x: borrowing BufferView) {}
func mutate(_ x: inout BufferView) {}
func testBasic() {
let a = [Int](repeating: 0, count: 4)
a.withUnsafeBytes {
let view = BufferView($0, a.count)
let derivedView = derive(view)
let consumedView = consumeAndCreate(derivedView)
let borrowedView = borrowAndCreate(consumedView)
use(borrowedView)
}
}
func testInitializers() {
let a = [Int](repeating: 0, count: 4)
a.withUnsafeBytes {
let view1 = BufferView($0, a.count)
let view2 = BufferView(view1)
let view3 = BufferView(view2)
use(view3)
}
}
func unsafetest(_ ptr: UnsafeRawBufferPointer, _ c: Int) {
let view1 = BufferView(ptr, c)
let view2 = BufferView(view1)
let view3 = BufferView(view2)
use(view3)
}
func testGetter() {
let a = [Int](repeating: 0, count: 4)
a.withUnsafeBytes {
let c = Container($0, a.count)
let view = c.view
use(view)
}
}
func testReadMutateAccessors() {
let a = [Int](repeating: 0, count: 4)
a.withUnsafeBytes {
let view = BufferView($0, a.count)
var c = Wrapper(view)
use(c.view)
mutate(&c.view)
}
}
// CHECK-LABEL: sil @$s32def_implicit_lifetime_dependence10BufferViewVyACSW_SitcfC : $@convention(method) (UnsafeRawBufferPointer, Int, @thin BufferView.Type) -> @lifetime(borrow 0) @owned BufferView
// CHECK-LABEL: sil @$s32def_implicit_lifetime_dependence6deriveyAA10BufferViewVADF : $@convention(thin) (@guaranteed BufferView) -> @lifetime(copy 0) @owned BufferView
// CHECK-LABEL: sil @$s32def_implicit_lifetime_dependence16consumeAndCreateyAA10BufferViewVADnF : $@convention(thin) (@owned BufferView) -> @lifetime(copy 0) @owned BufferView
// CHECK-LABEL: sil @$s32def_implicit_lifetime_dependence15borrowAndCreateyAA10BufferViewVADF : $@convention(thin) (@guaranteed BufferView) -> @lifetime(copy 0) @owned BufferView
// CHECK-LABEL: sil @$s32def_implicit_lifetime_dependence9ContainerV4viewAA10BufferViewVvg : $@convention(method) (@guaranteed Container) -> @lifetime(borrow 0) @owned BufferView
// CHECK-LABEL: sil @$s32def_implicit_lifetime_dependence7WrapperV4viewAA10BufferViewVvr : $@yield_once @convention(method) (@guaranteed Wrapper) -> @lifetime(copy 0) @yields @guaranteed BufferView