-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[4.1][stdlib] Eliminate IndexDistance #13344
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
[4.1][stdlib] Eliminate IndexDistance #13344
Conversation
* Eradicate IndexDistance associated type, replacing with Int everywhere * Consistently use Int for ExistentialCollection’s IndexDistance type. * Fix test for IndexDistance removal * Remove a handful of no-longer-needed explicit types * Add compatibility shims for non-Int index distances * Test compatibility shim * Move IndexDistance typealias into the Collection protocol
@swift-ci please test |
@swift-ci please benchmark |
@swift-ci please test source compatibility |
@swift-ci please smoke compiler performance |
@@ -782,6 +776,9 @@ public protocol Collection: Sequence where SubSequence: Collection { | |||
/// - Parameter i: A valid index of the collection. `i` must be less than | |||
/// `endIndex`. | |||
func formIndex(after i: inout Index) | |||
|
|||
@available(swift, deprecated, message: "all index distances are now of type Int") | |||
typealias IndexDistance = Int |
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
UPD: Oh wait, it's a protocol. Nevermind.
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.
Yup. I moved it back and forth between the protocol and the extension multiple times and forgot this every. single. time.
} | ||
*/ | ||
@available(*, deprecated, message: "all index distances are now of type Int") | ||
public func formIndex<T: BinaryInteger>(_ i: inout Index, offsetBy n: T, limitedBy limit: Index) -> Bool { |
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.
I think formIndex
should have a @discardableResult
attribute, otherwise it will issue 2 warnings.
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.
eh, they're both legit warnings though
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.
Take that back. Turns out we do not have @discardableResult
on this method anywhere...
return formIndex(&i, offsetBy: Int(n), limitedBy: limit) | ||
} | ||
@available(*, deprecated, message: "all index distances are now of type Int") | ||
public func distance<T: BinaryInteger>(from start: Index, to end: Index) -> 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.
Surprised it does not result in ambiguity in expressions like let d = xs.distance(from: someIndex, to: someOtherIndex)
.
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.
The other distance
method isn't generic (T
is Int
) so it wins.
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.
Isn't generic other than on the protocol, that is...
@@ -2898,6 +2898,9 @@ public struct ${Self} | |||
: FixedWidthInteger, ${Unsigned}Integer, | |||
_ExpressibleByBuiltinIntegerLiteral { | |||
|
|||
public typealias IntegerLiteralType = ${Self} |
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.
How is this related?
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.
Hum. It isn't. I probably meant to do this on my clean-up branch. But since this is a cherry-pick from master where it's merged, probably should just leave it in.
@swift-ci please nominate |
Build comment file:Build failed before running benchmark. |
IndexDistance
associated type, implementing SE-191.IndexDistance
withInt
. It also introduces some compatibility shims (anIndexDistance
typealias equal toInt
, and generic conversions for calls using non-Int
index distances).Int
is not already used, and the majority of changes are simplifications of the code to no longer need to perform casts between different distance types.