-
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] Adopt conditional conformance for Indices, Slice, ReversedCollection #12913
[stdlib] Adopt conditional conformance for Indices, Slice, ReversedCollection #12913
Conversation
Wow that's a lot of deleted code. |
stdlib/public/core/Indices.swift
Outdated
_elements: self, | ||
startIndex: self.startIndex, | ||
endIndex: self.endIndex) | ||
} | ||
} | ||
|
||
% end | ||
public typealias DefaultBidirectionalIndices<T: BidirectionalCollection> = DefaultIndices<T> |
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.
Deprecated in swift 4.1, perhaps?
@@ -1,4 +1,4 @@ | |||
//===--- RangeReplaceableCollection.swift.gyb -----------------*- swift -*-===// | |||
//===--- RangeReplaceableCollection.swift -----------------*- swift -*-===// |
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.
Notpick: No longer 80 columns.
stdlib/public/core/Reverse.swift
Outdated
public let _base: Base | ||
} | ||
@available(*, deprecated, renamed: "ReversedCollection") | ||
typealias ReversedRandomAccessCollection<T> = ReversedCollection<T> where T: RandomAccessCollection |
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.
public
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.
This is so great! 👏👏👏
stdlib/public/core/Indices.swift
Outdated
} | ||
} | ||
|
||
extension DefaultIndices: RandomAccessCollection where Elements: RandomAccessCollection { } |
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.
Need to make sure we're forwarding distance(to:) and index(_:offsetBy:) to the underlying collection.
stdlib/public/core/Reverse.swift
Outdated
public var endIndex: Index { | ||
return ReversedRandomAccessIndex(_base.startIndex) | ||
} | ||
extension ReversedCollection: RandomAccessCollection where Base: RandomAccessCollection { } |
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.
Here too — need the index-moving methods.
24b532b
to
41af770
Compare
The first compiler crash this hits is: https://bugs.swift.org/browse/SR-6466 |
stdlib/public/core/Reverse.swift
Outdated
/// | ||
/// - Complexity: O(1) | ||
@_inlineable | ||
public func reversed() -> LazyRandomAccessCollection< |
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.
Whoops, we still need this, up until the point where the Lazy collections also use conditional conformances
f348ce3
to
ce4d924
Compare
@swift-ci Please smoke test macOS platform |
@airspeedswift , that last commit re-breaks the test. The gyb'd conformances are redundant, so we (correctly) "redundant conformance" errors. Why did you revert my change? Because it uncovered a source-compatibility issue? |
@swift-ci please test source compatibility |
1 similar comment
@swift-ci please test source compatibility |
Quite curious how this fares on the compatibility suite in its current state. |
Note that all of the test suite failure other that the |
... and the crash appears to be in the
|
The Plank and R failures are the SwiftPM failure under discussion in swiftlang/swift-package-manager#1393, so this isn't introducing any source-compatibility regressions. |
Turns out that we don't need that big pile of explicit typealiases in the standard library now that I've reinstated the associated type redeclarations in the |
@DougGregor sorry, I thought that was reverting a change I made from before you restricted the feature to only stdlib use (looks like the test was failing due to using the restricted feature). Yeah, if that original code doesn't compile, it does suggest a source compatibility issue we'll need to work around. |
@swift-ci Please smoke test macOS platform |
The source compatibility issue here is that the code in question introduced conformances for each of the protocol P { }
extension ReversedCollection : P { }
extension ReversedRandomAccessCollection : P { }
extension ReversedRangeReplaceableCollection : P { } With this PR, those conformances are now redundant, because it's stating |
@swift-ci please smoke test compiler performance |
3b9c471
to
a608f78
Compare
@swift-ci Please test macOS platform |
@swift-ci please smoke test compiler performance |
@swift-ci Please smoke benchmark |
Build failed |
Fixed up the |
Build comment file:Optimized (O)Regression (14)
Improvement (12)
No Changes (308)
Unoptimized (Onone)Regression (38)
Improvement (12)
No Changes (284)
Hardware Overview
|
@swift-ci please test |
Build failed |
Build failed |
Refactor into base definitions + extensions. Redundant associated types are still required to word around bugs in associated type inference.
These fixes are for diagnostics that changed in benign ways or for places in the testsuite that were taking advantage of standard library internals.
The only significant casualty on the benchmarks seems to be CharIteration in Debug. @milseman possibly something to be aware of... |
9ea472e
to
887fece
Compare
@swift-ci please test source compatibility |
@swift-ci please test compiler performance |
@swift-ci please test |
Build failed |
Build failed |
@airspeedswift merge it! merge it! :) |
Build comment file:Summary for master fullUnexpected test results, stats may be off for Kronos, vapor, Dollar, Plank, RxDataSources Regressions found (see below) Debugdebug briefRegressed (1)
Improved (0)
Unchanged (delta < 1.0% or delta < 100.0ms) (1)
debug detailedRegressed (1)
Improved (7)
Unchanged (delta < 1.0% or delta < 100.0ms) (15)
Debug-optdebug-opt briefRegressed (0)
Improved (0)
Unchanged (delta < 1.0% or delta < 100.0ms) (2)
debug-opt detailedRegressed (1)
Improved (7)
Unchanged (delta < 1.0% or delta < 100.0ms) (15)
Wmo-ononewmo-onone briefNone wmo-onone detailedNone Releaserelease briefRegressed (0)
Improved (0)
Unchanged (delta < 1.0% or delta < 100.0ms) (2)
release detailedRegressed (2)
Improved (7)
Unchanged (delta < 1.0% or delta < 100.0ms) (14)
|
Did we figure out a plan for #12913 (comment) ? If that's part of our compatibility suite it'll surely be elsewhere in the wild—I could definitely see people giving conformance to a new protocol to multiple |
@natecook1000, that source-compatibility issue was in our own standard library test suite. We haven't seen any such code in the wild yet. The core team discussed that specific source compatibility concern and decided that the benefits of this change vastly outweigh the cost of such breakage; if we see more widespread breakage, we'll consider additional mitigations in the compiler (e.g, ignoring redundant conformances in such cases) |
Thanks @DougGregor, glad to know it's been discussed! |
This PR refactors the variations of
Slice
,DefaultIndices
, andReversedCollection
to be conditional conformances on each base type e.g.becomes: