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

refactor[lang]: remove VyperNode __hash__() and __eq__() implementations #4433

Merged
merged 9 commits into from
Jan 12, 2025

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Jan 1, 2025

it is a performance and correctness footgun for the hash and eq implementations to recurse. for instance, two nodes from different source files should never compare equal (you can use deepequals to signal intention there).

i refactored the test suite by temporarily overriding the __ne__ implementation for VyperNode so that we can find all the != uses in the tests. the CI for this commit (0a9830b) passes (run https://github.com/vyperlang/vyper/actions/runs/12574333551/), and the training wheels are taken off in commit 71726ad.

What I did

How I did it

How to verify it

Commit message

it is a performance and correctness footgun for `VyperNode`'s hash and
eq implementations to recurse. for instance, two nodes from different
source files should never compare equal.

several tests rely on the recursive behavior of the eq implementation;
a utility function `deepequals()` is added in this PR so that tests
can perform the recursive check on AST nodes where needed. nowhere in
the compiler itself (`vyper/` directory) is the recursive definition
relied on.

this commit also slightly refactors the import analyzer so that uses
the new hash and eq implementations instead of the previous workaround
to avoid recursion (which was to use `id(module_ast)`.

Description for the changelog

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

it is a performance and correctness footgun for the hash and eq
implementations to recurse. for instance, two nodes from different
source files should never compare equal (you can use deepequals to
signal intention there).

this commit temporarily overrides the `__ne__` implementation for
VyperNode so that we can find all the `!=` uses in the tests.
@charles-cooper charles-cooper marked this pull request as draft January 1, 2025 20:49
vyper/ast/nodes.py Fixed Show fixed Hide fixed
since we no longer need to worry about __hash__ and __eq__performance
@charles-cooper charles-cooper marked this pull request as ready for review January 1, 2025 21:11
@charles-cooper charles-cooper changed the title refactor[lang]: remove VyperNode __hash__ and __eq__ implementations refactor[lang]: remove VyperNode __hash__() and __eq__() implementations Jan 1, 2025
@charles-cooper charles-cooper added this to the v0.4.1 milestone Jan 2, 2025
Copy link

codecov bot commented Jan 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.99%. Comparing base (f444c8f) to head (ee1d080).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4433      +/-   ##
==========================================
+ Coverage   91.98%   91.99%   +0.01%     
==========================================
  Files         119      119              
  Lines       16686    16673      -13     
  Branches     2808     2803       -5     
==========================================
- Hits        15348    15339       -9     
+ Misses        919      916       -3     
+ Partials      419      418       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@charles-cooper charles-cooper merged commit 9b5523e into vyperlang:master Jan 12, 2025
159 checks passed
@charles-cooper charles-cooper deleted the perf/vypernode-hash branch January 12, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants