Skip to content

Conversation

@sandbubbles
Copy link
Collaborator

@sandbubbles sandbubbles commented Oct 24, 2024

What I did

Add internal functions from imported modules into metadata output. Issue #4312 but reverse the imports.

How I did it

Print all reachable functions rather than just functions that are present in the module.

How to verify it

Commit message

this commit adds all reachable internal functions to the `-f metadata`
output. this was overlooked during the 0.4.0 release - there could
be internal functions in submodules which didn't get added to the `-f
metadata` output, since the routine to build the `-f metadata` output
only looked at the top-level module.

this commit also makes a change to the format of the `.function_info`
keys - since function names are not guaranteed to be globally unique
anymore (that is, two different modules may both contain a function
named `foo`), this commit adds a disambiguating function id to each
key in `.function_info`. (it uses the function_id computed during IR
generation since it is guaranteed to be unique). the function name
is still present in the function metadata under the `.name` key, but
downstream tooling may have to adapt if they had the assumption that
the keys in `.function_info` were parseable names. for illustration,
here is an example of function metadata prior to and after this commit.

prior to this commit:
```json
{
  "function_info": {
    // valid identifier, but not necessarily unique
    "foo": {
      "name": "foo",
      "_ir_identifier": "internal 0 foo()",
      ...
    }
  }
}
```

after this commit:
```json
{
  "function_info": {
    // not a valid identifier, but is unique. for the function name, see
    // the "name" field below.
    "foo (0)": {
      "name": "foo",
      "_ir_identifier": "internal 0 foo()",
      ...
    }
  }
}
```

Description for the changelog

Cute Animal Picture

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


for fn_t in module_t.exposed_functions:
assert isinstance(fn_t.ast_def, vy_ast.FunctionDef)
for inf_t in fn_t.reachable_internal_functions:
Copy link
Member

Choose a reason for hiding this comment

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

what does inf_t stand for?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

internal function and the t cause its the type - ill rename it to something clearer

Comment on lines 113 to 116
assert "foochino" in out["function_info"]
assert "bar" in out["function_info"]
assert "foo" in out["function_info"]
assert "faa" not in out["function_info"]
Copy link
Member

Choose a reason for hiding this comment

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

hmm noticing something messed up -- what if we have two functions with the same name in different modules?

for fn_t in module_t.exposed_functions:
assert isinstance(fn_t.ast_def, vy_ast.FunctionDef)
for rif_t in fn_t.reachable_internal_functions:
sigs[rif_t.ast_def.module_node.path + ": " + rif_t.name] = rif_t
Copy link
Member

Choose a reason for hiding this comment

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

i think there can actually be collisions between path since it's not resolved (e.g. depending on which search path is used)

Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

i think we need to find a way to export the internal functions which doesn't have any collisions in the dict. i.e. it is injective from reachable functions to functions which actually appear in the output.

@codecov
Copy link

codecov bot commented Nov 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.74%. Comparing base (f38b61a) to head (4a95adb).
Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4328      +/-   ##
==========================================
- Coverage   90.99%   88.74%   -2.25%     
==========================================
  Files         112      112              
  Lines       16017    16032      +15     
  Branches     2696     2698       +2     
==========================================
- Hits        14574    14227     -347     
- Misses       1005     1289     +284     
- Partials      438      516      +78     

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

@sandbubbles
Copy link
Collaborator Author

i think we need to find a way to export the internal functions which doesn't have any collisions in the dict. i.e. it is injective from reachable functions to functions which actually appear in the output.

changed it to use _metadata["type"]._id instead of path

@charles-cooper
Copy link
Member

i think we need to find a way to export the internal functions which doesn't have any collisions in the dict. i.e. it is injective from reachable functions to functions which actually appear in the output.

changed it to use _metadata["type"]._id instead of path

sorry, ModuleT._id isn't guaranteed to be unique because it uses .path instead of .resolved_path 😬

@cyberthirst cyberthirst added the release - must release blocker label Dec 11, 2024
@sandbubbles
Copy link
Collaborator Author

We are now using the IR function id (which is unique). This should be good for another review.

Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

this lgtm, i will check with downstream users to see if they can use the new function identifier format

@charles-cooper charles-cooper changed the title fix[ux]: internal functions not in metadata fix[tool]: internal functions not in metadata Dec 13, 2024
@charles-cooper charles-cooper enabled auto-merge (squash) December 17, 2024 21:18
@charles-cooper charles-cooper changed the title fix[tool]: internal functions not in metadata fix[tool]: add missing internal functions to metadata Dec 17, 2024
@charles-cooper charles-cooper enabled auto-merge (squash) December 17, 2024 21:20
@charles-cooper charles-cooper merged commit f31ff46 into vyperlang:master Dec 17, 2024
158 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release - must release blocker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants