Skip to content

Commit 94c4c0e

Browse files
committed
Add lifetime dependence unit tests for synthesized accessors.
1 parent 03efaf4 commit 94c4c0e

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
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+
}

test/SILOptimizer/simplify_mark_dependence.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ bb0(%0 : $*Builtin.Int64, %1 : $B):
167167

168168
// CHECK-LABEL: sil hidden [ossa] @testChainedDependence : $@convention(thin) (@guaranteed NEHolder) -> () {
169169
// CHECK: bb0(%0 : @noImplicitCopy @guaranteed $NEHolder):
170-
// CHECK: ([[YIELD:%[0-9]+]], [[TOKEN:%[0-9]+]]) = begin_apply %2(%1) : $@yield_once @convention(method) (@guaranteed NEHolder) -> @lifetime(borrow 0) @yields @guaranteed NE
170+
// CHECK: ([[YIELD:%[0-9]+]], [[TOKEN:%[0-9]+]]) = begin_apply %{{.*}}(%{{.*}}) : $@yield_once @convention(method) (@guaranteed NEHolder) -> @lifetime(borrow 0) @yields @guaranteed NE
171171
// CHECK: [[MD1:%[0-9]+]] = mark_dependence [nonescaping] [[YIELD]] on [[TOKEN]]
172172
// CHECK: mark_dependence [nonescaping] [[MD1]] on
173173
// CHECK-LABEL: } // end sil function 'testChainedDependence'

0 commit comments

Comments
 (0)