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

feat[tool]: improvements to AST annotation #3829

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Mar 2, 2024

What I did

some improvements to AST annotation, including

  • link to declnode for user types
  • improve path information for modules
  • sha256sum for modules
  • include path resolution information on Import* nodes
  • tests

i also removed some dead code as i came across it. compare_nodes is only used in a couple tests, and those can be rewritten with the __eq__() operator. i'm not very thrilled about the idea of node equality in general as it's a bit ill-defined (what exactly do we want to measure?) and i think we should try to move away from defining/relying on node equality at all.

along with #3790, should fix #3600

How I did it

How to verify it

Commit message

this commit enriches the annotated AST output so that links between
nodes are explicit and consumers of the AST do not need to "guess" about
relationships.

- link to the type declaration node for user types
- add `sha256sum` field for `Module` nodes
- add fields on `Import*` nodes so that they can be linked directly to
  `Module` nodes (including `sha256sum`, so that changes in dependencies
  can be detected)
- add improved type information (including parsed out metadata, like
  array length) consistently across all types.

misc/refactors:
- add `to_dict()` for type objects
- removed some dead code - `compare_nodes` was only used in a couple of
  tests, and node equality could be used there instead. (node equality
  is not super well-defined, but we could revisit that later).

Description for the changelog

Cute Animal Picture

image

@charles-cooper charles-cooper changed the title feat: improvements to AST annotation [wip]feat: improvements to AST annotation Mar 2, 2024
@charles-cooper charles-cooper force-pushed the feat/integration/id-improvements branch from cbe8d5e to a4ef57e Compare March 2, 2024 20:25
@codecov-commenter
Copy link

codecov-commenter commented Mar 2, 2024

Codecov Report

Attention: Patch coverage is 93.75000% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 69.69%. Comparing base (5825e12) to head (e9c8f32).
Report is 1 commits behind head on master.

❗ Current head e9c8f32 differs from pull request most recent head a8fda55. Consider uploading reports for the commit a8fda55 to get more accurate results

Files Patch % Lines
vyper/semantics/analysis/module.py 57.14% 3 Missing ⚠️
vyper/ast/nodes.py 87.50% 1 Missing and 1 partial ⚠️
vyper/semantics/analysis/base.py 91.66% 0 Missing and 1 partial ⚠️
vyper/semantics/types/module.py 90.90% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #3829       +/-   ##
===========================================
- Coverage   86.15%   69.69%   -16.46%     
===========================================
  Files          92       92               
  Lines       13921    13990       +69     
  Branches     3067     3075        +8     
===========================================
- Hits        11993     9751     -2242     
- Misses       1491     3570     +2079     
- Partials      437      669      +232     

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

add typeclass to all types
add VyperType.to_dict to handle type serialization in AST
improve VyperType.decl_node handling for all types
add _addl_node_fields to handle types which "need parsing", e.g. HashMap,
    bytestrings, dynamic and static arrays, tuples
remove type information as it clutters the variable analysis test
tests/unit/ast/test_ast_dict.py Fixed Show fixed Hide fixed
tests/unit/ast/test_ast_dict.py Fixed Show fixed Hide fixed
@charles-cooper charles-cooper marked this pull request as ready for review March 3, 2024 23:01
@charles-cooper charles-cooper changed the title [wip]feat: improvements to AST annotation feat: improvements to AST annotation Mar 3, 2024
@charles-cooper charles-cooper changed the title feat: improvements to AST annotation feat[tool]: improvements to AST annotation Mar 3, 2024
it's only used in a couple tests, and those can be rewritten
Copy link
Collaborator

@cyberthirst cyberthirst left a comment

Choose a reason for hiding this comment

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

Shouldn't AdressT, SelfT, HashMapT have typeclass assigned?

@charles-cooper
Copy link
Member Author

Shouldn't AdressT, SelfT, HashMapT have typeclass assigned?

i found it not very useful (especially for AddressT and SelfT) because the typeclass is the same as the type name. but maybe yea we should add it for hashmap

@charles-cooper charles-cooper merged commit 9428196 into vyperlang:master Mar 9, 2024
83 checks passed
@charles-cooper charles-cooper deleted the feat/integration/id-improvements branch March 9, 2024 15:11
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.

AST node metadata (referenced declarations)
4 participants