Skip to content

[stdlib] Replace various uses of BlahSlice with Slice to reduce warnings #13263

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 3 commits into from
Dec 6, 2017
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ from gyb_stdlib_unittest_support import TRACE, stackTrace, trace
from gyb_stdlib_support import (
TRAVERSALS,
collectionForTraversal,
sliceTypeName,
collectionTypeName,
protocolsForCollectionFeatures
)
}%
Expand Down Expand Up @@ -508,8 +508,7 @@ Int64 distances.
% for Mutable in [ False, True ]:
% for RangeReplaceable in [ False, True ]:
% for StrideableIndex in [ False, True ]:
% SelfSlice = sliceTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
% Self = 'Minimal' + SelfSlice.replace('Slice', 'Collection')
% Self = 'Minimal' + collectionTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
% Self += 'WithStrideableIndex' if StrideableIndex else ''
% SelfProtocols = ', '.join(protocolsForCollectionFeatures(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable))
% Index = 'MinimalStrideableIndex' if StrideableIndex else 'MinimalIndex'
Expand Down Expand Up @@ -701,10 +700,10 @@ public struct ${Self}<T> : ${SelfProtocols} {
% end
}

public subscript(bounds: Range<${Index}>) -> ${SelfSlice}<${Self}<T>> {
public subscript(bounds: Range<${Index}>) -> Slice<${Self}<T>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the definition of SelfSlice too right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still used within the gyb. These tests create Minimal${SelfSlice} opaque types for some tests.

I did miss some more ${SelfSlice} uses tho.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No wait that is a different test. These ones just reuse SelfSlice to create MinimalCollection names. But still, they need something like it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt guilty after this so have fixed it properly now...

get {
_failEarlyRangeCheck(bounds, bounds: startIndex..<endIndex)
return ${SelfSlice}(base: self, bounds: bounds)
return Slice(base: self, bounds: bounds)
}
% if Mutable:
set {
Expand Down Expand Up @@ -853,10 +852,9 @@ public struct DefaultedSequence<Element> : Sequence {
% for Mutable in [ False, True ]:
% for RangeReplaceable in [ False, True ]:
% for StrideableIndex in [ False, True ]:
% SelfSlice = sliceTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
% Self = 'Defaulted' + SelfSlice.replace('Slice', 'Collection')
% Self = 'Defaulted' + collectionTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
% Self += 'WithStrideableIndex' if StrideableIndex else ''
% Base = 'Minimal' + SelfSlice.replace('Slice', 'Collection')
% Base = 'Minimal' + collectionTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
% Base += 'WithStrideableIndex' if StrideableIndex else ''
% SelfProtocols = ', '.join(protocolsForCollectionFeatures(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable))
% Index = 'MinimalStrideableIndex' if StrideableIndex else 'MinimalIndex'
Expand Down Expand Up @@ -973,10 +971,10 @@ public struct ${Self}<Element> : ${SelfProtocols} {
// FIXME: swift-3-indexing-model: use defaults.
// if Self not in ['DefaultedCollection', 'DefaultedBidirectionalCollection', 'DefaultedRandomAccessCollection', 'DefaultedMutableCollection', 'DefaultedRangeReplaceableCollection']:

public subscript(bounds: Range<${Index}>) -> ${SelfSlice}<${Self}<Base.Element>> {
public subscript(bounds: Range<${Index}>) -> Slice<${Self}<Base.Element>> {
get {
// FIXME: swift-3-indexing-model: range check.
return ${SelfSlice}(base: self, bounds: bounds)
return Slice(base: self, bounds: bounds)
}
% if Mutable:
set {
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/SDK/CoreAudio/CoreAudio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ extension UnsafeMutableAudioBufferListPointer
}

public subscript(bounds: Range<Int>)
-> MutableRandomAccessSlice<UnsafeMutableAudioBufferListPointer> {
-> Slice<UnsafeMutableAudioBufferListPointer> {
get {
return MutableRandomAccessSlice(base: self, bounds: bounds)
return Slice(base: self, bounds: bounds)
}
set {
_writeBackMutableSlice(&self, bounds: bounds, slice: newValue)
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/SDK/Dispatch/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable {
return ptr!.load(fromByteOffset: index - offset, as: UInt8.self)
}

public subscript(bounds: Range<Int>) -> RandomAccessSlice<DispatchData> {
return RandomAccessSlice(base: self, bounds: bounds)
public subscript(bounds: Range<Int>) -> Slice<DispatchData> {
return Slice(base: self, bounds: bounds)
}

/// Return a new copy of the data in a specified range.
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/SDK/Foundation/IndexSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
return indexSetRange.lowerBound..<indexSetRange.upperBound
}

public subscript(bounds: Range<Index>) -> BidirectionalSlice<RangeView> {
return BidirectionalSlice(base: self, bounds: bounds)
public subscript(bounds: Range<Index>) -> Slice<RangeView> {
return Slice(base: self, bounds: bounds)
}

public func index(after i: Index) -> Index {
Expand Down Expand Up @@ -237,8 +237,8 @@ public struct IndexSet : ReferenceConvertible, Equatable, BidirectionalCollectio
return index.value
}

public subscript(bounds: Range<Index>) -> BidirectionalSlice<IndexSet> {
return BidirectionalSlice(base: self, bounds: bounds)
public subscript(bounds: Range<Index>) -> Slice<IndexSet> {
return Slice(base: self, bounds: bounds)
}

// We adopt the default implementation of subscript(range: Range<Index>) from MutableCollection
Expand Down
2 changes: 0 additions & 2 deletions stdlib/public/core/Flatten.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from gyb_stdlib_support import (
TRAVERSALS,
collectionForTraversal,
sliceTypeName
)
}%

Expand Down Expand Up @@ -157,7 +156,6 @@ extension LazySequenceProtocol where Element : Sequence {
% if traversal == 'Bidirectional':
% constraints = '%(Base)sIterator.Element : BidirectionalCollection'
% Index = Collection + 'Index'
% Slice = sliceTypeName(traversal=traversal, mutable=False, rangeReplaceable=False)
/// A position in a `${Collection}`.
@_fixed_layout // FIXME(sil-serialize-all)
public struct ${Index}<BaseElements>
Expand Down
1 change: 0 additions & 1 deletion test/Prototypes/Algorithms.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ from gyb_stdlib_support import (
TRAVERSALS,
collectionForTraversal,
defaultIndicesForTraversal,
sliceTypeName
)

}%
Expand Down
4 changes: 2 additions & 2 deletions utils/gyb_stdlib_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def collectionForTraversal(traversal): # noqa (N802 function name should be low
raise ValueError("Unknown traversal %r" % traversal)


def sliceTypeName(traversal, mutable, rangeReplaceable): # noqa (N802)
name = collectionForTraversal(traversal).replace('Collection', 'Slice')
def collectionTypeName(traversal, mutable, rangeReplaceable): # noqa (N802)
name = collectionForTraversal(traversal)
if rangeReplaceable:
name = 'RangeReplaceable' + name
if mutable:
Expand Down
10 changes: 4 additions & 6 deletions validation-test/StdlibUnittest/SequencesCollections.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from gyb_stdlib_support import (
TRAVERSALS,
collectionForTraversal,
sliceTypeName,
protocolsForCollectionFeatures
protocolsForCollectionFeatures,
collectionTypeName
)

}%
Expand All @@ -22,8 +22,7 @@ import StdlibCollectionUnittest
// This comment is a workaround for <rdar://problem/18900352> gyb miscompiles nested loops
% for mutable in [ False, True ]:
// This comment is a workaround for <rdar://problem/18900352> gyb miscompiles nested loops
% SelfSlice = sliceTypeName(traversal=traversal, mutable=mutable, rangeReplaceable=False)
% Self = 'Minimal' + SelfSlice.replace('Slice', 'Collection')
% Self = 'Minimal' + collectionTypeName(traversal=traversal, mutable=mutable, rangeReplaceable=False)

var ${Self}TestSuite = TestSuite("${Self}")

Expand Down Expand Up @@ -116,8 +115,7 @@ ${Self}TestSuite.test("subscript(_:Index)/Set/DifferentCollections") {
%end

%for traversal in TRAVERSALS:
% SelfSlice = sliceTypeName(traversal=traversal, mutable=False, rangeReplaceable=True)
% Self = 'Minimal' + SelfSlice.replace('Slice', 'Collection')
% Self = 'Minimal' + collectionTypeName(traversal=traversal, mutable=False, rangeReplaceable=True)

func getTwoInterchangeable${Self}(_ elements: [Int])
-> (${Self}<OpaqueValue<Int>>, ${Self}<OpaqueValue<Int>>) {
Expand Down
5 changes: 2 additions & 3 deletions validation-test/stdlib/Collection/Inputs/Template.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from gyb_stdlib_support import (
TRAVERSALS,
collectionForTraversal,
sliceTypeName
)

import itertools
Expand All @@ -32,10 +31,10 @@ def all_tests():
test.base_kind = base_kind
test.mutable = mutable
test.range_replaceable = range_replaceable
test.base = base_kind + sliceTypeName(
test.base = base_kind + collectionTypeName(
traversal=traversal,
mutable=mutable,
rangeReplaceable=range_replaceable).replace('Slice', 'Collection')
rangeReplaceable=range_replaceable)
test.name = test.base + '.swift'
test.ref_name = test.base + 'OfRef.swift'
yield test
Expand Down
5 changes: 2 additions & 3 deletions validation-test/stdlib/CollectionType.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

% import os.path
% import gyb
% from gyb_stdlib_support import TRAVERSALS, collectionForTraversal, sliceTypeName, defaultIndicesForTraversal
% from gyb_stdlib_support import TRAVERSALS, collectionForTraversal, defaultIndicesForTraversal

import StdlibUnittest
import StdlibCollectionUnittest
Expand Down Expand Up @@ -829,7 +829,6 @@ func ==(lhs: FatalIndex, rhs: FatalIndex) -> Bool { fatalError() }
% for Traversal in TRAVERSALS:
% Collection = collectionForTraversal(Traversal)
% Self = 'Fatal' + Collection
% Slice = sliceTypeName(Traversal, False, False)
% Indices = defaultIndicesForTraversal(Traversal)

struct ${Self}<T> : ${Collection} {
Expand All @@ -847,7 +846,7 @@ CollectionTypeTests.test("AssociatedTypes/${Collection}") {
expectCollectionAssociatedTypes(
collectionType: C.self,
iteratorType: IndexingIterator<C>.self,
subSequenceType: ${Slice}<C>.self,
subSequenceType: Slice<C>.self,
indexType: FatalIndex.self,
indexDistanceType: Int.self,
indicesType: ${Indices}<C>.self)
Expand Down
4 changes: 2 additions & 2 deletions validation-test/stdlib/Join.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,14 @@ var JoinTestSuite = TestSuite("Join")

from gyb_stdlib_support import (
TRAVERSALS,
sliceTypeName
collectionTypeName
)

from itertools import product

base_kinds = [ 'Defaulted', 'Minimal' ]
collections = [
(base_kind + sliceTypeName(traversal=traversal, mutable=False, rangeReplaceable=True).replace('Slice', 'Collection'), traversal)
(base_kind + collectionTypeName(traversal=traversal, mutable=False, rangeReplaceable=True), traversal)
for base_kind, traversal in product(base_kinds, TRAVERSALS)
]
other_array_types = [ 'Array', 'ArraySlice', 'ContiguousArray' ]
Expand Down
29 changes: 15 additions & 14 deletions validation-test/stdlib/Slice.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
%{
from gyb_stdlib_support import (
TRAVERSALS,
sliceTypeName,
defaultIndicesForTraversal
defaultIndicesForTraversal,
collectionTypeName
)
}%

Expand Down Expand Up @@ -48,13 +48,12 @@ var SliceTests = TestSuite("Collection")
% for Traversal in TRAVERSALS:
% for Mutable in [ False, True ]:
% for RangeReplaceable in [ False, True ]:
% Slice = sliceTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
% Collection = 'Minimal' + Slice.replace('Slice', 'Collection')
% Collection = 'Minimal' + collectionTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)

SliceTests.test("${Slice}/AssociatedTypes") {
SliceTests.test("${Collection}.Slice/AssociatedTypes") {
do {
typealias Collection = ${Collection}<OpaqueValue<Int>>
typealias CollectionSlice = ${Slice}<Collection>
typealias CollectionSlice = Slice<Collection>
expectSliceType(CollectionSlice.self)
expectCollectionAssociatedTypes(
collectionType: CollectionSlice.self,
Expand All @@ -76,11 +75,12 @@ SliceTests.test("${Slice}/AssociatedTypes") {
}
}

SliceTests.test("${Slice}/init(base:bounds:)") {
SliceTests.test("${Collection}.Slice/init(base:bounds:)") {
for test in subscriptRangeTests {
let base = ${Collection}(elements: test.collection)
var slice = ${Slice}(base: base, bounds: test.bounds(in: base))
expectType(${Slice}<${Collection}<OpaqueValue<Int>>>.self, &slice)
var slice = Slice(base: base, bounds: test.bounds(in: base))
expectType(Slice<${Collection}<OpaqueValue<Int>>>.self, &slice)
expectType(${Collection}<OpaqueValue<Int>>.SubSequence.self, &slice)

checkCollection(
test.expected,
Expand All @@ -91,19 +91,20 @@ SliceTests.test("${Slice}/init(base:bounds:)") {
}

% if RangeReplaceable == False and Mutable == False:
SliceTests.test("${Slice}/baseProperty") {
SliceTests.test("${Collection}.Slice/baseProperty") {
let referenceCollection = ReferenceCollection()
let testSlice = ${Slice}(base: referenceCollection, bounds: 0..<1)
let testSlice = Slice(base: referenceCollection, bounds: 0..<1)
expectTrue(testSlice.base === referenceCollection)
}
% end

SliceTests.test("${Slice}.{startIndex,endIndex}") {
SliceTests.test("${Collection}.Slice.{startIndex,endIndex}") {
for test in subscriptRangeTests {
let c = ${Collection}(elements: test.collection)
let bounds = test.bounds(in: c)
var slice = ${Slice}(base: c, bounds: bounds)
expectType(${Slice}<${Collection}<OpaqueValue<Int>>>.self, &slice)
var slice = Slice(base: c, bounds: bounds)
expectType(Slice<${Collection}<OpaqueValue<Int>>>.self, &slice)
expectType(${Collection}<OpaqueValue<Int>>.SubSequence.self, &slice)

expectEqual(bounds.lowerBound, slice.startIndex)
expectEqual(bounds.upperBound, slice.endIndex)
Expand Down
6 changes: 3 additions & 3 deletions validation-test/stdlib/Slice/Inputs/Template.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from gyb_stdlib_support import (
TRAVERSALS,
collectionForTraversal,
sliceTypeName
collectionTypeName
)

import itertools
Expand All @@ -34,11 +34,11 @@ def all_tests():
test.base_kind = base_kind
test.mutable = mutable
test.range_replaceable = range_replaceable
test.base_slice = sliceTypeName(
test.base = base_kind + collectionTypeName(
traversal=traversal,
mutable=mutable,
rangeReplaceable=range_replaceable)
test.base = base_kind + test.base_slice.replace('Slice', 'Collection')

for name, prefix, suffix in [
('FullWidth', '[]', '[]'),
('WithPrefix', '[-9999, -9998, -9997]', '[]'),
Expand Down