Skip to content

Commit 6714641

Browse files
authored
Adjust availability and inlinability of span projections (#1400)
* Remove re-definitions of `_overrideLifetime()` - These have now propagated to become public in all the relevant sources of the stdlib. * Update availability of `Span` projections * Adjust availability of `Span` tests * Make adjustments to mitigate the ABI break * Remove the “FoundationSpan” availability name. * Remove availabilities older than the test deployment target * Availability and symbol adjustments - adjust visionOS availability
1 parent 16856cb commit 6714641

File tree

4 files changed

+22
-75
lines changed

4 files changed

+22
-75
lines changed

CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ list(APPEND CMAKE_MODULE_PATH ${SwiftFoundation_SOURCE_DIR}/cmake/modules)
9494

9595
# Availability Macros (only applies to FoundationEssentials and FoundationInternationalization)
9696
set(_SwiftFoundation_BaseAvailability "macOS 15, iOS 18, tvOS 18, watchOS 11")
97-
set(_SwiftFoundation_macOS26Availability "macOS 26, iOS 26, tvOS 26, watchOS 26")
9897
set(_SwiftFoundation_FutureAvailability "macOS 10000, iOS 10000, tvOS 10000, watchOS 10000")
9998

10099
# All versions to define for each availability name
@@ -106,13 +105,11 @@ list(APPEND _SwiftFoundation_versions
106105

107106
# Each availability name to define
108107
list(APPEND _SwiftFoundation_availability_names
109-
"FoundationPreview"
110-
"FoundationSpan")
108+
"FoundationPreview")
111109

112110
# The aligned availability for each name (in the same order)
113111
list(APPEND _SwiftFoundation_availability_releases
114-
${_SwiftFoundation_BaseAvailability}
115-
${_SwiftFoundation_macOS26Availability})
112+
${_SwiftFoundation_BaseAvailability})
116113

117114
foreach(version ${_SwiftFoundation_versions})
118115
foreach(name release IN ZIP_LISTS _SwiftFoundation_availability_names _SwiftFoundation_availability_releases)

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import CompilerPluginSupport
88

99
let availabilityTags: [_Availability] = [
1010
_Availability("FoundationPreview"), // Default FoundationPreview availability
11-
_Availability("FoundationSpan", availability: .macOS26), // Availability of Span types
1211
]
1312
let versionNumbers = ["6.0.2", "6.1", "6.2"]
1413

Sources/FoundationEssentials/Data/Data.swift

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,8 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
22032203
return try _representation.withUnsafeBytes(body)
22042204
}
22052205

2206-
@available(FoundationSpan 6.2, *)
2206+
@available(macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2, visionOS 1.1, *)
2207+
@_alwaysEmitIntoClient
22072208
public var bytes: RawSpan {
22082209
@lifetime(borrow self)
22092210
borrowing get {
@@ -2230,7 +2231,8 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
22302231
}
22312232
}
22322233

2233-
@available(FoundationSpan 6.2, *)
2234+
@available(macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2, visionOS 1.1, *)
2235+
@_alwaysEmitIntoClient
22342236
public var span: Span<UInt8> {
22352237
@lifetime(borrow self)
22362238
borrowing get {
@@ -2239,7 +2241,8 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
22392241
}
22402242
}
22412243

2242-
@available(FoundationSpan 6.2, *)
2244+
@available(macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2, visionOS 1.1, *)
2245+
@_alwaysEmitIntoClient
22432246
public var mutableBytes: MutableRawSpan {
22442247
@lifetime(&self)
22452248
mutating get {
@@ -2266,7 +2269,8 @@ public struct Data : Equatable, Hashable, RandomAccessCollection, MutableCollect
22662269
}
22672270
}
22682271

2269-
@available(FoundationSpan 6.2, *)
2272+
@available(macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2, visionOS 1.1, *)
2273+
@_alwaysEmitIntoClient
22702274
public var mutableSpan: MutableSpan<UInt8> {
22712275
@lifetime(&self)
22722276
mutating get {
@@ -2970,53 +2974,3 @@ extension Data : Codable {
29702974
}
29712975
}
29722976
}
2973-
2974-
// TODO: remove once _overrideLifetime is public in the standard library
2975-
/// Unsafely discard any lifetime dependency on the `dependent` argument. Return
2976-
/// a value identical to `dependent` with a lifetime dependency on the caller's
2977-
/// borrow scope of the `source` argument.
2978-
@unsafe
2979-
@_unsafeNonescapableResult
2980-
@_alwaysEmitIntoClient
2981-
@_transparent
2982-
@lifetime(borrow source)
2983-
internal func _overrideLifetime<
2984-
T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable
2985-
>(
2986-
_ dependent: consuming T, borrowing source: borrowing U
2987-
) -> T {
2988-
dependent
2989-
}
2990-
2991-
/// Unsafely discard any lifetime dependency on the `dependent` argument. Return
2992-
/// a value identical to `dependent` that inherits all lifetime dependencies from
2993-
/// the `source` argument.
2994-
@unsafe
2995-
@_unsafeNonescapableResult
2996-
@_alwaysEmitIntoClient
2997-
@_transparent
2998-
@lifetime(copy source)
2999-
internal func _overrideLifetime<
3000-
T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable
3001-
>(
3002-
_ dependent: consuming T, copying source: borrowing U
3003-
) -> T {
3004-
dependent
3005-
}
3006-
3007-
/// Unsafely discard any lifetime dependency on the `dependent` argument.
3008-
/// Return a value identical to `dependent` with a lifetime dependency
3009-
/// on the caller's exclusive borrow scope of the `source` argument.
3010-
@unsafe
3011-
@_unsafeNonescapableResult
3012-
@_alwaysEmitIntoClient
3013-
@_transparent
3014-
@lifetime(&source)
3015-
internal func _overrideLifetime<
3016-
T: ~Copyable & ~Escapable, U: ~Copyable & ~Escapable
3017-
>(
3018-
_ dependent: consuming T,
3019-
mutating source: inout U
3020-
) -> T {
3021-
dependent
3022-
}

Tests/FoundationEssentialsTests/DataTests.swift

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,8 +1645,8 @@ private final class DataTests {
16451645
#endif
16461646
}
16471647

1648-
@available(FoundationSpan 6.2, *)
1649-
@Test func inlineDataSpan() throws {
1648+
@Test
1649+
func inlineDataSpan() throws {
16501650
var source = Data()
16511651
var span = source.span
16521652
var isEmpty = span.isEmpty
@@ -1661,16 +1661,16 @@ private final class DataTests {
16611661
#expect(firstElement == 1)
16621662
}
16631663

1664-
@available(FoundationSpan 6.2, *)
1665-
@Test func inlineSliceDataSpan() throws {
1664+
@Test
1665+
func inlineSliceDataSpan() throws {
16661666
let source = Data(0 ... .max)
16671667
let span = source.span
16681668
#expect(span.count == source.count)
16691669
#expect(span[span.indices.last!] == .max)
16701670
}
16711671

1672-
@available(FoundationSpan 6.2, *)
1673-
@Test func inlineDataMutableSpan() throws {
1672+
@Test
1673+
func inlineDataMutableSpan() throws {
16741674
#if !canImport(Darwin) || FOUNDATION_FRAMEWORK
16751675
var source = Data()
16761676
var span = source.mutableSpan
@@ -1693,8 +1693,8 @@ private final class DataTests {
16931693
#endif
16941694
}
16951695

1696-
@available(FoundationSpan 6.2, *)
1697-
@Test func inlineSliceDataMutableSpan() throws {
1696+
@Test
1697+
func inlineSliceDataMutableSpan() throws {
16981698
#if !canImport(Darwin) || FOUNDATION_FRAMEWORK
16991699
var source = Data(0..<100)
17001700
let count = source.count
@@ -1707,8 +1707,8 @@ private final class DataTests {
17071707
#endif
17081708
}
17091709

1710-
@available(FoundationSpan 6.2, *)
1711-
@Test func inlineDataMutableRawSpan() throws {
1710+
@Test
1711+
func inlineDataMutableRawSpan() throws {
17121712
var source = Data()
17131713
var span = source.mutableBytes
17141714
var isEmpty = span.isEmpty
@@ -1728,8 +1728,8 @@ private final class DataTests {
17281728
#expect(source[i] == v)
17291729
}
17301730

1731-
@available(FoundationSpan 6.2, *)
1732-
@Test func inlineSliceDataMutableRawSpan() throws {
1731+
@Test
1732+
func inlineSliceDataMutableRawSpan() throws {
17331733
var source = Data(0..<100)
17341734
let count = source.count
17351735
var span = source.mutableBytes
@@ -2386,7 +2386,6 @@ extension DataTests {
23862386
@Suite("Large Data Tests", .serialized)
23872387
struct LargeDataTests {
23882388
@Test
2389-
@available(FoundationSpan 6.2, *)
23902389
func largeSliceDataSpan() throws {
23912390
#if _pointerBitWidth(_64)
23922391
let count = Int(Int32.max)
@@ -2404,7 +2403,6 @@ struct LargeDataTests {
24042403
}
24052404

24062405
@Test
2407-
@available(FoundationSpan 6.2, *)
24082406
func largeSliceDataMutableSpan() throws {
24092407
#if _pointerBitWidth(_64)
24102408
var count = Int(Int32.max)
@@ -2428,7 +2426,6 @@ struct LargeDataTests {
24282426
}
24292427

24302428
@Test
2431-
@available(FoundationSpan 6.2, *)
24322429
func largeSliceDataMutableRawSpan() throws {
24332430
#if _pointerBitWidth(_64)
24342431
var count = Int(Int32.max)

0 commit comments

Comments
 (0)