-
Notifications
You must be signed in to change notification settings - Fork 136
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
Start using compared by identity Set operations for UrlHelpers#includes_helper?
#877
Conversation
When doing a difference of arrays for finding interesting ancestors, we need to be careful in case a constant has overridden `Object#hash`. Since array subtractions use `Object#hash` to determine equality, this operation will fail. Instead, we need to use a Set with compare-by-identity semantics, so that `Object#hash` is never called.
@@ -54,7 +54,7 @@ def self.gather_constants; end | |||
sig { returns(T::Set[Module]) } | |||
def self.processable_constants | |||
@processable_constants ||= T.let( | |||
Set.new(gather_constants).tap(&:compare_by_identity), | |||
T::Set[Module].new(gather_constants).compare_by_identity, |
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.
Is this change relevant in this commit?
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 could do without it, but seen as I changed the signature of Set#compare_by_identity
to not need the tap
here anymore, I thought I'd include this too.
@@ -1,5 +1,6 @@ | |||
# typed: strict | |||
|
|||
class Set | |||
sig { returns(T.self_type) } |
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 we upstream this change? https://github.com/sorbet/sorbet/blob/master/rbi/stdlib/set.rbi#L174-L178
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.
Yes, that's what I'll do next.
…-hash Start using compared by identity Set operations for `UrlHelpers#includes_helper?`
…-hash Start using compared by identity Set operations for `UrlHelpers#includes_helper?`
…-hash Start using compared by identity Set operations for `UrlHelpers#includes_helper?`
Thanks @paracycle 💯 |
Motivation
When doing a difference of arrays for finding interesting ancestors, we need to be careful in case a constant has overridden
Object#hash
. Since array subtractions useObject#hash
to determine equality, this operation will fail.Implementation
Instead, we need to use a Set with compare-by-identity semantics, so that
Object#hash
is never called.Tests