Skip to content

[stdlib] improve mutableSpan accessor declarations #82517

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 5 commits into from
Jun 27, 2025
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
2 changes: 1 addition & 1 deletion stdlib/public/core/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1744,9 +1744,9 @@ extension Array {
}

@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public var mutableSpan: MutableSpan<Element> {
@lifetime(&self)
@_alwaysEmitIntoClient
mutating get {
// _makeMutableAndUnique*() inserts begin_cow_mutation.
// LifetimeDependence analysis inserts call to end_cow_mutation_addr since we cannot schedule it in the stdlib for mutableSpan property.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ArraySlice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1301,9 +1301,9 @@ extension ArraySlice {
}

@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public var mutableSpan: MutableSpan<Element> {
@lifetime(&self)
@_alwaysEmitIntoClient
mutating get {
// _makeMutableAndUnique*() inserts begin_cow_mutation.
// LifetimeDependence analysis inserts call to end_cow_mutation_addr since we cannot schedule it in the stdlib for mutableSpan property.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/CollectionOfOne.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ extension CollectionOfOne {
}

@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public var mutableSpan: MutableSpan<Element> {
@lifetime(&self)
@_alwaysEmitIntoClient
mutating get {
let pointer = unsafe UnsafeMutablePointer<Element>(
Builtin.addressOfBorrow(self)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ContiguousArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1243,9 +1243,9 @@ extension ContiguousArray {
}

@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public var mutableSpan: MutableSpan<Element> {
@lifetime(&self)
@_alwaysEmitIntoClient
mutating get {
// _makeMutableAndUnique*() inserts begin_cow_mutation.
// LifetimeDependence analysis inserts call to end_cow_mutation_addr since we cannot schedule it in the stdlib for mutableSpan property.
Expand Down
9 changes: 5 additions & 4 deletions stdlib/public/core/UnsafeBufferPointer.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -575,21 +575,22 @@ extension Unsafe${Mutable}BufferPointer where Element: ~Copyable {

@unsafe
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public var span: Span<Element> {
@lifetime(borrow self)
@_alwaysEmitIntoClient
@_transparent
get {
let span = unsafe Span(_unsafeElements: self)
return unsafe _overrideLifetime(span, borrowing: self)
unsafe Span(_unsafeElements: self)
}
}
%if Mutable:

@unsafe
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public var mutableSpan: MutableSpan<Element> {
@lifetime(borrow self)
@_alwaysEmitIntoClient
@_transparent
get {
unsafe MutableSpan(_unsafeElements: self)
}
Expand Down
9 changes: 5 additions & 4 deletions stdlib/public/core/UnsafeRawBufferPointer.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1164,9 +1164,10 @@ extension Unsafe${Mutable}RawBufferPointer {

@unsafe
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public var mutableBytes: MutableRawSpan {
@lifetime(borrow self)
@_alwaysEmitIntoClient
@_transparent
get {
unsafe MutableRawSpan(_unsafeBytes: self)
}
Expand All @@ -1184,12 +1185,12 @@ extension Unsafe${Mutable}RawBufferPointer {

@unsafe
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public var bytes: RawSpan {
@lifetime(borrow self)
@_alwaysEmitIntoClient
@_transparent
get {
let span = unsafe RawSpan(_unsafeBytes: self)
return unsafe _overrideLifetime(span, borrowing: self)
unsafe RawSpan(_unsafeBytes: self)
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions test/abi/macOS/arm64/stdlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -928,14 +928,6 @@ Added: _$ss14MutableRawSpanVN
Added: _$sSS8UTF8ViewV4spans4SpanVys5UInt8VGvg
Added: _$sSs8UTF8ViewV4spans4SpanVys5UInt8VGvg

// SE-0467 mutableSpan properties
Added: _$sSa11mutableSpans07MutableB0VyxGvr
Added: _$ss10ArraySliceV11mutableSpans07MutableD0VyxGvr
Added: _$ss15ContiguousArrayV11mutableSpans07MutableD0VyxGvr
Added: _$ss15CollectionOfOneV11mutableSpans07MutableE0VyxGvr
Added: _$sSrsRi_zrlE11mutableSpans07MutableB0VyxGvr
Added: _$sSw12mutableBytess14MutableRawSpanVvr

// _SwiftifyInfo enum for _SwiftifyImports macro
Added: _$ss13_SwiftifyExprO5paramyABSicABmFWC
Added: _$ss13_SwiftifyExprO6returnyA2BmFWC
Expand Down
8 changes: 0 additions & 8 deletions test/abi/macOS/x86_64/stdlib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -929,14 +929,6 @@ Added: _$ss14MutableRawSpanVN
Added: _$sSS8UTF8ViewV4spans4SpanVys5UInt8VGvg
Added: _$sSs8UTF8ViewV4spans4SpanVys5UInt8VGvg

// SE-0467 mutableSpan properties
Added: _$sSa11mutableSpans07MutableB0VyxGvr
Added: _$ss10ArraySliceV11mutableSpans07MutableD0VyxGvr
Added: _$ss15ContiguousArrayV11mutableSpans07MutableD0VyxGvr
Added: _$ss15CollectionOfOneV11mutableSpans07MutableE0VyxGvr
Added: _$sSrsRi_zrlE11mutableSpans07MutableB0VyxGvr
Added: _$sSw12mutableBytess14MutableRawSpanVvr

// _SwiftifyInfo enum for _SwiftifyImports macro
Added: _$ss13_SwiftifyExprO5paramyABSicABmFWC
Added: _$ss13_SwiftifyExprO6returnyA2BmFWC
Expand Down