Skip to content

[stdlib] Limit ranged subscript default implementations #12582

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

Closed
wants to merge 1 commit into from
Closed
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
44 changes: 25 additions & 19 deletions stdlib/public/core/MutableCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,26 @@ extension MutableCollection {
) rethrows -> R? {
return nil
}

/// Exchanges the values at the specified indices of the collection.
///
/// Both parameters must be valid indices of the collection that are not
/// equal to `endIndex`. Calling `swapAt(_:_:)` with the same index as both
/// `i` and `j` has no effect.
///
/// - Parameters:
/// - i: The index of the first value to swap.
/// - j: The index of the second value to swap.
@_inlineable
public mutating func swapAt(_ i: Index, _ j: Index) {
guard i != j else { return }
let tmp = self[i]
self[i] = self[j]
self[j] = tmp
}
}

extension MutableCollection where SubSequence == MutableSlice<Self> {
/// Accesses a contiguous subrange of the collection's elements.
///
/// The accessed slice uses the same indices for the same elements as the
Expand Down Expand Up @@ -226,26 +245,11 @@ extension MutableCollection {
_writeBackMutableSlice(&self, bounds: bounds, slice: newValue)
}
}

/// Exchanges the values at the specified indices of the collection.
///
/// Both parameters must be valid indices of the collection that are not
/// equal to `endIndex`. Calling `swapAt(_:_:)` with the same index as both
/// `i` and `j` has no effect.
///
/// - Parameters:
/// - i: The index of the first value to swap.
/// - j: The index of the second value to swap.
@_inlineable
public mutating func swapAt(_ i: Index, _ j: Index) {
guard i != j else { return }
let tmp = self[i]
self[i] = self[j]
self[j] = tmp
}
}

extension MutableCollection where Self: BidirectionalCollection {
extension MutableCollection
where SubSequence == MutableBidirectionalSlice<Self>
{
@_inlineable // FIXME(sil-serialize-all)
public subscript(bounds: Range<Index>) -> MutableBidirectionalSlice<Self> {
get {
Expand All @@ -258,7 +262,9 @@ extension MutableCollection where Self: BidirectionalCollection {
}
}

extension MutableCollection where Self: RandomAccessCollection {
extension MutableCollection
where SubSequence == MutableRandomAccessSlice<Self>
{
@_inlineable // FIXME(sil-serialize-all)
public subscript(bounds: Range<Index>) -> MutableRandomAccessSlice<Self> {
get {
Expand Down
7 changes: 0 additions & 7 deletions stdlib/public/core/RangeReplaceableCollection.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,6 @@ public protocol RangeReplaceableCollection : Collection
//===----------------------------------------------------------------------===//

extension RangeReplaceableCollection {
@_inlineable
public subscript(bounds: Range<Index>) -> RangeReplaceableSlice<Self> {
return RangeReplaceableSlice(base: self, bounds: bounds)
}

/// Creates a new collection containing the specified number of a single,
/// repeated value.
///
Expand Down Expand Up @@ -657,7 +652,6 @@ extension RangeReplaceableCollection {
// collections.

% for capability in ['', 'Bidirectional', 'RandomAccess']:
% if capability:
extension RangeReplaceableCollection where
Self.SubSequence == RangeReplaceable${capability}Slice<Self> {
@_inlineable // FIXME(sil-serialize-all)
Expand All @@ -666,7 +660,6 @@ extension RangeReplaceableCollection where
return RangeReplaceable${capability}Slice(base: self, bounds: bounds)
}
}
% end

extension RangeReplaceableCollection where
Self.SubSequence == MutableRangeReplaceable${capability}Slice<Self>
Expand Down