mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[NFC] Update tests and diagnostics
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
public struct AnotherView : ~Escapable {
|
||||
@usableFromInline let _ptr: UnsafeRawBufferPointer
|
||||
@usableFromInline let _count: Int
|
||||
@_lifetime(borrow ptr)
|
||||
internal init(_ ptr: UnsafeRawBufferPointer, _ count: Int) {
|
||||
self._ptr = ptr
|
||||
self._count = count
|
||||
}
|
||||
}
|
||||
|
||||
public struct BufferView : ~Escapable {
|
||||
@usableFromInline let _ptr: UnsafeRawBufferPointer
|
||||
@usableFromInline let _count: Int
|
||||
@usableFromInline
|
||||
@_lifetime(borrow ptr)
|
||||
internal init(_ ptr: UnsafeRawBufferPointer, _ count: Int) {
|
||||
self._ptr = ptr
|
||||
self._count = count
|
||||
}
|
||||
|
||||
@inlinable
|
||||
@_lifetime(borrow a)
|
||||
internal init(_ ptr: UnsafeRawBufferPointer, _ a: borrowing Array<Int>) {
|
||||
let bv = BufferView(ptr, a.count)
|
||||
self = _overrideLifetime(bv, borrowing: a)
|
||||
}
|
||||
@inlinable
|
||||
@_lifetime(copy a)
|
||||
internal init(_ ptr: UnsafeRawBufferPointer, _ a: consuming AnotherView) {
|
||||
let bv = BufferView(ptr, a._count)
|
||||
self = _overrideLifetime(bv, copying: a)
|
||||
}
|
||||
}
|
||||
|
||||
@inlinable
|
||||
@_lifetime(copy x)
|
||||
public func derive(_ x: consuming BufferView) -> BufferView {
|
||||
let pointer = x._ptr
|
||||
let bv = BufferView(pointer, x._count)
|
||||
return _overrideLifetime(bv, copying: x)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func use(_ x: consuming BufferView) {}
|
||||
|
||||
@inlinable
|
||||
@_lifetime(copy view)
|
||||
public func consumeAndCreate(_ view: consuming BufferView) -> BufferView {
|
||||
let pointer = view._ptr
|
||||
let bv = BufferView(pointer, view._count)
|
||||
return _overrideLifetime(bv, copying: view)
|
||||
}
|
||||
|
||||
// FIXME: Filed rdar://150398673 ([nonescapable] allocbox-to-stack fails causing lifetime diagnostics to fail)
|
||||
// Remove _overrideLifetime when this is fixed.
|
||||
@inlinable
|
||||
@_lifetime(copy this, copy that)
|
||||
public func deriveThisOrThat(_ this: consuming BufferView, _ that: consuming BufferView) -> BufferView {
|
||||
if (Int.random(in: 1..<100) == 0) {
|
||||
let thisView = BufferView(this._ptr, this._count)
|
||||
return _overrideLifetime(thisView, copying: this)
|
||||
}
|
||||
let thatView = BufferView(that._ptr, that._count)
|
||||
return _overrideLifetime(thatView, copying: that)
|
||||
}
|
||||
|
||||
public struct Container {
|
||||
var buffer: UnsafeRawBufferPointer
|
||||
var object: AnyObject
|
||||
}
|
||||
|
||||
extension Container {
|
||||
public var storage: BufferView {
|
||||
get {
|
||||
let view = BufferView(buffer, 1)
|
||||
return _overrideLifetime(view, borrowing: self)
|
||||
}
|
||||
}
|
||||
}
|
||||
112
test/ModuleInterface/lifetime_underscored_dependence_test.swift
Normal file
112
test/ModuleInterface/lifetime_underscored_dependence_test.swift
Normal file
@@ -0,0 +1,112 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
|
||||
// RUN: %target-swift-frontend -swift-version 5 -enable-library-evolution -emit-module \
|
||||
// RUN: -enable-experimental-feature Lifetimes \
|
||||
// RUN: -enable-experimental-feature Lifetimes \
|
||||
// RUN: -o %t/lifetime_underscored_dependence.swiftmodule \
|
||||
// RUN: -emit-module-interface-path %t/lifetime_underscored_dependence.swiftinterface \
|
||||
// RUN: %S/Inputs/lifetime_underscored_dependence.swift
|
||||
|
||||
// Check the interfaces
|
||||
|
||||
// RUN: %FileCheck %s < %t/lifetime_underscored_dependence.swiftinterface
|
||||
|
||||
// See if we can compile a module through just the interface and typecheck using it.
|
||||
|
||||
// RUN: %target-swift-frontend -compile-module-from-interface \
|
||||
// RUN: -enable-experimental-feature Lifetimes \
|
||||
// RUN: %t/lifetime_underscored_dependence.swiftinterface -o %t/lifetime_underscored_dependence.swiftmodule
|
||||
|
||||
// RUN: %target-swift-frontend -typecheck -I %t %s \
|
||||
// RUN: -enable-experimental-feature Lifetimes
|
||||
|
||||
// REQUIRES: swift_feature_Lifetimes
|
||||
|
||||
import lifetime_underscored_dependence
|
||||
// CHECK: #if compiler(>=5.3) && $Lifetimes
|
||||
// CHECK: @_lifetime(borrow a)
|
||||
// CHECK: @inlinable internal init(_ ptr: Swift.UnsafeRawBufferPointer, _ a: borrowing Swift.Array<Swift.Int>) {
|
||||
// CHECK: let bv = BufferView(ptr, a.count)
|
||||
// CHECK: self = _overrideLifetime(bv, borrowing: a)
|
||||
// CHECK: }
|
||||
// CHECK: #else
|
||||
// CHECK: @lifetime(borrow a)
|
||||
// CHECK: @inlinable internal init(_ ptr: Swift.UnsafeRawBufferPointer, _ a: borrowing Swift.Array<Swift.Int>) {
|
||||
// CHECK: let bv = BufferView(ptr, a.count)
|
||||
// CHECK: self = _overrideLifetime(bv, borrowing: a)
|
||||
// CHECK: }
|
||||
// CHECK: #endif
|
||||
|
||||
// CHECK: #if compiler(>=5.3) && $Lifetimes
|
||||
// CHECK: @_lifetime(copy a)
|
||||
// CHECK: @inlinable internal init(_ ptr: Swift.UnsafeRawBufferPointer, _ a: consuming lifetime_underscored_dependence.AnotherView) {
|
||||
// CHECK: let bv = BufferView(ptr, a._count)
|
||||
// CHECK: self = _overrideLifetime(bv, copying: a)
|
||||
// CHECK: }
|
||||
// CHECK: #else
|
||||
// CHECK: @lifetime(copy a)
|
||||
// CHECK: @inlinable internal init(_ ptr: Swift.UnsafeRawBufferPointer, _ a: consuming lifetime_underscored_dependence.AnotherView) {
|
||||
// CHECK: let bv = BufferView(ptr, a._count)
|
||||
// CHECK: self = _overrideLifetime(bv, copying: a)
|
||||
// CHECK: }
|
||||
// CHECK: #endif
|
||||
|
||||
// CHECK:#if compiler(>=5.3) && $Lifetimes
|
||||
// CHECK:@_lifetime(copy x)
|
||||
// CHECK:@inlinable public func derive(_ x: consuming lifetime_underscored_dependence.BufferView) -> lifetime_underscored_dependence.BufferView {
|
||||
// CHECK: let pointer = x._ptr
|
||||
// CHECK: let bv = BufferView(pointer, x._count)
|
||||
// CHECK: return _overrideLifetime(bv, copying: x)
|
||||
// CHECK:}
|
||||
// CHECK:#else
|
||||
// CHECK:@lifetime(copy x)
|
||||
// CHECK:@inlinable public func derive(_ x: consuming lifetime_underscored_dependence.BufferView) -> lifetime_underscored_dependence.BufferView {
|
||||
// CHECK: let pointer = x._ptr
|
||||
// CHECK: let bv = BufferView(pointer, x._count)
|
||||
// CHECK: return _overrideLifetime(bv, copying: x)
|
||||
// CHECK:}
|
||||
// CHECK:#endif
|
||||
|
||||
// CHECK:#if compiler(>=5.3) && $Lifetimes
|
||||
// CHECK:@_lifetime(copy view)
|
||||
// CHECK:@inlinable public func consumeAndCreate(_ view: consuming lifetime_underscored_dependence.BufferView) -> lifetime_underscored_dependence.BufferView {
|
||||
// CHECK: let pointer = view._ptr
|
||||
// CHECK: let bv = BufferView(pointer, view._count)
|
||||
// CHECK: return _overrideLifetime(bv, copying: view)
|
||||
// CHECK:}
|
||||
// CHECK:#else
|
||||
// CHECK:@lifetime(copy view)
|
||||
// CHECK:@inlinable public func consumeAndCreate(_ view: consuming lifetime_underscored_dependence.BufferView) -> lifetime_underscored_dependence.BufferView {
|
||||
// CHECK: let pointer = view._ptr
|
||||
// CHECK: let bv = BufferView(pointer, view._count)
|
||||
// CHECK: return _overrideLifetime(bv, copying: view)
|
||||
// CHECK:}
|
||||
// CHECK:#endif
|
||||
|
||||
// CHECK:#if compiler(>=5.3) && $Lifetimes
|
||||
// CHECK:@_lifetime(copy this, copy that)
|
||||
// CHECK:@inlinable public func deriveThisOrThat(_ this: consuming lifetime_underscored_dependence.BufferView, _ that: consuming lifetime_underscored_dependence.BufferView) -> lifetime_underscored_dependence.BufferView {
|
||||
// CHECK: if (Int.random(in: 1..<100) == 0) {
|
||||
// CHECK: let thisView = BufferView(this._ptr, this._count)
|
||||
// CHECK: return _overrideLifetime(thisView, copying: this)
|
||||
// CHECK: }
|
||||
// CHECK: let thatView = BufferView(that._ptr, that._count)
|
||||
// CHECK: return _overrideLifetime(thatView, copying: that)
|
||||
// CHECK:}
|
||||
// CHECK:#else
|
||||
// CHECK:@lifetime(copy this, copy that)
|
||||
// CHECK:@inlinable public func deriveThisOrThat(_ this: consuming lifetime_underscored_dependence.BufferView, _ that: consuming lifetime_underscored_dependence.BufferView) -> lifetime_underscored_dependence.BufferView {
|
||||
// CHECK: if (Int.random(in: 1..<100) == 0) {
|
||||
// CHECK: let thisView = BufferView(this._ptr, this._count)
|
||||
// CHECK: return _overrideLifetime(thisView, copying: this)
|
||||
// CHECK: }
|
||||
// CHECK: let thatView = BufferView(that._ptr, that._count)
|
||||
// CHECK: return _overrideLifetime(thatView, copying: that)
|
||||
// CHECK:}
|
||||
// CHECK:#endif
|
||||
|
||||
// Check that an implicitly dependent variable accessor is guarded by LifetimeDependence.
|
||||
//
|
||||
// CHECK: extension lifetime_underscored_dependence.Container {
|
||||
// CHECK-NEXT: #if compiler(>=5.3) && $NonescapableTypes && $LifetimeDependence
|
||||
// CHECK-NEXT: public var storage: lifetime_underscored_dependence.BufferView {
|
||||
Reference in New Issue
Block a user