[3.1] Fix source compatibility problems with conforming to multiple Collection axes at once. #7151
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Explanation: Improvements to the type checker and standard library in Swift 3.1 exposed the lack of default implementations for a
SubSequence
type and slicing operator when a type conformed to multiple axes ofCollection
simultaneously (Mutable
vs non,RangeReplaceable
vs non, and/or forward,Bidirectional
orRandomAccess
). Providing those default implementations then exposed remaining deficiencies in our handling of potential witnesses for associated type inference. This patch fixes these issues by constraining the type checker to only filter and compare witnesses by the constraints they require of theSelf
type, which are invariant of what associated types we end up inferring, and then filling in the missing default implementations in the standard library.Scope: Many users writing custom collection types report this as a compatibility regression from 3.0.
Issue: rdar://problem/30228957
Risk: Moderate; there is a nonzero chance of knock-on effects. However, not taking this patch means that a large class of useful programs that compiled in 3.0 won't compile in 3.1 without boilerplatey source changes that get incorrectly rejected in 3.0, making it impossible to get code working in both versions. (See realm/realm-swift#4586 (comment) for an example.)
Testing: Swift CI; realm-swift project