// RUN: %target-swift-frontend %s \ // RUN: -emit-sil \ // RUN: -enable-builtin-module \ // RUN: -enable-experimental-feature LifetimeDependence \ // RUN: | %FileCheck %s // REQUIRES: swift_feature_LifetimeDependence import Builtin @_unsafeNonescapableResult @lifetime(borrow source) internal func _overrideLifetime< T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable >( _ dependent: consuming T, borrowing source: borrowing U ) -> T { // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence // should be expressed by a builtin that is hidden within the function body. dependent } @_unsafeNonescapableResult @lifetime(copy source) internal func _overrideLifetime< T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable >( _ dependent: consuming T, copying source: borrowing U ) -> T { // TODO: Remove @_unsafeNonescapableResult. Instead, the unsafe dependence // should be expressed by a builtin that is hidden within the function body. dependent } struct BufferView : ~Escapable { let ptr: UnsafeRawBufferPointer // CHECK-LABEL: sil hidden @$s39explicit_lifetime_dependence_specifiers10BufferViewVyACSWcfC : $@convention(method) (UnsafeRawBufferPointer, @thin BufferView.Type) -> @lifetime(borrow 0) @owned BufferView { @lifetime(borrow ptr) init(_ ptr: UnsafeRawBufferPointer) { self.ptr = ptr } @_unsafeNonescapableResult init?(_ ptr: UnsafeRawBufferPointer, _ i: Int) { if (i % 2 == 0) { return nil } self.ptr = ptr } @lifetime(borrow ptr) init(independent ptr: UnsafeRawBufferPointer) { self.ptr = ptr } // CHECK-LABEL: sil hidden @$s39explicit_lifetime_dependence_specifiers10BufferViewVyACSW_SaySiGhtcfC : $@convention(method) (UnsafeRawBufferPointer, @guaranteed Array, @thin BufferView.Type) -> @lifetime(borrow 1) @owned BufferView { @lifetime(borrow a) init(_ ptr: UnsafeRawBufferPointer, _ a: borrowing Array) { self.ptr = ptr } // CHECK-LABEL: sil hidden @$s39explicit_lifetime_dependence_specifiers10BufferViewVyACSW_AA7WrapperVtcfC : $@convention(method) (UnsafeRawBufferPointer, @owned Wrapper, @thin BufferView.Type) -> @lifetime(copy 1) @owned BufferView { @lifetime(copy a) init(_ ptr: UnsafeRawBufferPointer, _ a: consuming Wrapper) { self.ptr = ptr } // CHECK-LABEL: sil hidden @$s39explicit_lifetime_dependence_specifiers10BufferViewVyACSW_AA7WrapperVSaySiGhtcfC : $@convention(method) (UnsafeRawBufferPointer, @owned Wrapper, @guaranteed Array, @thin BufferView.Type) -> @lifetime(copy 1, borrow 2) @owned BufferView { @lifetime(copy a, borrow b) init(_ ptr: UnsafeRawBufferPointer, _ a: consuming Wrapper, _ b: borrowing Array) { self.ptr = ptr } } struct MutableBufferView : ~Escapable, ~Copyable { let ptr: UnsafeMutableRawBufferPointer @lifetime(borrow ptr) init(_ ptr: UnsafeMutableRawBufferPointer) { self.ptr = ptr } } func testBasic() { let capacity = 4 let a = Array(0..