Skip to content

Make standard types conform BitwiseCopyable #83608

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions stdlib/public/core/ClosedRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,9 @@ extension ClosedRange {
}
}

extension ClosedRange: BitwiseCopyable where Bound: BitwiseCopyable {}
extension ClosedRange.Index: BitwiseCopyable where Bound: BitwiseCopyable {}

// Note: this is not for compatibility only, it is considered a useful
// shorthand. TODO: Add documentation
public typealias CountableClosedRange<Bound: Strideable> = ClosedRange<Bound>
Expand Down
3 changes: 3 additions & 0 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ extension IndexingIterator: IteratorProtocol, Sequence {
}
}

extension IndexingIterator: BitwiseCopyable
where Elements: BitwiseCopyable, Elements.Index: BitwiseCopyable {}

extension IndexingIterator: Sendable
where Elements: Sendable, Elements.Index: Sendable { }

Expand Down
5 changes: 5 additions & 0 deletions stdlib/public/core/CollectionOfOne.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ extension CollectionOfOne: CustomDebugStringConvertible {
}
}

extension CollectionOfOne: BitwiseCopyable
where Element: BitwiseCopyable { }
extension CollectionOfOne.Iterator: BitwiseCopyable
where Element: BitwiseCopyable { }

#if SWIFT_ENABLE_REFLECTION
extension CollectionOfOne: CustomReflectable {
public var customMirror: Mirror {
Expand Down
5 changes: 5 additions & 0 deletions stdlib/public/core/EnumeratedSequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public struct EnumeratedSequence<Base: Sequence> {
}
}

extension EnumeratedSequence: BitwiseCopyable where Base: BitwiseCopyable {}

extension EnumeratedSequence: Sendable where Base: Sendable {}

extension EnumeratedSequence {
Expand Down Expand Up @@ -71,6 +73,9 @@ extension EnumeratedSequence {
}
}

extension EnumeratedSequence.Iterator: BitwiseCopyable
where Base.Iterator: BitwiseCopyable {}

extension EnumeratedSequence.Iterator: Sendable where Base.Iterator: Sendable {}

extension EnumeratedSequence.Iterator: IteratorProtocol, Sequence {
Expand Down
9 changes: 9 additions & 0 deletions stdlib/public/core/Flatten.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public struct FlattenSequence<Base: Sequence> where Base.Element: Sequence {
}
}

extension FlattenSequence: BitwiseCopyable where Base: BitwiseCopyable {}

extension FlattenSequence: Sendable where Base: Sendable {}

extension FlattenSequence {
Expand All @@ -56,6 +58,10 @@ extension FlattenSequence {
}
}

extension FlattenSequence.Iterator: BitwiseCopyable
where Base.Iterator: BitwiseCopyable,
Base.Element.Iterator: BitwiseCopyable {}

extension FlattenSequence.Iterator: Sendable
where Base.Iterator: Sendable, Base.Element.Iterator: Sendable {}

Expand Down Expand Up @@ -167,6 +173,9 @@ extension FlattenSequence where Base: Collection, Base.Element: Collection {
}
}

extension FlattenSequence.Index: BitwiseCopyable
where Base.Index: BitwiseCopyable, Base.Element.Index: BitwiseCopyable {}

extension FlattenSequence.Index: Sendable
where Base.Index: Sendable, Base.Element.Index: Sendable {}

Expand Down
3 changes: 3 additions & 0 deletions stdlib/public/core/Indices.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,8 @@ extension Collection where Indices == DefaultIndices<Self> {
}
}

extension DefaultIndices: BitwiseCopyable
where Elements: BitwiseCopyable, Elements.Index: BitwiseCopyable { }

extension DefaultIndices: Sendable
where Elements: Sendable, Elements.Index: Sendable { }
2 changes: 2 additions & 0 deletions stdlib/public/core/LazySequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ public struct LazySequence<Base: Sequence> {
}
}

extension LazySequence: BitwiseCopyable where Base: BitwiseCopyable {}

extension LazySequence: Sendable where Base: Sendable {}

extension LazySequence: Sequence {
Expand Down
11 changes: 11 additions & 0 deletions stdlib/public/core/Range.swift
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ public struct PartialRangeUpTo<Bound: Comparable> {
public init(_ upperBound: Bound) { self.upperBound = upperBound }
}

extension PartialRangeUpTo: BitwiseCopyable where Bound: BitwiseCopyable {}

extension PartialRangeUpTo: RangeExpression {
@_transparent
public func relative<C: Collection>(to collection: C) -> Range<Bound>
Expand Down Expand Up @@ -559,6 +561,8 @@ public struct PartialRangeThrough<Bound: Comparable> {
public init(_ upperBound: Bound) { self.upperBound = upperBound }
}

extension PartialRangeThrough: BitwiseCopyable where Bound: BitwiseCopyable {}

extension PartialRangeThrough: RangeExpression {
@_transparent
public func relative<C: Collection>(to collection: C) -> Range<Bound>
Expand Down Expand Up @@ -676,6 +680,8 @@ public struct PartialRangeFrom<Bound: Comparable> {
public init(_ lowerBound: Bound) { self.lowerBound = lowerBound }
}

extension PartialRangeFrom: BitwiseCopyable where Bound: BitwiseCopyable {}

extension PartialRangeFrom: RangeExpression {
@_transparent
public func relative<C: Collection>(
Expand Down Expand Up @@ -723,6 +729,9 @@ extension PartialRangeFrom: Sequence
}
}

extension PartialRangeFrom.Iterator: BitwiseCopyable
where Bound: BitwiseCopyable {}

@_unavailableInEmbedded
extension PartialRangeFrom: Decodable where Bound: Decodable {
public init(from decoder: Decoder) throws {
Expand Down Expand Up @@ -1109,6 +1118,8 @@ extension Range {
}
}

extension Range: BitwiseCopyable where Bound: BitwiseCopyable {}

// Note: this is not for compatibility only, it is considered a useful
// shorthand. TODO: Add documentation
public typealias CountableRange<Bound: Strideable> = Range<Bound>
Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/core/Repeat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@ public func repeatElement<T>(_ element: T, count n: Int) -> Repeated<T> {
return Repeated(_repeating: element, count: n)
}

extension Repeated: BitwiseCopyable where Element: BitwiseCopyable {}

extension Repeated: Sendable where Element: Sendable { }
8 changes: 8 additions & 0 deletions stdlib/public/core/Reverse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public struct ReversedCollection<Base: BidirectionalCollection> {
}
}

extension ReversedCollection: BitwiseCopyable where Base: BitwiseCopyable {}

extension ReversedCollection: Sendable where Base: Sendable {}

extension ReversedCollection {
Expand All @@ -85,6 +87,9 @@ extension ReversedCollection {
}
}

extension ReversedCollection.Iterator: BitwiseCopyable
where Base: BitwiseCopyable, Base.Index: BitwiseCopyable {}

extension ReversedCollection.Iterator: Sendable
where Base: Sendable, Base.Index: Sendable {}

Expand Down Expand Up @@ -175,6 +180,9 @@ extension ReversedCollection {
}
}

extension ReversedCollection.Index: BitwiseCopyable
where Base.Index: BitwiseCopyable {}

extension ReversedCollection.Index: Sendable where Base.Index: Sendable {}

extension ReversedCollection.Index: Comparable {
Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/core/SIMDVector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,8 @@ public struct SIMDMask<Storage>: SIMD
}
}

extension SIMDMask: BitwiseCopyable where Storage: BitwiseCopyable {}

extension SIMDMask: Sendable where Storage: Sendable {}

extension SIMDMask {
Expand Down
15 changes: 15 additions & 0 deletions stdlib/public/core/Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ public struct DropFirstSequence<Base: Sequence> {
}
}

extension DropFirstSequence: BitwiseCopyable where Base: BitwiseCopyable {}

extension DropFirstSequence: Sendable where Base: Sendable {}

extension DropFirstSequence: Sequence {
Expand Down Expand Up @@ -534,6 +536,8 @@ public struct PrefixSequence<Base: Sequence> {
}
}

extension PrefixSequence: BitwiseCopyable where Base: BitwiseCopyable {}

extension PrefixSequence: Sendable where Base: Sendable {}

extension PrefixSequence {
Expand All @@ -552,6 +556,9 @@ extension PrefixSequence {
}
}

extension PrefixSequence.Iterator: BitwiseCopyable
where Base.Iterator: BitwiseCopyable {}

extension PrefixSequence.Iterator: Sendable where Base.Iterator: Sendable {}

extension PrefixSequence.Iterator: IteratorProtocol {
Expand Down Expand Up @@ -611,6 +618,9 @@ public struct DropWhileSequence<Base: Sequence> {
}
}

extension DropWhileSequence: BitwiseCopyable
where Base.Iterator: BitwiseCopyable, Element: BitwiseCopyable {}

extension DropWhileSequence: Sendable
where Base.Iterator: Sendable, Element: Sendable {}

Expand All @@ -630,6 +640,9 @@ extension DropWhileSequence {
}
}

extension DropWhileSequence.Iterator: BitwiseCopyable
where Base.Iterator: BitwiseCopyable, Element: BitwiseCopyable {}

extension DropWhileSequence.Iterator: Sendable
where Base.Iterator: Sendable, Element: Sendable {}

Expand Down Expand Up @@ -1291,6 +1304,8 @@ extension IteratorSequence: IteratorProtocol, Sequence {
}
}

extension IteratorSequence: BitwiseCopyable where Base: BitwiseCopyable {}

extension IteratorSequence: Sendable where Base: Sendable { }

/* FIXME: ideally for compatibility we would declare
Expand Down
3 changes: 3 additions & 0 deletions stdlib/public/core/Slice.swift
Original file line number Diff line number Diff line change
Expand Up @@ -529,5 +529,8 @@ extension Slice
}
}

extension Slice: BitwiseCopyable
where Base: BitwiseCopyable, Base.Index: BitwiseCopyable {}

extension Slice: Sendable
where Base: Sendable, Base.Index: Sendable { }
9 changes: 9 additions & 0 deletions stdlib/public/core/Stride.swift
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,15 @@ public func stride<T>(
return StrideThrough(_start: start, end: end, stride: stride)
}

extension StrideToIterator: BitwiseCopyable
where Element: BitwiseCopyable, Element.Stride: BitwiseCopyable { }
extension StrideTo: BitwiseCopyable
where Element: BitwiseCopyable, Element.Stride: BitwiseCopyable { }
extension StrideThroughIterator: BitwiseCopyable
where Element: BitwiseCopyable, Element.Stride: BitwiseCopyable { }
extension StrideThrough: BitwiseCopyable
where Element: BitwiseCopyable, Element.Stride: BitwiseCopyable { }

extension StrideToIterator: Sendable
where Element: Sendable, Element.Stride: Sendable { }
extension StrideTo: Sendable
Expand Down
2 changes: 2 additions & 0 deletions stdlib/public/core/UnicodeParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ extension Unicode {
public typealias Parser = _UnicodeParser
}

extension Unicode.ParseResult: BitwiseCopyable where T: BitwiseCopyable {}

extension Unicode.ParseResult: Sendable where T: Sendable { }
6 changes: 6 additions & 0 deletions stdlib/public/core/Zip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ extension Zip2Sequence: Sequence {
}
}

extension Zip2Sequence: BitwiseCopyable where Sequence1: BitwiseCopyable,
Sequence2: BitwiseCopyable { }
extension Zip2Sequence.Iterator: BitwiseCopyable
where Sequence1.Iterator: BitwiseCopyable,
Sequence2.Iterator: BitwiseCopyable { }

extension Zip2Sequence: Sendable where Sequence1: Sendable,
Sequence2: Sendable { }
extension Zip2Sequence.Iterator: Sendable where Sequence1.Iterator: Sendable,
Expand Down