Skip to content

Commit 046c61d

Browse files
committed
Update tests after disallowing @_lifetime(borrow) for inout
(cherry picked from commit f6c7524)
1 parent 19676a0 commit 046c61d

8 files changed

+57
-24
lines changed

test/SIL/implicit_lifetime_dependence.swift

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

test/SILOptimizer/lifetime_dependence/coroutine.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct Wrapper : ~Escapable {
4040
_read {
4141
yield _view
4242
}
43-
@_lifetime(borrow self)
43+
@_lifetime(&self)
4444
_modify {
4545
yield &_view
4646
}

test/SILOptimizer/lifetime_dependence/dependence_insertion.swift

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,39 @@ func bv_pointer_convert(p: UnsafePointer<Int>) -> BV {
8181
BV(p, 0)
8282
}
8383

84+
// =============================================================================
85+
// Builtin.addressOfBorrow
86+
// =============================================================================
87+
88+
// swift-frontend -emit-sil -enable-builtin-module -enable-experimental-feature Lifetimes -enable-experimental-feature AddressableParameters -Xllvm -sil-print-function=test ./dependsOnAddress.swift
89+
90+
import Builtin
91+
92+
struct IntHolder {
93+
var field: Int
94+
}
95+
96+
struct NERawPointer: ~Escapable {
97+
var p: Builtin.RawPointer
98+
}
99+
100+
@_lifetime(borrow x)
101+
func pointerDepends(on x: Builtin.RawPointer) -> NERawPointer {
102+
NERawPointer(p: x)
103+
}
104+
105+
// CHECK-LABEL: sil hidden [ossa] @$s4test0A22BuiltinAddressOfBorrow6holderAA12NERawPointerVAA9IntHolderVz_tF : $@convention(thin) (@inout IntHolder) -> @lifetime(borrow 0) @owned NERawPointer {
106+
// CHECK: bb0(%0 : $*IntHolder):
107+
// CHECK: [[ACCESS:%[0-9]+]] = begin_access [read] [static] %0
108+
// CHECK: [[PTR:%[0-9]+]] = address_to_pointer [stack_protection] %2 to $Builtin.RawPointer
109+
// CHECK: [[NE:%[0-9]+]] = apply %{{.*}}([[PTR]]) : $@convention(thin) (Builtin.RawPointer) -> @lifetime(borrow 0) @owned NERawPointer
110+
// CHECK: mark_dependence [unresolved] [[NE]] on %0
111+
// CHECK-LABEL: } // end sil function '$s4test0A22BuiltinAddressOfBorrow6holderAA12NERawPointerVAA9IntHolderVz_tF'
112+
@_lifetime(&holder)
113+
func testBuiltinAddressOfBorrow(holder: inout IntHolder) -> NERawPointer {
114+
pointerDepends(on: Builtin.addressOfBorrow(holder))
115+
}
116+
84117
// =============================================================================
85118
// @_addressableForDependencies
86119
// =============================================================================

test/SILOptimizer/lifetime_dependence/lifetime_dependence_inherit.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct NEBV : ~Escapable {
5858
_read {
5959
yield bv
6060
}
61-
@_lifetime(borrow self)
61+
@_lifetime(&self)
6262
_modify {
6363
yield &bv
6464
}

test/SILOptimizer/lifetime_dependence/lifetime_dependence_scope_fixup.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ struct Wrapper : ~Escapable {
224224
_read {
225225
yield _view
226226
}
227-
@_lifetime(borrow self)
227+
@_lifetime(&self)
228228
_modify {
229229
yield &_view
230230
}

test/SILOptimizer/lifetime_dependence/semantics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct MutableSpan<T>: ~Escapable, ~Copyable {
6767
let base: UnsafeMutablePointer<T>
6868
let count: Int
6969

70-
@_lifetime(&base)
70+
@_lifetime(borrow base)
7171
init(base: UnsafeMutablePointer<T>, count: Int) {
7272
self.base = base
7373
self.count = count
@@ -406,7 +406,7 @@ public func testTrivialLocalDeadEnd(p: UnsafePointer<Int>) {
406406

407407
// Test dependence on a borrow of a trivial inout. The access scope can be ignored since we don't care about the
408408
// in-memory value.
409-
@_lifetime(borrow p)
409+
@_lifetime(&p)
410410
public func testTrivialInoutBorrow(p: inout UnsafePointer<Int>) -> Span<Int> {
411411
return Span(base: p, count: 1)
412412
}
@@ -597,7 +597,7 @@ func testNonAddressable(arg: Holder) -> Span<Int> {
597597
*/
598598

599599
/* TODO: rdar://145872854 (SILGen: @addressable inout arguments are copied)
600-
@_lifetime(borrow arg)
600+
@_lifetime(&arg)
601601
func test(arg: inout AddressableInt) -> Span<Int> {
602602
arg.span()
603603
}

test/Sema/lifetime_depend_infer.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct NonEscapableSelf: ~Escapable {
4040
@_lifetime(copy self) // OK
4141
mutating func mutatingMethodNoParamCopy() -> NonEscapableSelf { self }
4242

43-
@_lifetime(borrow self) // OK
43+
@_lifetime(&self) // OK
4444
mutating func mutatingMethodNoParamBorrow() -> NonEscapableSelf { self }
4545

4646
func methodOneParam(_: Int) -> NonEscapableSelf { self } // expected-error{{a method with a ~Escapable result requires '@_lifetime(...)'}}
@@ -63,7 +63,7 @@ struct NonEscapableSelf: ~Escapable {
6363
@_lifetime(copy self) // OK
6464
mutating func mutatingMethodOneParamCopy(_: Int) -> NonEscapableSelf { self }
6565

66-
@_lifetime(borrow self) // OK
66+
@_lifetime(&self) // OK
6767
mutating func mutatingMethodOneParamBorrow(_: Int) -> NonEscapableSelf { self }
6868
}
6969

@@ -87,7 +87,7 @@ struct EscapableTrivialSelf {
8787
@_lifetime(copy self) // expected-error{{cannot copy the lifetime of an Escapable type, use '@_lifetime(&self)' instead}}
8888
mutating func mutatingMethodNoParamCopy() -> NEImmortal { NEImmortal() }
8989

90-
@_lifetime(borrow self)
90+
@_lifetime(&self)
9191
mutating func mutatingMethodNoParamBorrow() -> NEImmortal { NEImmortal() }
9292

9393
func methodOneParam(_: Int) -> NEImmortal { NEImmortal() } // expected-error{{a method with a ~Escapable result requires '@_lifetime(...)'}}
@@ -109,7 +109,7 @@ struct EscapableTrivialSelf {
109109
@_lifetime(copy self) // expected-error{{cannot copy the lifetime of an Escapable type, use '@_lifetime(&self)' instead}}
110110
mutating func mutatingMethodOneParamCopy(_: Int) -> NEImmortal { NEImmortal() }
111111

112-
@_lifetime(borrow self)
112+
@_lifetime(&self)
113113
mutating func mutatingMethodOneParamBorrow(_: Int) -> NEImmortal { NEImmortal() }
114114
}
115115

@@ -341,7 +341,7 @@ struct NonescapableSelfAccessors: ~Escapable {
341341
yield ne
342342
}
343343

344-
@_lifetime(borrow self)
344+
@_lifetime(&self)
345345
_modify {
346346
yield &ne
347347
}
@@ -401,7 +401,7 @@ struct NonescapableSelfAccessors: ~Escapable {
401401
ne
402402
}
403403

404-
@_lifetime(borrow self)
404+
@_lifetime(&self)
405405
set {
406406
ne = newValue
407407
}
@@ -413,7 +413,7 @@ struct NonescapableSelfAccessors: ~Escapable {
413413
yield ne
414414
}
415415

416-
@_lifetime(borrow self)
416+
@_lifetime(&self)
417417
_modify {
418418
yield &ne
419419
}
@@ -533,7 +533,7 @@ struct NonEscapableMutableSelf: ~Escapable {
533533
@_lifetime(self: copy self) // OK
534534
mutating func mutatingMethodNoParamCopy() {}
535535

536-
@_lifetime(self: borrow self) // expected-error{{invalid use of borrow dependence on the same inout parameter}}
536+
@_lifetime(self: &self) // expected-error{{invalid use of borrow dependence on the same inout parameter}}
537537
mutating func mutatingMethodNoParamBorrow() {}
538538

539539
mutating func mutatingMethodOneParam(_: NE) {} // expected-error{{a mutating method with a ~Escapable 'self' requires '@_lifetime(self: ...)'}}
@@ -544,6 +544,6 @@ struct NonEscapableMutableSelf: ~Escapable {
544544
@_lifetime(copy self) // OK
545545
mutating func mutatingMethodOneParamCopy(_: NE) {}
546546

547-
@_lifetime(borrow self)
547+
@_lifetime(&self)
548548
mutating func mutatingMethodOneParamBorrow(_: NE) {}
549549
}

test/Sema/lifetime_depend_infer_lazy.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct NonEscapableSelf: ~Escapable {
3838
@_lifetime(copy self) // OK
3939
mutating func mutatingMethodNoParamCopy() -> NonEscapableSelf { self }
4040

41-
@_lifetime(borrow self) // OK
41+
@_lifetime(&self) // OK
4242
mutating func mutatingMethodNoParamBorrow() -> NonEscapableSelf { self }
4343

4444
func methodOneParam(_: Int) -> NonEscapableSelf { self } // OK
@@ -58,7 +58,7 @@ struct NonEscapableSelf: ~Escapable {
5858
@_lifetime(copy self) // OK
5959
mutating func mutatingMethodOneParamCopy(_: Int) -> NonEscapableSelf { self }
6060

61-
@_lifetime(borrow self) // OK
61+
@_lifetime(&self) // OK
6262
mutating func mutatingMethodOneParamBorrow(_: Int) -> NonEscapableSelf { self }
6363
}
6464

@@ -72,7 +72,7 @@ struct EscapableTrivialSelf {
7272
@_lifetime(self) // OK
7373
mutating func mutatingMethodNoParamLifetime() -> NEImmortal { NEImmortal() }
7474

75-
@_lifetime(borrow self) // OK
75+
@_lifetime(&self) // OK
7676
mutating func mutatingMethodNoParamBorrow() -> NEImmortal { NEImmortal() }
7777

7878
@_lifetime(self) // OK
@@ -84,7 +84,7 @@ struct EscapableTrivialSelf {
8484
@_lifetime(self) // OK
8585
mutating func mutatingMethodOneParamLifetime(_: Int) -> NEImmortal { NEImmortal() }
8686

87-
@_lifetime(borrow self)
87+
@_lifetime(&self)
8888
mutating func mutatingMethodOneParamBorrow(_: Int) -> NEImmortal { NEImmortal() }
8989
}
9090

@@ -254,7 +254,7 @@ struct NonescapableSelfAccessors: ~Escapable {
254254
yield ne
255255
}
256256

257-
@_lifetime(borrow self)
257+
@_lifetime(&self)
258258
_modify {
259259
yield &ne
260260
}
@@ -314,7 +314,7 @@ struct NonescapableSelfAccessors: ~Escapable {
314314
ne
315315
}
316316

317-
@_lifetime(borrow self)
317+
@_lifetime(&self)
318318
set {
319319
ne = newValue
320320
}
@@ -326,7 +326,7 @@ struct NonescapableSelfAccessors: ~Escapable {
326326
yield ne
327327
}
328328

329-
@_lifetime(borrow self)
329+
@_lifetime(&self)
330330
_modify {
331331
yield &ne
332332
}
@@ -449,6 +449,6 @@ struct NonEscapableMutableSelf: ~Escapable {
449449
@_lifetime(copy self) // OK
450450
mutating func mutatingMethodOneParamCopy(_: NE) {}
451451

452-
@_lifetime(borrow self)
452+
@_lifetime(&self)
453453
mutating func mutatingMethodOneParamBorrow(_: NE) {}
454454
}

0 commit comments

Comments
 (0)