Skip to content

Commit ede853c

Browse files
committed
stdlib: Make typed throws ABI placeholders properly @usableFromInline.
Functions that are used in public `@inlinable` function bodies can't be marked `@_spi` nor can they be made obsolete. Also, they must retain `rethrows` so that use of these entry points from other `rethrows` functions is accepted. Builds on #72365. Once we no longer have to support pre-`$TypedThrows` compilers, all of this can be reverted. Part of rdar://125138945
1 parent 02a8ae0 commit ede853c

10 files changed

+37
-24
lines changed

stdlib/public/core/FloatingPointParsing.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ extension ${Self}: LosslessStringConvertible {
169169
self.init(Substring(text))
170170
} else {
171171
self = 0.0
172-
#if hasFeature(TypedThrows)
172+
#if $TypedThrows
173173
let success = _withUnprotectedUnsafeMutablePointer(to: &self) { p -> Bool in
174174
text.withCString { chars -> Bool in
175175
switch chars[0] {
@@ -216,7 +216,7 @@ extension ${Self}: LosslessStringConvertible {
216216
@available(SwiftStdlib 5.3, *)
217217
public init?(_ text: Substring) {
218218
self = 0.0
219-
#if hasFeature(TypedThrows)
219+
#if $TypedThrows
220220
let success = _withUnprotectedUnsafeMutablePointer(to: &self) { p -> Bool in
221221
text.withCString { chars -> Bool in
222222
switch chars[0] {

stdlib/public/core/LifetimeManager.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ public func withUnsafeMutablePointer<
8787
try body(UnsafeMutablePointer<T>(Builtin.addressof(&value)))
8888
}
8989

90-
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
90+
// FIXME(TypedThrows): Uncomment @_spi and revert rethrows
91+
//@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
9192
@_silgen_name("$ss24withUnsafeMutablePointer2to_q_xz_q_SpyxGKXEtKr0_lF")
9293
@usableFromInline
9394
internal func __abi_se0413_withUnsafeMutablePointer<T, Result>(
9495
to value: inout T,
9596
_ body: (UnsafeMutablePointer<T>) throws -> Result
96-
) throws -> Result {
97+
) rethrows -> Result {
9798
return try body(UnsafeMutablePointer<T>(Builtin.addressof(&value)))
9899
}
99100

@@ -147,13 +148,14 @@ public func withUnsafePointer<T: ~Copyable, E: Error, Result: ~Copyable>(
147148

148149
/// ABI: Historical withUnsafePointer(to:_:) rethrows, expressed as "throws",
149150
/// which is ABI-compatible with "rethrows".
150-
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
151+
// FIXME(TypedThrows): Uncomment @_spi and revert rethrows
152+
//@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
151153
@_silgen_name("$ss17withUnsafePointer2to_q_x_q_SPyxGKXEtKr0_lF")
152154
@usableFromInline
153155
internal func __abi_withUnsafePointer<T, Result>(
154156
to value: T,
155157
_ body: (UnsafePointer<T>) throws -> Result
156-
) throws -> Result
158+
) rethrows -> Result
157159
{
158160
return try body(UnsafePointer<T>(Builtin.addressOfBorrow(value)))
159161
}
@@ -192,13 +194,14 @@ public func withUnsafePointer<T: ~Copyable, E: Error, Result: ~Copyable>(
192194

193195
/// ABI: Historical withUnsafePointer(to:_:) rethrows,
194196
/// expressed as "throws", which is ABI-compatible with "rethrows".
195-
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
197+
// FIXME(TypedThrows): Uncomment @_spi and revert rethrows
198+
//@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
196199
@_silgen_name("$ss17withUnsafePointer2to_q_xz_q_SPyxGKXEtKr0_lF")
197200
@usableFromInline
198201
internal func __abi_se0413_withUnsafePointer<T, Result>(
199202
to value: inout T,
200203
_ body: (UnsafePointer<T>) throws -> Result
201-
) throws -> Result {
204+
) rethrows -> Result {
202205
return try body(UnsafePointer<T>(Builtin.addressof(&value)))
203206
}
204207

stdlib/public/core/Random.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public struct SystemRandomNumberGenerator: RandomNumberGenerator, Sendable {
158158
@inlinable
159159
public mutating func next() -> UInt64 {
160160
var random: UInt64 = 0
161-
#if hasFeature(TypedThrows)
161+
#if $TypedThrows
162162
_withUnprotectedUnsafeMutablePointer(to: &random) {
163163
swift_stdlib_random($0, MemoryLayout<UInt64>.size)
164164
}

stdlib/public/core/Runtime.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func _stdlib_atomicInitializeARCRef(
139139
let desiredPtr = unmanaged.toOpaque()
140140
let rawTarget = UnsafeMutableRawPointer(target).assumingMemoryBound(
141141
to: Optional<UnsafeRawPointer>.self)
142-
#if hasFeature(TypedThrows)
142+
#if $TypedThrows
143143
let wonRace = withUnsafeMutablePointer(to: &expected) {
144144
_stdlib_atomicCompareExchangeStrongPtr(
145145
object: rawTarget, expected: $0, desired: desiredPtr

stdlib/public/core/SmallString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ extension _SmallString {
223223
) rethrows -> Result {
224224
let count = self.count
225225
var raw = self.zeroTerminatedRawCodeUnits
226-
#if hasFeature(TypedThrows)
226+
#if $TypedThrows
227227
return try Swift._withUnprotectedUnsafeBytes(of: &raw) {
228228
let rawPtr = $0.baseAddress._unsafelyUnwrappedUnchecked
229229
// Rebind the underlying (UInt64, UInt64) tuple to UInt8 for the

stdlib/public/core/UnicodeScalar.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ extension Unicode.Scalar {
535535

536536
// The first code unit is in the least significant byte of codeUnits.
537537
codeUnits = codeUnits.littleEndian
538-
#if hasFeature(TypedThrows)
538+
#if $TypedThrows
539539
return try Swift._withUnprotectedUnsafePointer(to: &codeUnits) {
540540
return try $0.withMemoryRebound(to: UInt8.self, capacity: 4) {
541541
return try body(UnsafeBufferPointer(start: $0, count: utf8Count))

stdlib/public/core/UnsafeRawBufferPointer.swift.gyb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,13 +1230,14 @@ public func withUnsafeMutableBytes<T: ~Copyable, E: Error, Result: ~Copyable>(
12301230

12311231
/// ABI: Historical withUnsafeMutableBytes(of:_:) rethrows,
12321232
/// expressed as "throws", which is ABI-compatible with "rethrows".
1233-
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
1233+
// FIXME(TypedThrows): Uncomment @_spi and revert rethrows
1234+
//@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
12341235
@_silgen_name("$ss22withUnsafeMutableBytes2of_q_xz_q_SwKXEtKr0_lF")
12351236
@usableFromInline
12361237
func __abi_se0413_withUnsafeMutableBytes<T, Result>(
12371238
of value: inout T,
12381239
_ body: (UnsafeMutableRawBufferPointer) throws -> Result
1239-
) throws -> Result {
1240+
) rethrows -> Result {
12401241
return try withUnsafeMutablePointer(to: &value) {
12411242
return try body(UnsafeMutableRawBufferPointer(
12421243
start: $0, count: MemoryLayout<T>.size))
@@ -1297,13 +1298,14 @@ public func withUnsafeBytes<T: ~Copyable, E: Error, Result: ~Copyable>(
12971298

12981299
/// ABI: Historical withUnsafeBytes(of:_:) rethrows,
12991300
/// expressed as "throws", which is ABI-compatible with "rethrows".
1300-
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
1301+
// FIXME(TypedThrows): Uncomment @_spi and revert rethrows
1302+
//@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
13011303
@_silgen_name("$ss15withUnsafeBytes2of_q_xz_q_SWKXEtKr0_lF")
13021304
@usableFromInline
13031305
func __abi_se0413_withUnsafeBytes<T, Result>(
13041306
of value: inout T,
13051307
_ body: (UnsafeRawBufferPointer) throws -> Result
1306-
) throws -> Result {
1308+
) rethrows -> Result {
13071309
return try withUnsafePointer(to: &value) {
13081310
try body(UnsafeRawBufferPointer(start: $0, count: MemoryLayout<T>.size))
13091311
}
@@ -1361,13 +1363,14 @@ public func withUnsafeBytes<
13611363

13621364
/// ABI: Historical withUnsafeBytes(of:_:) rethrows,
13631365
/// expressed as "throws", which is ABI-compatible with "rethrows".
1364-
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
1366+
// FIXME(TypedThrows): Uncomment @_spi and revert rethrows
1367+
//@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
13651368
@_silgen_name("$ss15withUnsafeBytes2of_q_x_q_SWKXEtKr0_lF")
13661369
@usableFromInline
13671370
func __abi_se0413_withUnsafeBytes<T, Result>(
13681371
of value: T,
13691372
_ body: (UnsafeRawBufferPointer) throws -> Result
1370-
) throws -> Result {
1373+
) rethrows -> Result {
13711374
let addr = UnsafeRawPointer(Builtin.addressOfBorrow(value))
13721375
let buffer = UnsafeRawBufferPointer(start: addr, count: MemoryLayout<T>.size)
13731376
return try body(buffer)

stdlib/public/core/UnsafeRawPointer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ extension UnsafeMutableRawPointer {
15011501
"storeBytes to misaligned raw pointer")
15021502

15031503
var temp = value
1504-
#if hasFeature(TypedThrows)
1504+
#if $TypedThrows
15051505
withUnsafeMutablePointer(to: &temp) { source in
15061506
let rawSrc = UnsafeMutableRawPointer(source)._rawValue
15071507
// FIXME: to be replaced by _memcpy when conversions are implemented.

stdlib/public/core/VarArgs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public func _encodeBitsAsWords<T>(_ x: T) -> [Int] {
215215
_internalInvariant(!result.isEmpty)
216216
var tmp = x
217217
// FIXME: use UnsafeMutablePointer.assign(from:) instead of memcpy.
218-
#if hasFeature(TypedThrows)
218+
#if $TypedThrows
219219
_withUnprotectedUnsafeMutablePointer(to: &tmp) {
220220
_memcpy(dest: UnsafeMutablePointer(result._baseAddressIfContiguous!),
221221
src: $0,

test/api-digester/stability-stdlib-abi-without-asserts.test

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,10 +712,17 @@ Func withExtendedLifetime(_:_:) has generic signature change from <T, Result> to
712712
Func withExtendedLifetime(_:_:) has mangled name changing from 'Swift.withExtendedLifetime<A, B>(A, () throws -> B) throws -> B' to 'Swift.withExtendedLifetime<A, B where A: ~Swift.Copyable, B: ~Swift.Copyable>(A, () throws -> B) throws -> B'
713713
Func withExtendedLifetime(_:_:) has parameter 0 changing from Default to Shared
714714
Func withExtendedLifetime(_:_:) is now with @_preInverseGenerics
715-
Func withUnsafeBytes(of:_:) has been removed
716-
Func withUnsafeMutableBytes(of:_:) has been removed
717-
Func withUnsafeMutablePointer(to:_:) has been removed
718-
Func withUnsafePointer(to:_:) has been removed
715+
Func withUnsafeBytes(of:_:) has been renamed to Func __abi_se0413_withUnsafeBytes(of:_:)
716+
Func withUnsafeBytes(of:_:) has mangled name changing from 'Swift.withUnsafeBytes<A, B>(of: A, _: (Swift.UnsafeRawBufferPointer) throws -> B) throws -> B' to 'Swift.__abi_se0413_withUnsafeBytes<A, B>(of: A, _: (Swift.UnsafeRawBufferPointer) throws -> B) throws -> B'
717+
Func withUnsafeBytes(of:_:) has mangled name changing from 'Swift.withUnsafeBytes<A, B>(of: inout A, _: (Swift.UnsafeRawBufferPointer) throws -> B) throws -> B' to 'Swift.__abi_se0413_withUnsafeBytes<A, B>(of: inout A, _: (Swift.UnsafeRawBufferPointer) throws -> B) throws -> B'
718+
Func withUnsafeMutableBytes(of:_:) has been renamed to Func __abi_se0413_withUnsafeMutableBytes(of:_:)
719+
Func withUnsafeMutableBytes(of:_:) has mangled name changing from 'Swift.withUnsafeMutableBytes<A, B>(of: inout A, _: (Swift.UnsafeMutableRawBufferPointer) throws -> B) throws -> B' to 'Swift.__abi_se0413_withUnsafeMutableBytes<A, B>(of: inout A, _: (Swift.UnsafeMutableRawBufferPointer) throws -> B) throws -> B'
720+
Func withUnsafeMutablePointer(to:_:) has been renamed to Func __abi_se0413_withUnsafeMutablePointer(to:_:)
721+
Func withUnsafeMutablePointer(to:_:) has mangled name changing from 'Swift.withUnsafeMutablePointer<A, B>(to: inout A, _: (Swift.UnsafeMutablePointer<A>) throws -> B) throws -> B' to 'Swift.__abi_se0413_withUnsafeMutablePointer<A, B>(to: inout A, _: (Swift.UnsafeMutablePointer<A>) throws -> B) throws -> B'
722+
Func withUnsafePointer(to:_:) has been renamed to Func __abi_se0413_withUnsafePointer(to:_:)
723+
Func withUnsafePointer(to:_:) has been renamed to Func __abi_withUnsafePointer(to:_:)
724+
Func withUnsafePointer(to:_:) has mangled name changing from 'Swift.withUnsafePointer<A, B>(to: A, _: (Swift.UnsafePointer<A>) throws -> B) throws -> B' to 'Swift.__abi_withUnsafePointer<A, B>(to: A, _: (Swift.UnsafePointer<A>) throws -> B) throws -> B'
725+
Func withUnsafePointer(to:_:) has mangled name changing from 'Swift.withUnsafePointer<A, B>(to: inout A, _: (Swift.UnsafePointer<A>) throws -> B) throws -> B' to 'Swift.__abi_se0413_withUnsafePointer<A, B>(to: inout A, _: (Swift.UnsafePointer<A>) throws -> B) throws -> B'
719726
Protocol _Pointer has generic signature change from <Self : Swift.CustomDebugStringConvertible, Self : Swift.CustomReflectable, Self : Swift.Hashable, Self : Swift.Strideable> to <Self : Swift.CustomDebugStringConvertible, Self : Swift.CustomReflectable, Self : Swift.Hashable, Self : Swift.Strideable, Self : Swift._BitwiseCopyable, Self.Pointee : ~Copyable>
720727
Struct ManagedBufferPointer has generic signature change from <Header, Element> to <Header, Element where Element : ~Copyable>
721728
Struct UnsafeBufferPointer has generic signature change from <Element> to <Element where Element : ~Copyable>

0 commit comments

Comments
 (0)