Skip to content

[SE-0456, -0467] Data+Span+MutableSpan #1276

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

glessard
Copy link
Contributor

Add the properties span, mutableSpan, bytes and mutableBytes to Data, as proposed in SE-0456 and SE-0467.

Addresses rdar://137711067

@glessard
Copy link
Contributor Author

@swift-ci please test

@glessard
Copy link
Contributor Author

@swift-ci please test

@glessard
Copy link
Contributor Author

The Windows test https://ci-external.swift.org/job/swift-foundation-pull-request-windows/717/ ran with swift-DEVELOPMENT-SNAPSHOT-2025-03-10-a, which is too old for this code change.

@glessard
Copy link
Contributor Author

@swift-ci please test macOS platform

@parkera parkera requested a review from jmschonfeld April 30, 2025 23:30
@@ -111,7 +111,8 @@ list(APPEND _SwiftFoundation_versions
list(APPEND _SwiftFoundation_availability_names
"FoundationPreview"
"FoundationPredicate"
"FoundationPredicateRegex")
"FoundationPredicateRegex"
"FoundationSpan")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a new availability macro?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires a 6.2 toolchain to get the symbols, and won't have the same range of deployment targets as any of the others, as far as I can tell.

@@ -49,6 +49,7 @@
#endif

internal import _FoundationCShims
import Builtin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be internal import Builtin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Builtin module is public by virtue of being inlined all over the standard library; in this file we're calling it from opaque code, so there's nothing being reexported at all.

@@ -604,6 +605,7 @@ internal final class __DataStorage : @unchecked Sendable {

@frozen
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
@_addressableForDependencies
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any ABI or source stability impact for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no source stability impact. It only changes the mangling for functions that try to establish a lifetime dependence on Data, and there are none of those until we publish these span properties.

@@ -2198,7 +2200,105 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
public func withUnsafeBytes<ResultType>(_ body: (UnsafeRawBufferPointer) throws -> ResultType) rethrows -> ResultType {
return try _representation.withUnsafeBytes(body)
}


#if compiler(>=6.2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only support building this with the 6.2 compiler in the first place.

@@ -2848,3 +2948,62 @@ extension Data : Codable {
}
}
}

#if compiler(>=6.2)
// TODO: remove once _overrideLifetime is public in the standard library
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will that happen?

Copy link
Contributor Author

@glessard glessard Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the PR: swiftlang/swift#81225
I presume that this could be in a nightly snapshot within a week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants