-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SE-0157] Standard library uses of Recursive Protocol Constraints #11923
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
[SE-0157] Standard library uses of Recursive Protocol Constraints #11923
Conversation
fdd5482
to
17df27f
Compare
@swift-ci please smoke test |
@swift-ci please test source compatibility |
Note: rebased so the compiler changes don't show up in this pull request. Now it's all library + test suite updates. Also, improved the |
17df27f
to
0e81e08
Compare
I have been waiting for this for years! Thanks, Doug! |
Wonderful to see! |
@gribozavr He lives! |
Type checker slowdowns have not been fixed yet; I'm collecting the standard library improvements here, and pushing the compiler improvements into master via separate PRs. I won't merge this until compile-time performance is acceptable. |
@gribozavr, your standard library annotations are invaluable in rolling out this feature. |
6fe6ec0
to
8135593
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎆
FWIW, most of those hacks were due to an intermediate compiler state and are no longer an issue. I'll update the PR soonish... I'm testing the local removal of said hacks. |
a2aef31
to
4aa8471
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
Build failed |
@swift-ci please test source compatibility |
That GSB commit doesn't belong here; I'll zap it later. |
Build failed |
Well, that's encouraging! |
4aa8471
to
0e82dee
Compare
@slavapestov that last commit's for you |
Any chance you could throw |
Addressed ABI FIXME’s #4, swiftlang#5, swiftlang#104 and swiftlang#105, making Sequence’s SubSequence conform to Sequence, with the same element type, and for which the SubSequence of a SubSequence is the same SubSequence. Fixes SR-318 / rdar://problem/31418206.
…ection. Introduce (recursive) constraints that make the *Collection constraint of SubSequence match that of its enclosing *Collection, e.g., MutableCollection.SubSequence conforms to MutableCollection. Fixes rdar://problem/20715031 and more of SR-3453.
Make the Indices types conform to the appropriate Collection protocol: * Collection.Indices: Collection * BidirectionalCollection.Indices: BidirectionalCollection * RandomAccessCollection.Indices: RandomAccessCollection
…traints. Eliminates a few explicit uses of the Indexable protocols.
Rather than using the default slice type when slicing the collection produced by a lazy map or filter, slice the base collection and form a new lazy map/filter collection from it. This allows any optimizations provided by the collection SubSequence type to kick in, as well as ensuring that slicing a lazy collection provides the same type as producing a lazy collection of a slice. This is technically source-breaking, because someone could have spelled out the types of slicing a lazy filter or map… but it seems unlikely to matter in practice and the benefits could be significant. Fixes ABI FIXME’s swiftlang#28 and swiftlang#46.
The various _*Indexable protocols only exist to work around the lack of recursive protocol constraints. Eliminate all of the *_Indexable protocols, collapsing their requirements into the corresponding Collection protocol (e.g., _MutableIndexable —> Collection). This introduces a number of extraneous requirements into the various Collection protocols to work around bugs in associated type inference. Specifically, to work around the lack of "global" inference of associated type witnesses. These hacks were implicitly present in the *Indexable protocols; I've made marked them as ABI FIXMEs here so we can remove them when associated type inference improves. Fixes rdar://problem/21935030 and a number of ABI FIXMEs in the library.
430a86d
to
772352e
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
@swift-ci please test |
Build failed |
@swift-ci please test source compatibility |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
Fixed a crasher. Huh. |
@swift-ci please smoke test and merge |
1 similar comment
@swift-ci please smoke test and merge |
This pull request implements the standard library part of SE-0157: Recursive Protocol Constraints, which includes:
SubSequence
associated type have the same capabilities as its enclosing protocol, e.g.,Sequence.SubSequence
conforms toSequence
,Collection.SubSequence
conforms toCollection
, and so on.Indices
associated type have the same traversal requirements as its enclosing protocol, e.g.,Collection.Indices
conforms toCollection
,BidirectionalCollection.Indices
conforms toBidirectionalCollection
, and so onNumeric.Magnitude
conform toNumeric
SubSequence
types for lazy filter and map*Indexable
protocols.Fixes SR-3453 and rdar://problem/20715031 rdar://problem/28330668.