From 65c8334b991c11a31e527b9e66e6ee765158c808 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Thu, 20 Apr 2017 13:11:21 -0700 Subject: [PATCH 1/2] [GSB] Hack: self-derived sources are showing up very late; ignore them. There's a more pervasive issue here that needs further study; essentially, we can end up with self-derived sources getting reinjected later, and will either need to avoid that reinjection or need to expand what this localized hack does, filtering out self-derived constraints when we enumerate requirements. --- lib/AST/GenericSignatureBuilder.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/AST/GenericSignatureBuilder.cpp b/lib/AST/GenericSignatureBuilder.cpp index 18c589cc3af78..6d649c9ea6b7f 100644 --- a/lib/AST/GenericSignatureBuilder.cpp +++ b/lib/AST/GenericSignatureBuilder.cpp @@ -4211,6 +4211,15 @@ static void computeDerivedSameTypeComponents( assert(componentOf.count(concrete.archetype) > 0); auto &component = components[componentOf[concrete.archetype]]; + // FIXME: Skip self-derived sources. This means our attempts to "stage" + // construction of self-derived sources really don't work, because we + // discover more information later, so we need a more on-line or + // iterative approach. + bool derivedViaConcrete; + if (concrete.source->isSelfDerivedSource(concrete.archetype, + derivedViaConcrete)) + continue; + // If it has a better source than we'd seen before for this component, // keep it. auto &bestConcreteTypeSource = component.concreteTypeSource; From 13f6c79b2a65b6347151ce3b0457fd462768e521 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Thu, 20 Apr 2017 13:18:32 -0700 Subject: [PATCH 2/2] [Stdlib] For Collections, the SubSequence of a Subsequence is SubSequence. Part of ABI FIXME #99, this gives us some nice consistency that ensures that slicing a SubSequence gives us another SubSequence. There are two source-compatibility implications to this change: * Collections now need to satisfy this property, which could not be expressed in Swift 3. There might be some Collections that don't satisfy this property, and will break with the Swift 4 compiler *even in Swift 3 compatibility mode*. Case in point... * The Lazy collection types were formulated as a lazy collection of the base slice (e.g., LazyCollection>) rather than as a slice of the lazy collection (e.g., Slice>). The former doesn't meet the new requirements, so change to the latter. --- .../StdlibCollectionUnittest/CheckCollectionType.swift.gyb | 1 - .../CheckMutableCollectionType.swift.gyb | 3 --- .../CheckRangeReplaceableCollectionType.swift | 3 --- stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb | 4 ---- stdlib/public/core/Collection.swift | 5 ++--- stdlib/public/core/ExistentialCollection.swift.gyb | 7 ++----- stdlib/public/core/LazyCollection.swift.gyb | 4 ++-- stdlib/public/core/Mirror.swift | 2 -- 8 files changed, 6 insertions(+), 23 deletions(-) diff --git a/stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb b/stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb index 77078aa39f224..8ce20401e2788 100644 --- a/stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb +++ b/stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb @@ -480,7 +480,6 @@ internal enum _SubSequenceSubscriptOnRangeMode { CollectionWithEquatableElement : %(protocol)s, %(subseq_as_collection)s C.SubSequence : %(protocol)s, - C.SubSequence.SubSequence == C.SubSequence, C.Indices : %(protocol)s, CollectionWithEquatableElement.Iterator.Element : Equatable ''' % locals() diff --git a/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb b/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb index a5a35d8dca425..ada6069fadeea 100644 --- a/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb +++ b/stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb @@ -122,7 +122,6 @@ extension TestSuite { collectionIsBidirectional: Bool = false ) where C.SubSequence : MutableCollection, - C.SubSequence.SubSequence == C.SubSequence, C.Indices : Collection, CollectionWithEquatableElement.Iterator.Element : Equatable, CollectionWithComparableElement.Iterator.Element : Comparable { @@ -785,7 +784,6 @@ self.test("\(testNamePrefix).partition/InvalidOrderings") { isFixedLengthCollection: Bool ) where C.SubSequence : BidirectionalCollection & MutableCollection, - C.SubSequence.SubSequence == C.SubSequence, C.Indices : BidirectionalCollection, CollectionWithEquatableElement.Iterator.Element : Equatable, CollectionWithComparableElement.Iterator.Element : Comparable { @@ -932,7 +930,6 @@ self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBuffer isFixedLengthCollection: Bool ) where C.SubSequence : RandomAccessCollection & MutableCollection, - C.SubSequence.SubSequence == C.SubSequence, C.Indices : RandomAccessCollection, CollectionWithEquatableElement.Iterator.Element : Equatable, CollectionWithComparableElement.Iterator.Element : Comparable { diff --git a/stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift b/stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift index d76ed3c215ff3..14363c64c71c1 100644 --- a/stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift +++ b/stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift @@ -463,7 +463,6 @@ extension TestSuite { collectionIsBidirectional: Bool = false ) where C.SubSequence : Collection, - C.SubSequence.SubSequence == C.SubSequence, C.Indices : Collection, CollectionWithEquatableElement.Iterator.Element : Equatable, CollectionWithEquatableElement.SubSequence : Collection { @@ -1182,7 +1181,6 @@ self.test("\(testNamePrefix).OperatorPlus") { outOfBoundsIndexOffset: Int = 1 ) where C.SubSequence : BidirectionalCollection & RangeReplaceableCollection, - C.SubSequence.SubSequence == C.SubSequence, C.Indices : BidirectionalCollection, CollectionWithEquatableElement.Iterator.Element : Equatable { @@ -1305,7 +1303,6 @@ self.test("\(testNamePrefix).removeLast(n: Int)/whereIndexIsBidirectional/remove outOfBoundsIndexOffset: Int = 1 ) where C.SubSequence : RandomAccessCollection & RangeReplaceableCollection, - C.SubSequence.SubSequence == C.SubSequence, C.Indices : RandomAccessCollection, CollectionWithEquatableElement.Iterator.Element : Equatable { diff --git a/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb b/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb index ef6967fbce503..e904e7e7b303a 100644 --- a/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb +++ b/stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb @@ -367,7 +367,6 @@ public func expect${Mutable}CollectionType( X.SubSequence : Collection, % end // X.SubSequence.Indices == X.Indices, // FIXME(ABI)#3 (Recursive Protocol Constraints): can't have this constraint now. - X.SubSequence.SubSequence == X.SubSequence, X.Indices : Collection {} % end @@ -411,7 +410,6 @@ public func expectCollectionAssociatedTypes( // the 'where' clause, all of these should be required by the protocol. X.SubSequence : Collection, // X.SubSequence.Indices == X.Indices, // FIXME(ABI)#7 (Recursive Protocol Constraints): can't have this constraint now. - X.SubSequence.SubSequence == X.SubSequence, X.Indices : Collection {} /// Check that all associated types of a `BidirectionalCollection` are what we @@ -428,7 +426,6 @@ public func expectBidirectionalCollectionAssociatedTypes where Self.SubSequence.Index == Index, - Self.Iterator.Element == Self.SubSequence.Iterator.Element + Self.Iterator.Element == Self.SubSequence.Iterator.Element, + SubSequence.SubSequence == SubSequence // FIXME(ABI)#98 (Recursive Protocol Constraints): // FIXME(ABI)#99 (Associated Types with where clauses): // associatedtype SubSequence : Collection // where - // , // SubSequence.Indices == Indices, - // SubSequence.SubSequence == SubSequence // // ( Implement recursive protocol // constraints) diff --git a/stdlib/public/core/ExistentialCollection.swift.gyb b/stdlib/public/core/ExistentialCollection.swift.gyb index 8b8db4c54b432..6cdb79d3c19cb 100644 --- a/stdlib/public/core/ExistentialCollection.swift.gyb +++ b/stdlib/public/core/ExistentialCollection.swift.gyb @@ -430,13 +430,11 @@ internal final class _${Kind}Box : _Any${Kind}Box C.SubSequence : ${SubProtocol}, C.SubSequence.Iterator.Element == Element, C.SubSequence.Indices : ${SubProtocol}, - C.SubSequence.SubSequence == C.SubSequence, C.Indices : ${SubProtocol} { // Traversal: ${Traversal} diff --git a/stdlib/public/core/LazyCollection.swift.gyb b/stdlib/public/core/LazyCollection.swift.gyb index 7bc7519aa165e..76e50cb57b27a 100644 --- a/stdlib/public/core/LazyCollection.swift.gyb +++ b/stdlib/public/core/LazyCollection.swift.gyb @@ -163,8 +163,8 @@ extension ${Self} : ${TraversalCollection} { /// /// - Complexity: O(1) @_inlineable - public subscript(bounds: Range) -> ${Self}<${Slice}> { - return ${Slice}(base: _base, bounds: bounds).lazy + public subscript(bounds: Range) -> ${Slice}<${Self}> { + return ${Slice}(base: self, bounds: bounds) } /// A Boolean value indicating whether the collection is empty. diff --git a/stdlib/public/core/Mirror.swift b/stdlib/public/core/Mirror.swift index b689a29e67b55..c2d319e7ea5fc 100644 --- a/stdlib/public/core/Mirror.swift +++ b/stdlib/public/core/Mirror.swift @@ -220,7 +220,6 @@ public struct Mirror { // associated types of Collection. C.SubSequence : Collection, C.SubSequence.Indices : Collection, - C.SubSequence.SubSequence == C.SubSequence, C.Indices : Collection { self.subjectType = Subject.self @@ -272,7 +271,6 @@ public struct Mirror { // FIXME(ABI)#48 (Associated Types with where clauses): these constraints should be applied to // associated types of Collection. C.SubSequence : Collection, - C.SubSequence.SubSequence == C.SubSequence, C.Indices : Collection { self.subjectType = Subject.self