mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Update tests
This commit is contained in:
@@ -44,7 +44,7 @@ void lenName(int lenName, int size, int * __counted_by(lenName * size) _Nullable
|
||||
void func(int len, int * __counted_by(len) _Nullable func __noescape);
|
||||
|
||||
void *funcRenameKeyword(int len, int * __counted_by(len) _Nullable func __noescape,
|
||||
int extension __lifetimebound,
|
||||
int extension,
|
||||
int init,
|
||||
int open,
|
||||
int var,
|
||||
@@ -55,7 +55,7 @@ void *funcRenameKeyword(int len, int * __counted_by(len) _Nullable func __noesca
|
||||
int where) __attribute__((swift_name("funcRenamed(len:func:extension:init:open:var:is:as:in:guard:where:)")));
|
||||
|
||||
void *funcRenameKeywordAnonymous(int len, int * __counted_by(len) _Nullable __noescape,
|
||||
int __lifetimebound,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
int,
|
||||
|
||||
@@ -38,13 +38,11 @@ import CountedByNoEscapeClang
|
||||
|
||||
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop
|
||||
// CHECK-NEXT: @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
|
||||
// CHECK-NEXT: @_lifetime(borrow extension)
|
||||
// CHECK-NEXT: @_lifetime(func: copy func)
|
||||
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func funcRenamed(func: inout MutableSpan<Int32>?, extension: Int32, init: Int32, open: Int32, var: Int32, is: Int32, as: Int32, in: Int32, guard: Int32, where: Int32) -> UnsafeMutableRawPointer!
|
||||
|
||||
// CHECK-NEXT: /// This is an auto-generated wrapper for safer interop
|
||||
// CHECK-NEXT: @available(visionOS 1.0, tvOS 12.2, watchOS 5.2, iOS 12.2, macOS 10.14.4, *)
|
||||
// CHECK-NEXT: @_lifetime(borrow _funcRenamedAnon_param2)
|
||||
// CHECK-NEXT: @_lifetime(_funcRenamedAnon_param1: copy _funcRenamedAnon_param1)
|
||||
// CHECK-NEXT: @_alwaysEmitIntoClient @_disfavoredOverload public func funcRenamedAnon(func _funcRenamedAnon_param1: inout MutableSpan<Int32>?, extension _funcRenamedAnon_param2: Int32, init _funcRenamedAnon_param3: Int32, open _funcRenamedAnon_param4: Int32, var _funcRenamedAnon_param5: Int32, is _funcRenamedAnon_param6: Int32, as _funcRenamedAnon_param7: Int32, in _funcRenamedAnon_param8: Int32, guard _funcRenamedAnon_param9: Int32, where _funcRenamedAnon_param10: Int32) -> UnsafeMutableRawPointer!
|
||||
|
||||
|
||||
@@ -41,16 +41,16 @@ func mutReturn() -> UnsafeMutablePointer<CInt> {}
|
||||
func mutOptReturn() -> UnsafeMutablePointer<CInt>? {}
|
||||
|
||||
|
||||
@_SwiftifyImport(.countedBy(pointer: .param(1), count: "37"), .lifetimeDependence(dependsOn: .param(1), pointer: .return, type: .copy))
|
||||
@_SwiftifyImport(.countedBy(pointer: .param(1), count: "37"))
|
||||
func noescape(_ ptr: UnsafePointer<CInt>) -> UnsafePointer<CInt> {}
|
||||
|
||||
@_SwiftifyImport(.countedBy(pointer: .param(1), count: "37"), .lifetimeDependence(dependsOn: .param(1), pointer: .return, type: .copy))
|
||||
@_SwiftifyImport(.countedBy(pointer: .param(1), count: "37"))
|
||||
func noescapeOpt(_ ptr: UnsafePointer<CInt>?) -> UnsafePointer<CInt>? {}
|
||||
|
||||
@_SwiftifyImport(.countedBy(pointer: .param(1), count: "37"), .lifetimeDependence(dependsOn: .param(1), pointer: .return, type: .copy))
|
||||
@_SwiftifyImport(.countedBy(pointer: .param(1), count: "37"))
|
||||
func noescapeMut(_ ptr: UnsafeMutablePointer<CInt>) -> UnsafeMutablePointer<CInt> {}
|
||||
|
||||
@_SwiftifyImport(.countedBy(pointer: .param(1), count: "37"), .lifetimeDependence(dependsOn: .param(1), pointer: .return, type: .copy))
|
||||
@_SwiftifyImport(.countedBy(pointer: .param(1), count: "37"))
|
||||
func noescapeMutOpt(_ ptr: UnsafeMutablePointer<CInt>?) -> UnsafeMutablePointer<CInt>? {}
|
||||
|
||||
// CHECK: @_alwaysEmitIntoClient @_disfavoredOverload
|
||||
@@ -100,15 +100,13 @@ func noescapeMutOpt(_ ptr: UnsafeMutablePointer<CInt>?) -> UnsafeMutablePointer<
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: }
|
||||
|
||||
// CHECK: @_alwaysEmitIntoClient @_lifetime(copy ptr) @_disfavoredOverload
|
||||
// CHECK-NEXT: func noescape(_ ptr: Span<CInt>) -> UnsafePointer<CInt> {
|
||||
// CHECK-NEXT: let _ptrCount = ptr.count
|
||||
// CHECK: @_alwaysEmitIntoClient @_disfavoredOverload
|
||||
// CHECK-NEXT: func noescape(_ ptr: UnsafeBufferPointer<CInt>) -> UnsafePointer<CInt> {
|
||||
// CHECK-NEXT: let _ptrCount = unsafe ptr.count
|
||||
// CHECK-NEXT: if _ptrCount != 37 {
|
||||
// CHECK-NEXT: fatalError("bounds check failure in noescape: expected \(37) but got \(_ptrCount)")
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: return unsafe ptr.withUnsafeBufferPointer { _ptrPtr in
|
||||
// CHECK-NEXT: return unsafe noescape(_ptrPtr.baseAddress!)
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: return unsafe noescape(ptr.baseAddress!)
|
||||
// CHECK-NEXT: }
|
||||
|
||||
// CHECK: @_alwaysEmitIntoClient @_disfavoredOverload
|
||||
@@ -128,23 +126,6 @@ func noescapeMutOpt(_ ptr: UnsafeMutablePointer<CInt>?) -> UnsafeMutablePointer<
|
||||
// CHECK-NEXT: }()
|
||||
// CHECK-NEXT: }
|
||||
|
||||
// CHECK: @_alwaysEmitIntoClient @_lifetime(copy ptr) @_disfavoredOverload
|
||||
// CHECK-NEXT: func noescapeOpt(_ ptr: Span<CInt>?) -> UnsafePointer<CInt>? {
|
||||
// CHECK-NEXT: let _ptrCount = ptr?.count ?? 0
|
||||
// CHECK-NEXT: if _ptrCount != 37 {
|
||||
// CHECK-NEXT: fatalError("bounds check failure in noescapeOpt: expected \(37) but got \(_ptrCount)")
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: return { () in
|
||||
// CHECK-NEXT: return if ptr == nil {
|
||||
// CHECK-NEXT: unsafe noescapeOpt(nil)
|
||||
// CHECK-NEXT: } else {
|
||||
// CHECK-NEXT: unsafe ptr!.withUnsafeBufferPointer { _ptrPtr in
|
||||
// CHECK-NEXT: return unsafe noescapeOpt(_ptrPtr.baseAddress)
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: }()
|
||||
// CHECK-NEXT: }
|
||||
|
||||
// CHECK: @_alwaysEmitIntoClient @_lifetime(ptr: copy ptr) @_disfavoredOverload
|
||||
// CHECK-NEXT: func noescapeMut(_ ptr: inout MutableSpan<CInt>) {
|
||||
// CHECK-NEXT: let _ptrCount = ptr.count
|
||||
@@ -156,49 +137,22 @@ func noescapeMutOpt(_ ptr: UnsafeMutablePointer<CInt>?) -> UnsafeMutablePointer<
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: }
|
||||
|
||||
// CHECK: @_alwaysEmitIntoClient @_lifetime(copy ptr) @_lifetime(ptr: copy ptr) @_disfavoredOverload
|
||||
// CHECK-NEXT: func noescapeMut(_ ptr: inout MutableSpan<CInt>) -> UnsafeMutablePointer<CInt> {
|
||||
// CHECK-NEXT: let _ptrCount = ptr.count
|
||||
// CHECK: @_alwaysEmitIntoClient @_disfavoredOverload
|
||||
// CHECK-NEXT: func noescapeMut(_ ptr: UnsafeMutableBufferPointer<CInt>) -> UnsafeMutablePointer<CInt> {
|
||||
// CHECK-NEXT: let _ptrCount = unsafe ptr.count
|
||||
// CHECK-NEXT: if _ptrCount != 37 {
|
||||
// CHECK-NEXT: fatalError("bounds check failure in noescapeMut: expected \(37) but got \(_ptrCount)")
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: return unsafe ptr.withUnsafeMutableBufferPointer { _ptrPtr in
|
||||
// CHECK-NEXT: return unsafe noescapeMut(_ptrPtr.baseAddress!)
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: return unsafe noescapeMut(ptr.baseAddress!)
|
||||
// CHECK-NEXT: }
|
||||
|
||||
// CHECK: @_alwaysEmitIntoClient @_lifetime(ptr: copy ptr) @_disfavoredOverload
|
||||
// CHECK-NEXT: func noescapeMutOpt(_ ptr: inout MutableSpan<CInt>?) {
|
||||
// CHECK-NEXT: let _ptrCount = ptr?.count ?? 0
|
||||
// CHECK: @_alwaysEmitIntoClient @_disfavoredOverload
|
||||
// CHECK-NEXT: func noescapeMutOpt(_ ptr: UnsafeMutableBufferPointer<CInt>?) -> UnsafeMutablePointer<CInt>? {
|
||||
// CHECK-NEXT: let _ptrCount = unsafe ptr?.count ?? 0
|
||||
// CHECK-NEXT: if _ptrCount != 37 {
|
||||
// CHECK-NEXT: fatalError("bounds check failure in noescapeMutOpt: expected \(37) but got \(_ptrCount)")
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: return { () in
|
||||
// CHECK-NEXT: return if ptr == nil {
|
||||
// CHECK-NEXT: unsafe noescapeMutOpt(nil)
|
||||
// CHECK-NEXT: } else {
|
||||
// CHECK-NEXT: unsafe ptr!.withUnsafeMutableBufferPointer { _ptrPtr in
|
||||
// CHECK-NEXT: return unsafe noescapeMutOpt(_ptrPtr.baseAddress)
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: }()
|
||||
// CHECK-NEXT: }
|
||||
|
||||
// CHECK: @_alwaysEmitIntoClient @_lifetime(copy ptr) @_lifetime(ptr: copy ptr) @_disfavoredOverload
|
||||
// CHECK-NEXT: func noescapeMutOpt(_ ptr: inout MutableSpan<CInt>?) -> UnsafeMutablePointer<CInt>? {
|
||||
// CHECK-NEXT: let _ptrCount = ptr?.count ?? 0
|
||||
// CHECK-NEXT: if _ptrCount != 37 {
|
||||
// CHECK-NEXT: fatalError("bounds check failure in noescapeMutOpt: expected \(37) but got \(_ptrCount)")
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: return { () in
|
||||
// CHECK-NEXT: return if ptr == nil {
|
||||
// CHECK-NEXT: unsafe noescapeMutOpt(nil)
|
||||
// CHECK-NEXT: } else {
|
||||
// CHECK-NEXT: unsafe ptr!.withUnsafeMutableBufferPointer { _ptrPtr in
|
||||
// CHECK-NEXT: return unsafe noescapeMutOpt(_ptrPtr.baseAddress)
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: }
|
||||
// CHECK-NEXT: }()
|
||||
// CHECK-NEXT: return unsafe noescapeMutOpt(ptr?.baseAddress)
|
||||
// CHECK-NEXT: }
|
||||
|
||||
// CHECK: @_alwaysEmitIntoClient @_disfavoredOverload
|
||||
|
||||
@@ -240,12 +240,11 @@ extension MutableSpan where Element: ~Copyable {
|
||||
/// - Complexity: O(1)
|
||||
@_alwaysEmitIntoClient
|
||||
public subscript(_ position: Index) -> Element {
|
||||
@_lifetime(borrow self)
|
||||
_read {
|
||||
precondition(indices.contains(position), "index out of bounds")
|
||||
yield self[unchecked: position]
|
||||
}
|
||||
@_lifetime(&self)
|
||||
@_lifetime(self: copy self)
|
||||
_modify {
|
||||
precondition(indices.contains(position), "index out of bounds")
|
||||
yield &self[unchecked: position]
|
||||
|
||||
@@ -627,7 +627,6 @@ func test(arg: inout AddressableInt) -> Span<Int> {
|
||||
}
|
||||
|
||||
// unsafeAddress generates an addressable value with a local scope.
|
||||
@_lifetime(borrow arg)
|
||||
func testBorrowedAddressableInt(arg: Holder) -> Int {
|
||||
let span = arg.addressableInt.span()
|
||||
return span[0]
|
||||
|
||||
@@ -169,7 +169,7 @@ public struct NoncopyableImplicitAccessors : ~Copyable & ~Escapable {
|
||||
@_lifetime(borrow self)
|
||||
get { ne }
|
||||
|
||||
@_lifetime(&self)
|
||||
@_lifetime(self: copy newValue)
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -315,14 +315,3 @@ func inoutToImmortal(_ s: inout RawSpan) {
|
||||
s = _overrideLifetime(tmp, borrowing: ())
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// Dependence on non-Copyable values
|
||||
// =============================================================================
|
||||
|
||||
@_lifetime(immortal)
|
||||
func dependOnNonCopyable() -> NCBuffer {
|
||||
let buffer = NCBuffer()
|
||||
let count = buffer.bytes.count
|
||||
_ = count
|
||||
return buffer // expected-error {{noncopyable 'buffer' cannot be consumed when captured by an escaping closure or borrowed by a non-Escapable type}}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public struct NoncopyableImplicitAccessors : ~Copyable & ~Escapable {
|
||||
@_lifetime(borrow self)
|
||||
get { ne }
|
||||
|
||||
@_lifetime(&self)
|
||||
@_lifetime(self: copy newValue)
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
|
||||
@@ -331,7 +331,6 @@ struct TrivialAccessors {
|
||||
NEImmortal()
|
||||
}
|
||||
|
||||
@_lifetime(&self)
|
||||
set { // OK (no dependency)
|
||||
}
|
||||
}
|
||||
@@ -385,7 +384,7 @@ struct NonescapableSelfAccessors: ~Escapable {
|
||||
ne
|
||||
}
|
||||
|
||||
@_lifetime(self) // expected-error{{cannot infer the lifetime dependence scope on a mutating method with a ~Escapable parameter, specify '@_lifetime(borrow self)' or '@_lifetime(copy self)'}}
|
||||
@_lifetime(self: newValue) // expected-error{{cannot infer the lifetime dependence scope on a mutating method with a ~Escapable parameter, specify '@_lifetime(borrow newValue)' or '@_lifetime(copy newValue)'}}
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -409,7 +408,7 @@ struct NonescapableSelfAccessors: ~Escapable {
|
||||
ne
|
||||
}
|
||||
|
||||
@_lifetime(copy self)
|
||||
@_lifetime(self: copy newValue)
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -433,7 +432,7 @@ struct NonescapableSelfAccessors: ~Escapable {
|
||||
ne
|
||||
}
|
||||
|
||||
@_lifetime(&self)
|
||||
@_lifetime(self: borrow newValue)
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -482,7 +481,7 @@ struct NoncopyableSelfAccessors: ~Copyable & ~Escapable {
|
||||
ne
|
||||
}
|
||||
|
||||
@_lifetime(self) // expected-error{{cannot infer the lifetime dependence scope on a mutating method with a ~Escapable parameter, specify '@_lifetime(borrow self)' or '@_lifetime(copy self)'}}
|
||||
@_lifetime(self: newValue) // expected-error{{cannot infer the lifetime dependence scope on a mutating method with a ~Escapable parameter, specify '@_lifetime(borrow newValue)' or '@_lifetime(copy newValue)'}}
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -506,7 +505,7 @@ struct NoncopyableSelfAccessors: ~Copyable & ~Escapable {
|
||||
ne
|
||||
}
|
||||
|
||||
@_lifetime(copy self)
|
||||
@_lifetime(self: copy newValue)
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -530,7 +529,7 @@ struct NoncopyableSelfAccessors: ~Copyable & ~Escapable {
|
||||
ne
|
||||
}
|
||||
|
||||
@_lifetime(&self)
|
||||
@_lifetime(self: copy newValue)
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -574,10 +573,10 @@ struct NonEscapableMutableSelf: ~Escapable {
|
||||
@_lifetime(self: self) // expected-error{{cannot infer the lifetime dependence scope on a mutating method with a ~Escapable parameter, specify '@_lifetime(borrow self)' or '@_lifetime(copy self)'}}
|
||||
mutating func mutatingMethodOneParamLifetime(_: NE) {}
|
||||
|
||||
@_lifetime(copy self) // OK
|
||||
@_lifetime(self: copy self) // OK
|
||||
mutating func mutatingMethodOneParamCopy(_: NE) {}
|
||||
|
||||
@_lifetime(&self)
|
||||
@_lifetime(self: copy self) // OK
|
||||
mutating func mutatingMethodOneParamBorrow(_: NE) {}
|
||||
}
|
||||
|
||||
|
||||
@@ -266,7 +266,7 @@ struct NonescapableSelfAccessors: ~Escapable {
|
||||
ne
|
||||
}
|
||||
|
||||
@_lifetime(self) // OK
|
||||
@_lifetime(self: newValue) // OK
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -290,7 +290,7 @@ struct NonescapableSelfAccessors: ~Escapable {
|
||||
ne
|
||||
}
|
||||
|
||||
@_lifetime(copy self)
|
||||
@_lifetime(self: copy newValue)
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -314,7 +314,7 @@ struct NonescapableSelfAccessors: ~Escapable {
|
||||
ne
|
||||
}
|
||||
|
||||
@_lifetime(&self)
|
||||
@_lifetime(self: borrow newValue)
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -363,7 +363,7 @@ struct NoncopyableSelfAccessors: ~Copyable & ~Escapable {
|
||||
ne
|
||||
}
|
||||
|
||||
@_lifetime(self) // OK
|
||||
@_lifetime(self: newValue) // OK
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -387,7 +387,7 @@ struct NoncopyableSelfAccessors: ~Copyable & ~Escapable {
|
||||
ne
|
||||
}
|
||||
|
||||
@_lifetime(copy self)
|
||||
@_lifetime(self: copy self)
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -411,7 +411,7 @@ struct NoncopyableSelfAccessors: ~Copyable & ~Escapable {
|
||||
ne
|
||||
}
|
||||
|
||||
@_lifetime(&self)
|
||||
@_lifetime(self: borrow newValue)
|
||||
set {
|
||||
ne = newValue
|
||||
}
|
||||
@@ -446,9 +446,9 @@ struct NonEscapableMutableSelf: ~Escapable {
|
||||
@_lifetime(self: self) // OK
|
||||
mutating func mutatingMethodOneParamLifetime(_: NE) {}
|
||||
|
||||
@_lifetime(copy self) // OK
|
||||
@_lifetime(self: copy self) // OK
|
||||
mutating func mutatingMethodOneParamCopy(_: NE) {}
|
||||
|
||||
@_lifetime(&self)
|
||||
@_lifetime(self: copy self) // OK
|
||||
mutating func mutatingMethodOneParamBorrow(_: NE) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user