-
Notifications
You must be signed in to change notification settings - Fork 10.6k
De-gyb Tuple.swift.gyb and replace it with variadic generics #85373
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
base: main
Are you sure you want to change the base?
Conversation
|
@swift-ci please smoke test |
|
@swift-ci Please benchmark |
|
@swift-ci please smoke test |
|
Ah, this is a fun one -- @slavapestov This seems related to the concessions here: https://forums.swift.org/t/variadic-generics-and-tuple-shuffle-conversions/60694 It looks like we explicitly are not performing the |
| public func !=<each B: Equatable>(lhs: (repeat each B), rhs: (repeat each B)) -> Bool { | ||
| for (lhs, rhs) in repeat (each lhs, each rhs) { | ||
| if lhs == rhs { | ||
| return false | ||
| } | ||
| } | ||
| return true |
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 it would be nicer if we forwarded to the same member-wise operations, e.g.
guard lhs != rhs else {
return false
}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.
Agreed
| /// - lhs: A tuple of `Equatable` elements. | ||
| /// - rhs: Another tuple of elements of the same type as `lhs`. | ||
| @_alwaysEmitIntoClient | ||
| public func ==<each B: Equatable>(lhs: (repeat each B), rhs: (repeat each B)) -> 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.
aside: does the choice of B as the generic parameter name have some particular significance or prior art?
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.
Ah, no, this was leftover from originally writing it as <A, each B> thinking it might make the algorithm simpler. It didn’t. I’ll rename and make it more verbose!
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 verbosity budget should be flush, what with all the boilerplate removal! 😄
This replaces the 2-7ary variadic gyb'd tuple comparison implementations with unified variadic implementations that short-circuit when the first element fails the test.
Unfortunately, the existing gyb'd tuple comparison entry points are all ABI, so we need to leave them in. However, we can just forward them along to the variadic implementation and rename them so they no longer conflict from an overload perspective.