-
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] 0-ary tuples should be equatable #8354
Conversation
Add an == method for comparing two empty tuples. Resolves: SR-4172 (https://bugs.swift.org/browse/SR-4172)
@swift-ci Please smoke test |
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.
May as well do the full monty and edit the gyb template to make tuples quasi-Comparable
too. This is also missing !=
.
@CodaFi - Thanks. Just to clarify edit the .gyb to add |
You should edit the GYB template to account for the non-generic 0-ary tuple. It should be possible to do this "in GYB's terms" so we don't litter this file with just this specific conformance. |
Gotcha - was considering that adding extra logic for the 0 case in the existing templated methods might actually be less readable / more complicated (both the impls and comment generation will have to fork based on arity) than having a specific extra section for 0 outside of that, but can do that if preferred since it would litter less. |
👍 for the initiative/idea! |
Thanks @anayini! I agree that trying to incorporate the |
stdlib/public/core/Tuple.swift.gyb
Outdated
@@ -23,6 +23,14 @@ comparableOperators = [ | |||
|
|||
}% | |||
|
|||
/// Two tuples each of arity 0 are equal |
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 would copy the heading from the 'generic' ==
on tuples, and later add a sentence that all empty-tuples are equal to each other as a note.
/// Returns a Boolean value indicating whether the corresponding components of
/// two tuples are equal.
///
/// All zero-arity tuples are equal.
Similarly for the <
etc...
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.
👍
Add `!=`, `<`, `<=`, `>`, `>=` to 0-ary tuples Resolves: SR-4172 (https://bugs.swift.org/browse/SR-4172)
@moiseev - Updated to address your comments. Could also roll up the |
stdlib/public/core/Tuple.swift.gyb
Outdated
/// Returns a Boolean value indicating whether any corresponding components of | ||
/// the two tuples are not equal. | ||
/// | ||
/// Two tuples each of arity zero are never unequal |
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.
'never unequal' is a bit hard to understand (and there is a period missing ;-)). I'd go with the same note as for the ==
.
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.
Makes sense
I don't mind the non-gybbed version. @CodaFi , @airspeedswift what do you think? |
I don't have any qualms with not using GYB here - my thinking was that the file would be more resilient to future interface changes/tuple changes and we could update everything all at once. But that's a lot of work that can be done later. For now, LGTM. |
There a bit of more discussion here: https://bugs.swift.org/browse/SR-4172, regarding the size of this code and whether the |
@swift-ci please smoke test |
Welp, I suck. Looks like a failure in |
@anayini that's why we have CI ;-) Few people have enough resources and patience to run all the tests locally. |
Long time since last update, sorry about that. - @moiseev I'm actually still pretty confused about how the IDE code completion tests run using FileCheck. I've got something that I believe passes, but I'm definitely still confused about the semantics of the file. I basically have a pseudo understanding of how it works, but would like a deeper understanding so that I can update my commit to make sense. |
test/IDE/complete_operators.swift
Outdated
@@ -40,7 +40,7 @@ | |||
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=INFIX_14 | %FileCheck %s -check-prefix=NO_OPERATORS | |||
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=INFIX_15 | %FileCheck %s -check-prefix=NO_OPERATORS | |||
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=INFIX_16 | %FileCheck %s -check-prefix=NO_OPERATORS | |||
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=INFIX_17 | %FileCheck %s -check-prefix=NO_OPERATORS | |||
// RUN: %target-swift-ide-test -code-completion -source-filename=%s -code-completion-token=INFIX_17 | %FileCheck %s -check-prefix=VOID_OPERATORS |
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.
Should maybe rename VOID_OPERATORS
to VOID_INFIX_OPERATORS
?
func testInfix17(x: Void) { | ||
x#^INFIX_17^# | ||
} | ||
|
||
// VOID_OPERATORS: Begin completions |
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.
Generally want some feedback as to where the CHECK:
lines need to go. Even before this PR seems like the NO_OPERATORS-NOT
was in a strange place, but could be my misunderstanding.
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.
FileCheck is part of LLVM. See here for the documentation.
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.
Oh, I see how this is related to the change. ()
is same as Void
, and therefore we get all the equality/comparison ops on the value of type Void
. This might have other consequences...
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. Took me a bit to figure out, but yeah SourceKit code completion was offering suggestions of all the equality/comparison ops that were added, but it wasn't expecting any suggestions so this test was failing.
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.
/cc @airspeedswift
@swift-ci Please smoke test |
test/IDE/complete_operators.swift
Outdated
@@ -244,6 +244,7 @@ func testInfix11() { | |||
S2#^INFIX_11^# | |||
} | |||
// NO_OPERATORS-NOT: Decl[InfixOperatorFunction] | |||
|
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.
Why the newline?
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 sorry - I can remove that.
bump @airspeedswift I can fix the newline nits, but wanted to see if you had any other feedback if you have some time |
@moiseev - anyone else we can get feedback from :) I'll push up the whitespace fix, but was going to wait for other feedback in case its needed. |
@anayini Sorry for the silence. Last I remember there were some discussions about it. We'll get back to you once things clear up. Thanks for your patience! |
@moiseev - Just checking in again :) |
@moiseev - Did ya'll come to a conclusion? Should I close for now? |
@swift-ci please smoke test |
@swift-ci Please Test Source Compatibility |
@moiseev - Can dive into the Source Compatibility Suite error log - do these tests ever flake? If so, can you rerun? |
This one's a known issue that we just XFAILed. I'll kick off another run for you. @swift-ci Please test source compatibility |
Hm seems like this time its an |
Finally back to normal! @swift-ci Please test source compatibility |
😄 . All green! |
@moiseev - Are we good to merge? |
@anayini, do you mind sending an email to swift-evolution with a proposal to refine https://github.com/apple/swift-evolution/blob/master/proposals/0015-tuple-comparison-operators.md to cover the empty tuple case? |
@moiseev - Sorry for the delay - was getting ready for a long OOTO and am now out of the country until the end of the month. Will be able to check in on this periodically. Sent the email. |
@moiseev - Looks like it was accepted to be posted on swift-evolution. What are the next steps? |
@anayini Thanks for the contribution and your patience! |
Add an == method for comparing two empty tuples.
Resolves: SR-4172 (https://bugs.swift.org/browse/SR-4172)