Skip to content

Commit 578a058

Browse files
authored
Merge pull request #72052 from glessard/toplevel-withpointer-typed-throws
[stdlib] convert `withUnsafePointer()` to typed throws
2 parents 4d484c9 + 95c07e4 commit 578a058

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

stdlib/public/core/LifetimeManager.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,22 @@ func __abi_withUnsafePointer<T, Result>(
166166
/// `withUnsafeMutablePointer(to:_:)` instead.
167167
/// - Returns: The return value, if any, of the `body` closure.
168168
@inlinable
169-
public func withUnsafePointer<T, Result>(
169+
@_alwaysEmitIntoClient
170+
public func withUnsafePointer<T, E: Error, Result>(
171+
to value: inout T,
172+
_ body: (UnsafePointer<T>) throws(E) -> Result
173+
) throws(E) -> Result {
174+
try body(UnsafePointer<T>(Builtin.addressof(&value)))
175+
}
176+
177+
/// ABI: Historical withUnsafePointer(to:_:) rethrows,
178+
/// expressed as "throws", which is ABI-compatible with "rethrows".
179+
@_silgen_name("$ss17withUnsafePointer2to_q_xz_q_SPyxGKXEtKr0_lF")
180+
@usableFromInline
181+
func __abi_se0413_withUnsafePointer<T, Result>(
170182
to value: inout T,
171183
_ body: (UnsafePointer<T>) throws -> Result
172-
) rethrows -> Result
173-
{
184+
) throws -> Result {
174185
return try body(UnsafePointer<T>(Builtin.addressof(&value)))
175186
}
176187

@@ -179,11 +190,10 @@ public func withUnsafePointer<T, Result>(
179190
/// This function is similar to `withUnsafePointer`, except that it
180191
/// doesn't trigger stack protection for the pointer.
181192
@_alwaysEmitIntoClient
182-
public func _withUnprotectedUnsafePointer<T, Result>(
193+
public func _withUnprotectedUnsafePointer<T, E: Error, Result>(
183194
to value: inout T,
184-
_ body: (UnsafePointer<T>) throws -> Result
185-
) rethrows -> Result
186-
{
195+
_ body: (UnsafePointer<T>) throws(E) -> Result
196+
) throws(E) -> Result {
187197
#if $BuiltinUnprotectedAddressOf
188198
return try body(UnsafePointer<T>(Builtin.unprotectedAddressOf(&value)))
189199
#else

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ Func Result.get() has been renamed to Func __abi_get()
107107
Func Result.get() has mangled name changing from 'Swift.Result.get() throws -> A' to 'Swift.Result.__abi_get() throws -> A'
108108
Func withUnsafePointer(to:_:) has been renamed to Func __abi_withUnsafePointer(to:_:)
109109
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'
110+
Func withUnsafePointer(to:_:) has been renamed to Func __abi_se0413_withUnsafePointer(to:_:)
111+
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'
110112
Func withUnsafePointer(to:_:) is now without @rethrows
111113
Func withoutActuallyEscaping(_:do:) has been renamed to Func __abi_withoutActuallyEscaping(_:do:)
112114
Func withoutActuallyEscaping(_:do:) has mangled name changing from 'Swift.withoutActuallyEscaping<A, B>(_: A, do: (A) throws -> B) throws -> B' to 'Swift.__abi_withoutActuallyEscaping<A, B>(_: A, do: (A) throws -> B) throws -> B'
@@ -115,6 +117,7 @@ Func _openExistential(_:do:) has been renamed to Func __abi_openExistential(_:do
115117
Func _openExistential(_:do:) has mangled name changing from 'Swift._openExistential<A, B, C>(_: A, do: (B) throws -> C) throws -> C' to 'Swift.__abi_openExistential<A, B, C>(_: A, do: (B) throws -> C) throws -> C'
116118
Func _openExistential(_:do:) is now without @rethrows
117119

120+
118121
// These haven't actually been removed; they are simply marked unavailable.
119122
// This seems to be a false positive in the ABI checker. This is not an ABI
120123
// break because the symbols are still present, and is not a source break

0 commit comments

Comments
 (0)