Skip to content

Commit b7de5e4

Browse files
committed
Add lifetime dependence unit tests for syntesized accessors.
1 parent 03efaf4 commit b7de5e4

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// RUN: %target-swift-emit-sil -enable-experimental-feature Lifetimes -primary-file %s | %FileCheck %s
2+
3+
// REQUIRES: swift_feature_Lifetimes
4+
5+
struct NE : ~Escapable {
6+
let _p: UnsafeRawPointer
7+
8+
@_lifetime(borrow p)
9+
init(_ p: UnsafeRawPointer) { self._p = p }
10+
}
11+
12+
struct NEStoredProp : ~Copyable, ~Escapable {
13+
var ne: NE
14+
}
15+
16+
struct NCNE : ~Copyable, ~Escapable {
17+
let _p: UnsafeRawPointer
18+
19+
@_lifetime(borrow p)
20+
init(_ p: UnsafeRawPointer) {
21+
self._p = p
22+
}
23+
}
24+
25+
struct NCNEHolder : ~Copyable, ~Escapable {
26+
var p: UnsafeRawPointer
27+
28+
// this cannot be public in order to synthesize the _read accessor.
29+
var ncneBorrow: NCNE {
30+
// CHECK-LABEL: sil{{.*}} @$s9accessors10NCNEHolderV10ncneBorrowAA4NCNEVvr : $@yield_once @convention(method) (@guaranteed NCNEHolder) -> @lifetime(borrow 0) @yields @guaranteed NCNE {
31+
@_lifetime(borrow self)
32+
borrowing get {
33+
_overrideLifetime(NCNE(p), borrowing: self)
34+
}
35+
// CHECK-LABEL: sil{{.*}} @$s9accessors10NCNEHolderV10ncneBorrowAA4NCNEVvM : $@yield_once @convention(method) (@lifetime(copy 0) @inout NCNEHolder) -> @lifetime(borrow 0) @yields @inout NCNE {
36+
@_lifetime(self: copy self)
37+
set {
38+
p = newValue._p
39+
}
40+
}
41+
42+
// this cannot be public in order to synthesize the _read accessor.
43+
var ncneCopy: NCNE {
44+
// CHECK-LABEL: sil{{.*}} @$s9accessors10NCNEHolderV8ncneCopyAA4NCNEVvr : $@yield_once @convention(method) (@guaranteed NCNEHolder) -> @lifetime(copy 0) @yields @guaranteed NCNE {
45+
@_lifetime(copy self)
46+
borrowing get {
47+
_overrideLifetime(NCNE(p), copying: self)
48+
}
49+
// CHECK-LABEL: sil{{.*}} @$s9accessors10NCNEHolderV8ncneCopyAA4NCNEVvM : $@yield_once @convention(method) (@lifetime(copy 0) @inout NCNEHolder) -> @lifetime(copy 0) @yields @inout NCNE {
50+
@_lifetime(self: copy self)
51+
set {
52+
p = newValue._p
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)