Skip to content

[span] express correct lifetimes for initializers #77548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 15 additions & 24 deletions stdlib/public/core/Span/RawSpan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public struct RawSpan: ~Escapable, Copyable, BitwiseCopyable {
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
@inline(__always)
//FIXME: should be @lifetime(borrow pointer) rdar://138672380
@lifetime(immortal)
@lifetime(borrow pointer)
internal init(
_unchecked pointer: borrowing UnsafeRawPointer?,
byteCount: Int
Expand Down Expand Up @@ -90,8 +89,7 @@ extension RawSpan {
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init(
_unsafeBytes buffer: borrowing UnsafeRawBufferPointer
) {
Expand All @@ -110,8 +108,7 @@ extension RawSpan {
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init(
_unsafeBytes buffer: borrowing Slice<UnsafeRawBufferPointer>
) {
Expand All @@ -128,8 +125,7 @@ extension RawSpan {
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init(
_unsafeBytes buffer: borrowing UnsafeMutableRawBufferPointer
) {
Expand All @@ -138,8 +134,7 @@ extension RawSpan {

@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init(
_unsafeBytes buffer: borrowing Slice<UnsafeMutableRawBufferPointer>
) {
Expand All @@ -158,8 +153,7 @@ extension RawSpan {
/// - byteCount: the number of initialized bytes in the span.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow pointer)
public init(
_unsafeStart pointer: borrowing UnsafeRawPointer,
byteCount: Int
Expand All @@ -178,8 +172,7 @@ extension RawSpan {
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init<T: BitwiseCopyable>(
_unsafeElements buffer: borrowing UnsafeBufferPointer<T>
) {
Expand All @@ -196,8 +189,7 @@ extension RawSpan {
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init<T: BitwiseCopyable>(
_unsafeElements buffer: borrowing Slice<UnsafeBufferPointer<T>>
) {
Expand All @@ -216,8 +208,7 @@ extension RawSpan {
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init<T: BitwiseCopyable>(
_unsafeElements buffer: borrowing UnsafeMutableBufferPointer<T>
) {
Expand All @@ -234,8 +225,7 @@ extension RawSpan {
/// - buffer: an `UnsafeRawBufferPointer` to initialized memory.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init<T: BitwiseCopyable>(
_unsafeElements buffer: borrowing Slice<UnsafeMutableBufferPointer<T>>
) {
Expand All @@ -256,8 +246,7 @@ extension RawSpan {
/// - byteCount: the number of initialized bytes in the span.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow pointer)
public init<T: BitwiseCopyable>(
_unsafeStart pointer: borrowing UnsafePointer<T>,
count: Int
Expand All @@ -275,8 +264,10 @@ extension RawSpan {
/// `RawSpan`'s lifetime and the memory it represents.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
@lifetime(span)
public init<Element: BitwiseCopyable>(_elements span: consuming Span<Element>) {
@lifetime(borrow span)
public init<Element: BitwiseCopyable>(
_elements span: borrowing Span<Element>
) {
self.init(
_unchecked: span._pointer,
byteCount: span.count &* MemoryLayout<Element>.stride
Expand Down
33 changes: 11 additions & 22 deletions stdlib/public/core/Span/Span.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public struct Span<Element: ~Copyable & ~Escapable>
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
@inline(__always)
//FIXME: should be @lifetime(borrow pointer) rdar://138672380
@lifetime(immortal)
@lifetime(borrow pointer)
internal init(
_unchecked pointer: borrowing UnsafeRawPointer?,
count: Int
Expand Down Expand Up @@ -92,8 +91,7 @@ extension Span where Element: ~Copyable {
/// - buffer: an `UnsafeBufferPointer` to initialized elements.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init(
_unsafeElements buffer: borrowing UnsafeBufferPointer<Element>
) {
Expand All @@ -116,8 +114,7 @@ extension Span where Element: ~Copyable {
/// - buffer: an `UnsafeMutableBufferPointer` to initialized elements.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init(
_unsafeElements buffer: borrowing UnsafeMutableBufferPointer<Element>
) {
Expand All @@ -136,8 +133,7 @@ extension Span where Element: ~Copyable {
/// - count: the number of initialized elements in the span.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow pointer)
public init(
_unsafeStart pointer: borrowing UnsafePointer<Element>,
count: Int
Expand All @@ -161,8 +157,7 @@ extension Span {
/// - buffer: an `UnsafeBufferPointer` to initialized elements.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init(
_unsafeElements buffer: borrowing Slice<UnsafeBufferPointer<Element>>
) {
Expand All @@ -179,8 +174,7 @@ extension Span {
/// - buffer: an `UnsafeMutableBufferPointer` to initialized elements.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init(
_unsafeElements buffer: borrowing Slice<UnsafeMutableBufferPointer<Element>>
) {
Expand All @@ -206,8 +200,7 @@ extension Span where Element: BitwiseCopyable {
/// - buffer: a buffer to initialized elements.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init(
_unsafeBytes buffer: borrowing UnsafeRawBufferPointer
) {
Expand Down Expand Up @@ -239,8 +232,7 @@ extension Span where Element: BitwiseCopyable {
/// - buffer: a buffer to initialized elements.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init(
_unsafeBytes buffer: borrowing UnsafeMutableRawBufferPointer
) {
Expand All @@ -263,8 +255,7 @@ extension Span where Element: BitwiseCopyable {
/// - byteCount: the number of initialized elements in the span.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow pointer)
public init(
_unsafeStart pointer: borrowing UnsafeRawPointer,
byteCount: Int
Expand All @@ -287,8 +278,7 @@ extension Span where Element: BitwiseCopyable {
/// - buffer: a buffer to initialized elements.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init(
_unsafeBytes buffer: borrowing Slice<UnsafeRawBufferPointer>
) {
Expand All @@ -309,8 +299,7 @@ extension Span where Element: BitwiseCopyable {
/// - buffer: a buffer to initialized elements.
@_disallowFeatureSuppression(NonescapableTypes)
@_alwaysEmitIntoClient
//FIXME: should be @lifetime(borrow <argname>) rdar://138672380
@lifetime(immortal)
@lifetime(borrow buffer)
public init(
_unsafeBytes buffer: borrowing Slice<UnsafeMutableRawBufferPointer>
) {
Expand Down