Skip to content

Commit 7a7cbd9

Browse files
committed
Update unit tests for improved inference rules.
1 parent cd28433 commit 7a7cbd9

File tree

7 files changed

+18
-29
lines changed

7 files changed

+18
-29
lines changed

test/SIL/implicit_lifetime_dependence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ struct Wrapper : ~Escapable {
8888
_read {
8989
yield _view
9090
}
91-
// CHECK: sil hidden @$s28implicit_lifetime_dependence7WrapperV4viewAA10BufferViewVvM : $@yield_once @convention(method) (@inout Wrapper) -> @lifetime(borrow 0) @yields @inout BufferView {
91+
// CHECK: sil hidden @$s28implicit_lifetime_dependence7WrapperV4viewAA10BufferViewVvM : $@yield_once @convention(method) (@lifetime(copy 0) @inout Wrapper) -> @lifetime(borrow 0) @yields @inout BufferView {
9292
@_lifetime(&self)
9393
_modify {
9494
yield &_view

test/SILOptimizer/lifetime_dependence/lifetime_dependence_borrow.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
// REQUIRES: swift_in_compiler
99
// REQUIRES: swift_feature_Lifetimes
1010

11-
@_unsafeNonescapableResult
12-
@_lifetime(copy source)
13-
internal func _overrideLifetime<
14-
T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable
15-
>(
16-
_ dependent: consuming T, copying source: borrowing U
17-
) -> T {
18-
dependent
19-
}
20-
2111
// Some container-ish thing.
2212
struct CN: ~Copyable {
2313
let p: UnsafeRawPointer

test/SILOptimizer/lifetime_dependence/lifetime_dependence_diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public struct NEInt: ~Escapable {
3030
var i: Int
3131

3232
// Test yielding an address.
33-
// CHECK-LABEL: sil hidden @$s4test5NEIntV5iprop{{.*}}vM : $@yield_once @convention(method) (@inout NEInt) -> @lifetime(borrow 0) @yields @inout NEInt
33+
// CHECK-LABEL: sil hidden @$s4test5NEIntV5iprop{{.*}}vM : $@yield_once @convention(method) (@lifetime(copy 0) @inout NEInt) -> @lifetime(borrow 0) @yields @inout NEInt
3434
// CHECK: bb0(%0 : $*NEInt):
3535
// CHECK: [[A:%.*]] = begin_access [modify] [static] %0 : $*NEInt
3636
// CHECK: yield [[A]] : $*NEInt, resume bb1, unwind bb2

test/SILOptimizer/lifetime_dependence/lifetime_dependence_scope_fixup.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,12 @@ func testPointeeDependenceOnMutablePointer(p: UnsafePointer<Int64>) {
280280
// CHECK: [[VAR:%.*]] = alloc_stack [lexical] [var_decl] $MutableView, var, name "span", type $MutableView
281281
// CHECK: apply %{{.*}}(%0, %{{.*}}) : $@convention(method) (UnsafeMutableRawBufferPointer, @thin MutableView.Type) -> @lifetime(borrow 0) @owned MutableView
282282
// CHECK: [[ACCESS1:%.*]] = begin_access [modify] [static] [[VAR]] : $*MutableView
283-
// CHECK: apply %{{.*}}(%{{.*}}) : $@convention(method) (@inout MutableView) -> @lifetime(borrow 0) @owned MutableView
283+
// CHECK: apply %{{.*}}(%{{.*}}) : $@convention(method) (@lifetime(copy 0) @inout MutableView) -> @lifetime(borrow 0) @owned MutableView
284284
// CHECK: [[LD1:%.*]] = load %{{.*}} : $*MutableView
285285
// CHECK: apply %{{.*}}([[LD1]]) : $@convention(thin) (@guaranteed MutableView) -> ()
286286
// CHECK: end_access [[ACCESS1]] : $*MutableView
287287
// CHECK: [[ACCESS2:%.*]] = begin_access [modify] [static] [[VAR]] : $*MutableView
288-
// CHECK: apply %{{.*}}(%{{.*}}) : $@convention(method) (@inout MutableView) -> @lifetime(borrow 0) @owned MutableView
288+
// CHECK: apply %{{.*}}(%{{.*}}) : $@convention(method) (@lifetime(copy 0) @inout MutableView) -> @lifetime(borrow 0) @owned MutableView
289289
// CHECK: [[LD2:%.*]] = load %{{.*}} : $*MutableView
290290
// CHECK: apply %{{.*}}([[LD2]]) : $@convention(thin) (@guaranteed MutableView) -> ()
291291
// CHECK: end_access [[ACCESS2]] : $*MutableView

test/Sema/lifetime_attr.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func invalidDependenceInoutInt(_ x: inout Int) -> NE {
6363
NE()
6464
}
6565

66-
@_lifetime(result: copy source)
67-
@_lifetime(result: borrow source) // TODO: display error here
68-
func invalidTarget(_ result: inout NE, _ source: consuming NE) { // expected-error{{invalid duplicate target lifetime dependencies on function}}
66+
@_lifetime(result: copy source) // expected-error{{duplicate lifetime dependence specifier}}
67+
@_lifetime(result: borrow source)
68+
func invalidTarget(_ result: inout NE, _ source: consuming NE) {
6969
result = source
7070
}
7171

@@ -123,6 +123,7 @@ struct Wrapper : ~Escapable {
123123
}
124124
@_lifetime(self: &self)
125125
nonmutating _modify {// expected-error{{lifetime-dependent parameter 'self' must be 'inout'}}
126+
// expected-error@-1{{cannot infer the lifetime dependence scope on a method with a ~Escapable parameter, specify '@_lifetime(borrow self)' or '@_lifetime(copy self)'}}
126127
}
127128
}
128129

test/Sema/lifetime_attr_nofeature.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ func derive(_ ne: NE) -> NE { // expected-error{{a function cannot return a ~Esc
99
ne
1010
}
1111

12-
func f_inout_infer(a: inout MutableRawSpan) {}
12+
func f_inout_infer(a: inout MutableRawSpan) {} // DEFAULT OK
1313

14-
func f_inout_no_infer(a: inout MutableRawSpan, b: RawSpan) {}
15-
// expected-error @-1{{a function cannot have a ~Escapable 'inout' parameter 'a' in addition to other ~Escapable parameters}}
14+
func f_inout_no_infer(a: inout MutableRawSpan, b: RawSpan) {} // DEFAULT OK
1615

test/Sema/lifetime_depend_nofeature.swift

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ struct EmptyNonEscapable: ~Escapable {} // expected-error{{an implicit initializ
1111
// Don't allow non-Escapable return values.
1212
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a function cannot return a ~Escapable result}}
1313

14-
func neInout(span: inout RawSpan) {} // OK
14+
func neInout(span: inout RawSpan) {} // DEFAULT OK
1515

16-
func neInoutNEParam(span: inout RawSpan, _: RawSpan) {} // expected-error{{a function cannot have a ~Escapable 'inout' parameter 'span'}}
16+
func neInoutNEParam(span: inout RawSpan, _: RawSpan) {} // DEFAULT OK
1717

1818
struct S {
1919
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a method cannot return a ~Escapable result}}
2020

2121
func neInout(span: inout RawSpan) {} // OK
2222

23-
func neInoutNEParam(span: inout RawSpan, _: RawSpan) {} // expected-error{{a method cannot have a ~Escapable 'inout' parameter 'span'}}
23+
func neInoutNEParam(span: inout RawSpan, _: RawSpan) {} // DEFAULT OK
2424

2525
mutating func mutatingNEInout(span: inout RawSpan) {} // OK
2626

27-
mutating func mutatingNEInoutParam(span: inout RawSpan, _: RawSpan) {} // expected-error{{a mutating method cannot have a ~Escapable 'inout' parameter 'span'}}
27+
mutating func mutatingNEInoutParam(span: inout RawSpan, _: RawSpan) {} // DEFAULT OK
2828
}
2929

3030
class C {
@@ -36,16 +36,15 @@ class C {
3636
extension MutableSpan {
3737
func method() {} // OK
3838

39-
mutating func mutatingMethod() {} // expected-error{{a mutating method cannot have a ~Escapable 'self'}}
39+
mutating func mutatingMethod() {} // DEFAULT OK
4040

4141
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a method cannot return a ~Escapable result}}
4242

43-
func neInout(span: inout RawSpan) {} // expected-error{{a method cannot have a ~Escapable 'inout' parameter 'span'}}
43+
func neInout(span: inout RawSpan) {} // DEFAULT OK
4444

45-
mutating func mutatingNEInout(span: inout RawSpan) {} // expected-error{{a mutating method cannot have a ~Escapable 'self'}}
46-
// expected-error@-1{{a mutating method cannot have a ~Escapable 'inout' parameter 'span'}}
45+
mutating func mutatingNEInout(span: inout RawSpan) {} // DEFAULT OK
4746
}
4847

4948
extension Span {
50-
mutating func mutate() {} // expected-error{{a mutating method cannot have a ~Escapable 'self'}}
49+
mutating func mutate() {} // DEFAULT OK
5150
}

0 commit comments

Comments
 (0)