-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[stdlib][WIP perf experiment] Replace AnySequence with Array in default Sequence methods #9639
Conversation
I don't really have time to advise on this but I'll suggest that you build some small models of the feature you're trying to add, outside of the standard library, to understand how the language works before jumping into changing stdlib code. It looks like you're expecting Array to resolve overloads that require AnySequence, but those are unrelated types. |
2ea0bb8
to
b37bcaf
Compare
@dabrahams, @airspeedswift, @moiseev, @gottesmm Could you point me in the right direction here? |
@palimondo what if you try to specify the |
@moiseev How does one explicitly specify associated type in default implementation? Can I do |
b37bcaf
to
f579944
Compare
Can I get a benchmark, please? |
@palimondo You should be able to ask swift-ci to do that. Can you try: 'Please smoke benchmark'? |
@swift-ci Please smoke benchmark |
Build comment file:Build failed before running benchmark. |
f579944
to
7d5fadf
Compare
@moiseev AFAIK CI bot listening to you requires commit access which I don't have yet. BTW where is the link to the failed build? // @shahmishal @swift-ci Please smoke benchmark |
@swift-ci Please smoke benchmark |
Build comment file:Build failed before running benchmark. |
@shahmishal Why aren't there any links to failing build here? After searching around a lot on Jenkins I found the failing build. My changes are crashing the compiler... filed SR-4988. |
@swift-ci Please smoke benchmark |
From the build Log: Setting status of f579944fcdf129893dc59ac3154fd8c490496585 to FAILURE with url https://ci.swift.org/job/swift-PR-osx-smoke-perf/97/ and message: 'Build finished. ' Did you force push to this PR? If yes, it's known bug with GitHub PR testing. |
@shahmishal Indeed I force pushed. There's no need to try to build again now, it crashes the compiler. |
Build comment file:Build failed before running benchmark. |
@dabrahams Could you please have a quick look over the changes in |
These changes would fail with infinite input sequences, wouldn't they? |
Yes, it would fail with infinite input sequences, as is the case with all other non-lazy methods on At the moment this initial commit has only extracted the inner classes into their own files without any changes. Second part is to properly implement But extracting out the lazy implementations would allow the default methods to just always return |
My point is that to handle infinite sequences you should explicitly use |
294ef36
to
dd6d50d
Compare
#20221 has removed AnySequence as return type from sequence slicing operations. 🎉 |
This is an experiment to confirm that replacing AnySequence in default methods on Sequence with Array improves performance. This is a supporting argument to SE-NNNN Sequence Cleanup.
At the moment, I don't know if the replacement implementations work correctly, because the code as is does not compile. I seem to misunderstand something fundamental here and would appreciate getting educated. Please advise @dabrahams, @airspeedswift, @moiseev, @gottesmm, @atrick.
My original reasoning is that
associatedtype SubSequence
defined inprotocol Sequence
ensures same return type of following methods:dropFirst
,dropLast
,drop(while:)
,prefix
,prefix(while:)
. Another requirement that can not be expressed in Swift type system at the moment (recursive protocol constraints) is thatSubSequence
conforms toSequence
.For a lot of types in stdlib, the Sequence conformance is provided by the default implementation in
extension Sequence
inSequence.swift
. And I thought replacingAnySequence<Element>
with[Element]
— here I assume it's just syntactic sugar forArray<Element>
— would just work. But stdlib with this change does not compile. According to the first error, my modified implementation (please see diff) fails to provideSequence
conformance forEnumeratedIterator
:Am I missing something fundamental? Is this some kind of compiler bug? Is it related to the most recent changes in #8990?