Skip to content

stdlib: Guard @inlinable use of withMemoryRebound() with #if $TypedThrows #72301

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions stdlib/public/core/UnsafeRawBufferPointer.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ extension Unsafe${Mutable}RawBufferPointer {
public func withContiguousMutableStorageIfAvailable<R>(
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
) rethrows -> R? {
#if $TypedThrows
try withMemoryRebound(to: Element.self) { b in
var buffer = b
defer {
Expand All @@ -1143,6 +1144,9 @@ extension Unsafe${Mutable}RawBufferPointer {
}
return try body(&buffer)
}
#else
fatalError("unsupported compiler")
#endif
}

% end
Expand All @@ -1151,9 +1155,13 @@ extension Unsafe${Mutable}RawBufferPointer {
public func withContiguousStorageIfAvailable<R>(
_ body: (UnsafeBufferPointer<Element>) throws -> R
) rethrows -> R? {
#if $TypedThrows
try withMemoryRebound(to: Element.self) {
try body(${ 'UnsafeBufferPointer<Element>($0)' if Mutable else '$0' })
}
#else
fatalError("unsupported compiler")
#endif
}
}

Expand Down