Skip to content

stdlib: Remove #if $TypedThrows guards #75067

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 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions stdlib/public/Concurrency/ExecutorAssertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,12 @@ extension Actor {
fatalError("Incorrect actor executor assumption; Expected same executor as \(self).", file: file, line: line)
}

#if $TypedThrows
// To do the unsafe cast, we have to pretend it's @escaping.
return try withoutActuallyEscaping(operation) {
(_ fn: @escaping YesActor) throws -> T in
let rawFn = unsafeBitCast(fn, to: NoActor.self)
return try rawFn(self)
}
#else
fatalError("unsupported compiler")
#endif
}

@available(SwiftStdlib 5.9, *)
Expand Down
4 changes: 0 additions & 4 deletions stdlib/public/Concurrency/MainActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,12 @@ extension MainActor {
fatalError("Incorrect actor executor assumption; Expected same executor as \(self).", file: file, line: line)
}

#if $TypedThrows
// To do the unsafe cast, we have to pretend it's @escaping.
return try withoutActuallyEscaping(operation) {
(_ fn: @escaping YesActor) throws -> T in
let rawFn = unsafeBitCast(fn, to: NoActor.self)
return try rawFn()
}
#else
fatalError("unsupported compiler")
#endif
}

@available(SwiftStdlib 5.9, *)
Expand Down
4 changes: 0 additions & 4 deletions stdlib/public/Distributed/DistributedAssertions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,12 @@ extension DistributedActor {
fatalError("Incorrect actor executor assumption; Expected same executor as \(self).", file: file, line: line)
}

#if $TypedThrows
// To do the unsafe cast, we have to pretend it's @escaping.
return try withoutActuallyEscaping(operation) {
(_ fn: @escaping YesActor) throws -> T in
let rawFn = unsafeBitCast(fn, to: NoActor.self)
return try rawFn(self)
}
#else
fatalError("unsupported compiler")
#endif
}

@available(SwiftStdlib 5.9, *)
Expand Down
4 changes: 0 additions & 4 deletions stdlib/public/core/ArrayCast.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ public func _arrayForceCast<SourceElement, TargetElement>(
return Array(_immutableCocoaArray: source._buffer._asCocoaArray())
}
#endif
#if $TypedThrows
return source.map { $0 as! TargetElement }
#else
return try! source.__rethrows_map { $0 as! TargetElement }
#endif
}

/// Called by the casting machinery.
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ extension Collection {
// ABI-only entrypoint for the rethrows version of map, which has been
// superseded by the typed-throws version. Expressed as "throws", which is
// ABI-compatible with "rethrows".
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
@usableFromInline
@_silgen_name("$sSlsE3mapySayqd__Gqd__7ElementQzKXEKlF")
func __rethrows_map<T>(
Expand Down
20 changes: 4 additions & 16 deletions stdlib/public/core/ExistentialCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,7 @@ internal final class _SequenceBox<S: Sequence>: _AnySequenceBox<S.Element> {
internal override func _map<T>(
_ transform: (Element) throws -> T
) throws -> [T] {
#if $TypedThrows
try _base.map(transform)
#else
try _base.__rethrows_map(transform)
#endif
}
@inlinable
internal override func _filter(
Expand Down Expand Up @@ -650,11 +646,7 @@ internal final class _CollectionBox<S: Collection>: _AnyCollectionBox<S.Element>
internal override func _map<T>(
_ transform: (Element) throws -> T
) throws -> [T] {
#if $TypedThrows
try _base.map(transform)
#else
try _base.__rethrows_map(transform)
#endif
}
@inlinable
internal override func _filter(
Expand Down Expand Up @@ -852,11 +844,7 @@ internal final class _BidirectionalCollectionBox<S: BidirectionalCollection>
internal override func _map<T>(
_ transform: (Element) throws -> T
) throws -> [T] {
#if $TypedThrows
try _base.map(transform)
#else
try _base.__rethrows_map(transform)
#endif
}
@inlinable
internal override func _filter(
Expand Down Expand Up @@ -1072,11 +1060,7 @@ internal final class _RandomAccessCollectionBox<S: RandomAccessCollection>
internal override func _map<T>(
_ transform: (Element) throws -> T
) throws -> [T] {
#if $TypedThrows
try _base.map(transform)
#else
try _base.__rethrows_map(transform)
#endif
}
@inlinable
internal override func _filter(
Expand Down Expand Up @@ -1380,6 +1364,7 @@ extension AnySequence {
// ABI-only entrypoint for the rethrows version of map, which has been
// superseded by the typed-throws version. Expressed as "throws", which is
// ABI-compatible with "rethrows".
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
@usableFromInline
@_silgen_name("$ss11AnySequenceV3mapySayqd__Gqd__xKXEKlF")
func __rethrows_map<T>(
Expand Down Expand Up @@ -1483,6 +1468,7 @@ extension AnyCollection {
// ABI-only entrypoint for the rethrows version of map, which has been
// superseded by the typed-throws version. Expressed as "throws", which is
// ABI-compatible with "rethrows".
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
@usableFromInline
@_silgen_name("$ss13AnyCollectionV3mapySayqd__Gqd__xKXEKlF")
func __rethrows_map<T>(
Expand Down Expand Up @@ -1592,6 +1578,7 @@ extension AnyBidirectionalCollection {
// ABI-only entrypoint for the rethrows version of map, which has been
// superseded by the typed-throws version. Expressed as "throws", which is
// ABI-compatible with "rethrows".
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
@usableFromInline
@_silgen_name("$ss26AnyBidirectionalCollectionV3mapySayqd__Gqd__xKXEKlF")
func __rethrows_map<T>(
Expand Down Expand Up @@ -1703,6 +1690,7 @@ extension AnyRandomAccessCollection {
// ABI-only entrypoint for the rethrows version of map, which has been
// superseded by the typed-throws version. Expressed as "throws", which is
// ABI-compatible with "rethrows".
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
@usableFromInline
@_silgen_name("$ss25AnyRandomAccessCollectionV3mapySayqd__Gqd__xKXEKlF")
func __rethrows_map<T>(
Expand Down
36 changes: 0 additions & 36 deletions stdlib/public/core/FloatingPointParsing.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ extension ${Self}: LosslessStringConvertible {
self.init(Substring(text))
} else {
self = 0.0
#if $TypedThrows
let success = _withUnprotectedUnsafeMutablePointer(to: &self) { p -> Bool in
text.withCString { chars -> Bool in
switch chars[0] {
Expand All @@ -185,23 +184,6 @@ extension ${Self}: LosslessStringConvertible {
return endPtr != nil && endPtr![0] == 0
}
}
#else
let success = __abi_se0413_withUnsafeMutablePointer(to: &self) { p -> Bool in
text.withCString { chars -> Bool in
switch chars[0] {
case 9, 10, 11, 12, 13, 32:
return false // Reject leading whitespace
case 0:
return false // Reject empty string
default:
break
}
let endPtr = _swift_stdlib_strto${cFuncSuffix2[bits]}_clocale(chars, p)
// Succeed only if endPtr points to end of C string
return endPtr != nil && endPtr![0] == 0
}
}
#endif
if !success {
return nil
}
Expand All @@ -216,7 +198,6 @@ extension ${Self}: LosslessStringConvertible {
@available(SwiftStdlib 5.3, *)
public init?(_ text: Substring) {
self = 0.0
#if $TypedThrows
let success = _withUnprotectedUnsafeMutablePointer(to: &self) { p -> Bool in
text.withCString { chars -> Bool in
switch chars[0] {
Expand All @@ -232,23 +213,6 @@ extension ${Self}: LosslessStringConvertible {
return endPtr != nil && endPtr![0] == 0
}
}
#else
let success = __abi_se0413_withUnsafeMutablePointer(to: &self) { p -> Bool in
text.withCString { chars -> Bool in
switch chars[0] {
case 9, 10, 11, 12, 13, 32:
return false // Reject leading whitespace
case 0:
return false // Reject empty string
default:
break
}
let endPtr = _swift_stdlib_strto${cFuncSuffix2[bits]}_clocale(chars, p)
// Succeed only if endPtr points to end of C string
return endPtr != nil && endPtr![0] == 0
}
}
#endif
if !success {
return nil
}
Expand Down
15 changes: 6 additions & 9 deletions stdlib/public/core/LifetimeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,13 @@ public func withUnsafeMutablePointer<
try body(UnsafeMutablePointer<T>(Builtin.addressof(&value)))
}

// FIXME(TypedThrows): Uncomment @_spi and revert rethrows
//@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
@_silgen_name("$ss24withUnsafeMutablePointer2to_q_xz_q_SpyxGKXEtKr0_lF")
@usableFromInline
internal func __abi_se0413_withUnsafeMutablePointer<T, Result>(
to value: inout T,
_ body: (UnsafeMutablePointer<T>) throws -> Result
) rethrows -> Result {
) throws -> Result {
return try body(UnsafeMutablePointer<T>(Builtin.addressof(&value)))
}

Expand Down Expand Up @@ -167,14 +166,13 @@ public func withUnsafePointer<T: ~Copyable, E: Error, Result: ~Copyable>(

/// ABI: Historical withUnsafePointer(to:_:) rethrows, expressed as "throws",
/// which is ABI-compatible with "rethrows".
// FIXME(TypedThrows): Uncomment @_spi and revert rethrows
//@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
@_silgen_name("$ss17withUnsafePointer2to_q_x_q_SPyxGKXEtKr0_lF")
@usableFromInline
internal func __abi_withUnsafePointer<T, Result>(
to value: T,
_ body: (UnsafePointer<T>) throws -> Result
) rethrows -> Result
) throws -> Result
{
return try body(UnsafePointer<T>(Builtin.addressOfBorrow(value)))
}
Expand Down Expand Up @@ -213,14 +211,13 @@ public func withUnsafePointer<T: ~Copyable, E: Error, Result: ~Copyable>(

/// ABI: Historical withUnsafePointer(to:_:) rethrows,
/// expressed as "throws", which is ABI-compatible with "rethrows".
// FIXME(TypedThrows): Uncomment @_spi and revert rethrows
//@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
@_silgen_name("$ss17withUnsafePointer2to_q_xz_q_SPyxGKXEtKr0_lF")
@usableFromInline
internal func __abi_se0413_withUnsafePointer<T, Result>(
to value: inout T,
_ body: (UnsafePointer<T>) throws -> Result
) rethrows -> Result {
) throws -> Result {
return try body(UnsafePointer<T>(Builtin.addressof(&value)))
}

Expand Down
6 changes: 0 additions & 6 deletions stdlib/public/core/Random.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,9 @@ public struct SystemRandomNumberGenerator: RandomNumberGenerator, Sendable {
@inlinable
public mutating func next() -> UInt64 {
var random: UInt64 = 0
#if $TypedThrows
_withUnprotectedUnsafeMutablePointer(to: &random) {
swift_stdlib_random($0, MemoryLayout<UInt64>.size)
}
#else
__abi_se0413_withUnsafeMutablePointer(to: &random) {
swift_stdlib_random($0, MemoryLayout<UInt64>.size)
}
#endif
return random
}
}
8 changes: 0 additions & 8 deletions stdlib/public/core/Runtime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,11 @@ func _stdlib_atomicInitializeARCRef(
let desiredPtr = unmanaged.toOpaque()
let rawTarget = UnsafeMutableRawPointer(target).assumingMemoryBound(
to: Optional<UnsafeRawPointer>.self)
#if $TypedThrows
let wonRace = withUnsafeMutablePointer(to: &expected) {
_stdlib_atomicCompareExchangeStrongPtr(
object: rawTarget, expected: $0, desired: desiredPtr
)
}
#else
let wonRace = __abi_se0413_withUnsafeMutablePointer(to: &expected) {
_stdlib_atomicCompareExchangeStrongPtr(
object: rawTarget, expected: $0, desired: desiredPtr
)
}
#endif
if !wonRace {
// Some other thread initialized the value. Balance the retain that we
// performed on 'desired'.
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ extension Sequence {
// ABI-only entrypoint for the rethrows version of map, which has been
// superseded by the typed-throws version. Expressed as "throws", which is
// ABI-compatible with "rethrows".
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
@usableFromInline
@_silgen_name("$sSTsE3mapySayqd__Gqd__7ElementQzKXEKlF")
func __rethrows_map<T>(
Expand Down
14 changes: 0 additions & 14 deletions stdlib/public/core/SmallString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ extension _SmallString {
) rethrows -> Result {
let count = self.count
var raw = self.zeroTerminatedRawCodeUnits
#if $TypedThrows
return try Swift._withUnprotectedUnsafeBytes(of: &raw) {
let rawPtr = $0.baseAddress._unsafelyUnwrappedUnchecked
// Rebind the underlying (UInt64, UInt64) tuple to UInt8 for the
Expand All @@ -235,19 +234,6 @@ extension _SmallString {
}
return try f(UnsafeBufferPointer(_uncheckedStart: ptr, count: count))
}
#else
return try Swift.__abi_se0413_withUnsafeBytes(of: &raw) {
let rawPtr = $0.baseAddress._unsafelyUnwrappedUnchecked
// Rebind the underlying (UInt64, UInt64) tuple to UInt8 for the
// duration of the closure. Accessing self after this rebind is undefined.
let ptr = rawPtr.bindMemory(to: UInt8.self, capacity: count)
defer {
// Restore the memory type of self._storage
_ = rawPtr.bindMemory(to: RawBitPattern.self, capacity: 1)
}
return try f(UnsafeBufferPointer(_uncheckedStart: ptr, count: count))
}
#endif
}

// Overwrite stored code units, including uninitialized. `f` should return the
Expand Down
8 changes: 0 additions & 8 deletions stdlib/public/core/UnicodeScalar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -528,18 +528,10 @@ extension Unicode.Scalar {

// The first code unit is in the least significant byte of codeUnits.
codeUnits = codeUnits.littleEndian
#if $TypedThrows
return try Swift._withUnprotectedUnsafePointer(to: &codeUnits) {
return try $0.withMemoryRebound(to: UInt8.self, capacity: 4) {
return try body(UnsafeBufferPointer(start: $0, count: utf8Count))
}
}
#else
return try Swift.__abi_se0413_withUnsafePointer(to: &codeUnits) {
return try $0.withMemoryRebound(to: UInt8.self, capacity: 4) {
return try body(UnsafeBufferPointer(start: $0, count: utf8Count))
}
}
#endif
}
}
Loading