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

Make sure we use compare by identity Sets properly #1735

Merged
merged 2 commits into from
Dec 18, 2023

Conversation

paracycle
Copy link
Member

@paracycle paracycle commented Dec 18, 2023

Motivation

Fix #1728

Implementation

There were a few places where we have not been using Sets with compare_by_identity properly. This commit fixes those instances so that the test added in the previous commit passes.

Tests

Added a failing test that passes with the fix.

@paracycle paracycle requested a review from vinistock December 18, 2023 16:21
@paracycle paracycle requested a review from a team as a code owner December 18, 2023 16:21
@paracycle paracycle requested a review from andyw8 December 18, 2023 16:21
@@ -36,7 +36,7 @@ def gather_constants; end
sig { returns(T::Set[Module]) }
def processable_constants
@processable_constants ||= T.let(
T::Set[Module].new(gather_constants).compare_by_identity,
T::Set[Module].new.compare_by_identity.merge(gather_constants),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this some kind of perf optimization?

Copy link
Member Author

Choose a reason for hiding this comment

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

No. The constants that we are handed could be doing anything, like implementing self.hash method as in this example. If we don't use a compare_by_identity set to store them, then their hash method gets called (among others), which could raise, as it was happening on #1728.

If a constant implements `self.hash`, then Tapioca DSL compiler should be resilient against it.
There have been a few instances where we have not been using `Set`s with `compare_by_identity` properly. This commit fixes those instances so that the test added in the previous commit passes.

Fixes #1728
@paracycle paracycle force-pushed the uk-fix-set-compare-by-identity branch from 4426ba2 to c1333df Compare December 18, 2023 17:13
@paracycle paracycle enabled auto-merge December 18, 2023 17:25
@paracycle paracycle changed the title Make sure we use compare by identity Sets properly Make sure we use compare by identity Sets properly Dec 18, 2023
@paracycle paracycle merged commit 0bc05d6 into main Dec 18, 2023
28 checks passed
@paracycle paracycle deleted the uk-fix-set-compare-by-identity branch December 18, 2023 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bin/tapioca dsl fails with undefined method ancestors' for ...`
4 participants