Skip to content

Commit

Permalink
stdlib: Remove #if $NoncopyableGenerics guards.
Browse files Browse the repository at this point in the history
The stdlib is always built with NoncopyableGenerics enabled, so `#if
$NoncopyableGenerics` guards in non-inlinable code are superfluous.
Additionally, the stdlib's interface no longer needs to support compilers
without the feature, so the guards in inlinable code can also be removed.
  • Loading branch information
tshortli committed Jul 9, 2024
1 parent 4e4d547 commit b1bf693
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 22 deletions.
2 changes: 0 additions & 2 deletions stdlib/public/core/Bitset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,8 @@ extension _UnsafeBitset.Word {
// iterator, not the original word.
extension _UnsafeBitset.Word: Sequence, IteratorProtocol {

#if $NoncopyableGenerics
@usableFromInline
typealias Element = Int
#endif

@inlinable
internal var count: Int {
Expand Down
3 changes: 0 additions & 3 deletions stdlib/public/core/ExistentialCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1286,10 +1286,7 @@ internal struct _ClosureBasedSequence<Iterator: IteratorProtocol> {
extension _ClosureBasedSequence: Sendable {}

extension _ClosureBasedSequence: Sequence {

#if $NoncopyableGenerics
public typealias Element = Iterator.Element
#endif

@inlinable
internal func makeIterator() -> Iterator {
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func _rethrowsViaClosure(_ fn: () throws -> ()) rethrows {
@_marker public protocol Escapable {}

#if $BitwiseCopyable2
#if $NoncopyableGenerics && $NonescapableTypes
#if $NonescapableTypes
@_marker public protocol BitwiseCopyable: ~Escapable { }
#else
@_marker public protocol BitwiseCopyable { }
Expand All @@ -240,7 +240,7 @@ func _rethrowsViaClosure(_ fn: () throws -> ()) rethrows {
@available(*, deprecated, message: "Use BitwiseCopyable")
public typealias _BitwiseCopyable = BitwiseCopyable
#else
#if $NoncopyableGenerics && $NonescapableTypes
#if $NonescapableTypes
@_marker public protocol _BitwiseCopyable: ~Escapable { }
#else
@_marker public protocol _BitwiseCopyable { }
Expand Down
8 changes: 0 additions & 8 deletions stdlib/public/core/Optional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,12 @@ extension Optional where Wrapped: ~Copyable {
public borrowing func _borrowingMap<U: ~Copyable, E: Error>(
_ transform: (borrowing Wrapped) throws(E) -> U
) throws(E) -> U? {
#if compiler(>=6.0) && $NoncopyableGenerics
switch self {
case .some(let y):
return .some(try transform(y))
case .none:
return .none
}
#else
fatalError("unsupported compiler")
#endif
}
}

Expand Down Expand Up @@ -308,16 +304,12 @@ extension Optional where Wrapped: ~Copyable {
public func _borrowingFlatMap<U: ~Copyable, E: Error>(
_ transform: (borrowing Wrapped) throws(E) -> U?
) throws(E) -> U? {
#if compiler(>=6.0) && $NoncopyableGenerics
switch self {
case .some(let y):
return try transform(y)
case .none:
return .none
}
#else
fatalError("Unsupported compiler")
#endif
}
}

Expand Down
7 changes: 3 additions & 4 deletions stdlib/public/core/Sendable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,12 @@
/// ### Sendable Metatypes
///
/// Metatypes such as `Int.Type` implicitly conform to the `Sendable` protocol.
#if $NoncopyableGenerics && $NonescapableTypes
#if $NonescapableTypes
@_marker public protocol Sendable: ~Copyable, ~Escapable { }
#elseif $NoncopyableGenerics
@_marker public protocol Sendable: ~Copyable { }
#else
@_marker public protocol Sendable { }
@_marker public protocol Sendable: ~Copyable { }
#endif

///
/// A type whose values can safely be passed across concurrency domains by copying,
/// but which disables some safety checking at the conformance site.
Expand Down
4 changes: 1 addition & 3 deletions stdlib/public/core/Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1272,9 +1272,7 @@ public struct IteratorSequence<Base: IteratorProtocol> {

extension IteratorSequence: IteratorProtocol, Sequence {

#if $NoncopyableGenerics
public typealias Element = Base.Element
#endif
public typealias Element = Base.Element

/// Advances to the next element and returns it, or `nil` if no next element
/// exists.
Expand Down

0 comments on commit b1bf693

Please sign in to comment.