Skip to content

Commit e06bbf7

Browse files
authored
Merge pull request #70971 from kubamracek/tt-withunsafeptr
Adopt typed throws in one withUnsafePointer() API
2 parents 1da24ec + 53ddf9b commit e06bbf7

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

stdlib/public/core/LifetimeManager.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public func _withUnprotectedUnsafeMutablePointer<T, Result>(
9999
#endif
100100
}
101101

102-
#if !$Embedded
103102
/// Invokes the given closure with a pointer to the given argument.
104103
///
105104
/// The `withUnsafePointer(to:_:)` function is useful for calling Objective-C
@@ -120,25 +119,27 @@ public func _withUnprotectedUnsafeMutablePointer<T, Result>(
120119
/// type. If you need to mutate the argument through the pointer, use
121120
/// `withUnsafeMutablePointer(to:_:)` instead.
122121
/// - Returns: The return value, if any, of the `body` closure.
122+
@_alwaysEmitIntoClient
123123
@inlinable
124-
public func withUnsafePointer<T, Result>(
124+
public func withUnsafePointer<T, E, Result>(
125125
to value: T,
126-
_ body: (UnsafePointer<T>) throws -> Result
127-
) rethrows -> Result
126+
_ body: (UnsafePointer<T>) throws(E) -> Result
127+
) throws(E) -> Result
128128
{
129129
return try body(UnsafePointer<T>(Builtin.addressOfBorrow(value)))
130130
}
131-
#else
132-
// TODO: This should be unified with non-embedded Swift.
133-
@inlinable
134-
public func withUnsafePointer<T, E, Result>(
131+
132+
/// ABI: Historical withUnsafePointer(to:_:) rethrows, expressed as "throws",
133+
/// which is ABI-compatible with "rethrows".
134+
@_silgen_name("$ss17withUnsafePointer2to_q_x_q_SPyxGKXEtKr0_lF")
135+
@usableFromInline
136+
func __abi_withUnsafePointer<T, Result>(
135137
to value: T,
136-
_ body: (UnsafePointer<T>) throws(E) -> Result
137-
) throws(E) -> Result
138+
_ body: (UnsafePointer<T>) throws -> Result
139+
) throws -> Result
138140
{
139141
return try body(UnsafePointer<T>(Builtin.addressOfBorrow(value)))
140142
}
141-
#endif
142143

143144
/// Invokes the given closure with a pointer to the given argument.
144145
///

test/api-digester/Outputs/stability-stdlib-source-x86_64.swift.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Func Collection.map(_:) is now without @rethrows
4141
Func Sequence.map(_:) has generic signature change from <Self, T where Self : Swift.Sequence> to <Self, T, E where Self : Swift.Sequence, E : Swift.Error>
4242
Func Sequence.map(_:) is now without @rethrows
4343
Constructor Result.init(catching:) has generic signature change from <Success, Failure where Failure == any Swift.Error> to <Success, Failure where Failure : Swift.Error>
44+
Func withUnsafePointer(to:_:) has generic signature change from <T, Result> to <T, E, Result where E : Swift.Error>
45+
Func withUnsafePointer(to:_:) is now without @rethrows
4446
Func withoutActuallyEscaping(_:do:) has generic signature change from <ClosureType, ResultType> to <ClosureType, ResultType, Failure where Failure : Swift.Error>
4547
Func withoutActuallyEscaping(_:do:) is now without @rethrows
4648

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ Constructor Result.init(__abi_catching:) is a new API without @available attribu
9999
Constructor Result.init(catching:) has been removed
100100
Func Result.get() has been renamed to Func __abi_get()
101101
Func Result.get() has mangled name changing from 'Swift.Result.get() throws -> A' to 'Swift.Result.__abi_get() throws -> A'
102+
Func withUnsafePointer(to:_:) has been renamed to Func __abi_withUnsafePointer(to:_:)
103+
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'
104+
Func withUnsafePointer(to:_:) is now without @rethrows
102105
Func withoutActuallyEscaping(_:do:) has been renamed to Func __abi_withoutActuallyEscaping(_:do:)
103106
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'
104107
Func withoutActuallyEscaping(_:do:) is now without @rethrows

0 commit comments

Comments
 (0)