Skip to content
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

Merged
merged 3 commits into from
Mar 29, 2022

Conversation

paracycle
Copy link
Member

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 use Object#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

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.
@paracycle paracycle requested a review from a team March 29, 2022 18:05
@@ -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,
Copy link
Collaborator

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?

Copy link
Member Author

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) }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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.

@paracycle paracycle merged commit 083285a into main Mar 29, 2022
@paracycle paracycle deleted the uk-fix-url-helpers-dsl-overriden-hash branch March 29, 2022 18:23
paracycle added a commit that referenced this pull request Mar 29, 2022
…-hash

Start using compared by identity Set operations for `UrlHelpers#includes_helper?`
paracycle added a commit that referenced this pull request Mar 29, 2022
…-hash

Start using compared by identity Set operations for `UrlHelpers#includes_helper?`
paracycle added a commit that referenced this pull request Mar 29, 2022
…-hash

Start using compared by identity Set operations for `UrlHelpers#includes_helper?`
@c-bacon
Copy link

c-bacon commented Mar 29, 2022

Thanks @paracycle 💯

@paracycle paracycle added the backported Backported to stable branch label Apr 29, 2022
@shopify-shipit shopify-shipit bot temporarily deployed to production May 13, 2022 23:08 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported Backported to stable branch bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants