Skip to content

[stdlib] Implement slice Indices using their base Indices #12277

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 2 commits into from
Oct 5, 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
15 changes: 4 additions & 11 deletions stdlib/public/core/Indices.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public struct ${Self}<
Elements : ${collectionForTraversal(Traversal)}
> : ${collectionForTraversal(Traversal)} {

// FIXME(compiler limitation): this typealias should be inferred.
public typealias Index = Elements.Index
public typealias Indices = ${Self}<Elements>

@_inlineable
@_versioned
Expand All @@ -50,12 +50,12 @@ public struct ${Self}<
}

@_inlineable
public var startIndex: Elements.Index {
public var startIndex: Index {
return _startIndex
}

@_inlineable
public var endIndex: Elements.Index {
public var endIndex: Index {
return _endIndex
}

Expand All @@ -65,7 +65,6 @@ public struct ${Self}<
return i
}

// FIXME(compiler limitation): this typealias should be inferred.
public typealias SubSequence = ${Self}<Elements>

@_inlineable
Expand Down Expand Up @@ -103,9 +102,6 @@ public struct ${Self}<
}
% end

// FIXME(compiler limitation): this typealias should be inferred.
public typealias Indices = ${Self}<Elements>

@_inlineable
public var indices: Indices {
return self
Expand All @@ -120,10 +116,7 @@ public struct ${Self}<
}

extension ${collectionForTraversal(Traversal)}
% if Traversal != 'RandomAccess':
where Indices == ${Self}<Self>
% end
{
where Indices == ${Self}<Self> {
/// The indices that are valid for subscripting the collection, in ascending
/// order.
///
Expand Down
14 changes: 5 additions & 9 deletions stdlib/public/core/Slice.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ public struct ${Self}<Base : ${BaseRequirements}>
: ${SelfProtocols} {

public typealias Index = Base.Index
public typealias IndexDistance = Base.IndexDistance
public typealias Indices = ${Indices}<${Self}<Base>>
public typealias IndexDistance = Base.IndexDistance

public var _startIndex: Index
public var _endIndex: Index
Expand Down Expand Up @@ -164,13 +163,10 @@ public struct ${Self}<Base : ${BaseRequirements}>
% end
}

// FIXME(ABI)#67 (Associated Types with where clauses):
//
// public typealias Indices = Base.Indices
// public var indices: Indices { ... }
//
// We can't do it right now because we don't have enough
// constraints on the Base.Indices type in this context.
public typealias Indices = Base.Indices
public var indices: Indices {
return _base.indices[_startIndex..<_endIndex]
}

@_inlineable // FIXME(sil-serialize-all)
public func index(after i: Index) -> Index {
Expand Down
2 changes: 1 addition & 1 deletion validation-test/stdlib/Slice.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ SliceTests.test("${Slice}/AssociatedTypes") {
subSequenceType: CollectionSlice.self,
indexType: MinimalIndex.self,
indexDistanceType: Int.self,
indicesType: ${defaultIndicesForTraversal(Traversal)}<CollectionSlice>.self)
indicesType: Collection.Indices.self)
}

func checkStaticTypealiases1<Base : Collection>(_: Base) {
Expand Down