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

Raise for already used arg name in function definition #510

Merged
merged 11 commits into from
Sep 16, 2024

Conversation

matteojug
Copy link
Contributor

@matteojug matteojug commented Sep 12, 2024

Address #473.

To add the context to the error I've added two globals, please let me know if some other approach works better.
Also fixes crosscheck_expect_failure that wasn't really expecting failures (it was used for an earlier test in this PR).

If the approach sounds good I'll port the standard.wat edits to stacks-core and bump it here before merging this PR.

A similar approach for the error (adding also the stringified type) could be also used for #385.

Copy link

codecov bot commented Sep 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.11%. Comparing base (9d5dd14) to head (085736d).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #510      +/-   ##
==========================================
+ Coverage   86.10%   86.11%   +0.01%     
==========================================
  Files          44       44              
  Lines       20708    20799      +91     
  Branches    20708    20799      +91     
==========================================
+ Hits        17830    17912      +82     
- Misses       1346     1347       +1     
- Partials     1532     1540       +8     

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

@Acaccia
Copy link
Collaborator

Acaccia commented Sep 13, 2024

(Continued from stacks-network/stacks-core#5168 (review))

For now, we try to not change the typechecker implementation, since we don't have the capabilities to check for the repercussions any change will have.

For this issue, my idea of a fix would be to check if any argument name is already used when we traverse a function:

  • if no, we keep going as usual
  • if yes, the body of the function is directly a runtime error.

@matteojug
Copy link
Contributor Author

Moving the convo here:

The interpreter will let the contract deploy, but then fail when invoked with an Unchecked error (#473 (comment)). Addressing this at typechecker level will give an early feedback about it.
Do you think we should keep the interpreter current behaviour (and address it only at compiler level)?

@Acaccia
Copy link
Collaborator

Acaccia commented Sep 13, 2024

We cannot change the current interpreter behavior. The compiler should be a perfect replacement for it. Otherwise, believe me, we wouldn't have all those awful typechecker workarounds in the codebase :(

@matteojug matteojug marked this pull request as ready for review September 13, 2024 14:42
@matteojug matteojug requested review from csgui and Acaccia and removed request for csgui September 13, 2024 15:17
@matteojug matteojug changed the title Add test for already used arg Raise for already used arg name in function definition Sep 16, 2024
clar2wasm/src/error_mapping.rs Outdated Show resolved Hide resolved
clar2wasm/src/wasm_generator.rs Outdated Show resolved Hide resolved
@Acaccia
Copy link
Collaborator

Acaccia commented Sep 16, 2024

If the approach sounds good I'll port the standard.wat edits to stacks-core and bump it here before merging this PR.

Do we have any changes to make when adding a global? Not sure.

A similar approach for the error (adding also the stringified type) could be also used for #385.

Excellent idea :)

@matteojug
Copy link
Contributor Author

Do we have any changes to make when adding a global? Not sure.

I was thinking about what would happen for contract calls (given the code duplication situation), but you're right: the global itself will not cause issues, as the code path involving it can only be triggered by the changed wasm (raising the new error type), so given the wasm change will not be present it should be fine as is.

@Acaccia
Copy link
Collaborator

Acaccia commented Sep 16, 2024

No you are right, I just noticed that we have more code duplication here: https://github.com/stacks-network/stacks-core/blob/c3c3af4ba8602fb1ed3bc870376ef1f96237e24c/clarity/src/vm/clarity_wasm.rs#L7647

Yeah I guess we will need to add this to stacks-core too :(

Copy link
Collaborator

@Acaccia Acaccia left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@csgui csgui left a comment

Choose a reason for hiding this comment

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

LGTM!

@matteojug matteojug added this pull request to the merge queue Sep 16, 2024
Merged via the queue into main with commit 6402754 Sep 16, 2024
13 of 15 checks passed
@matteojug matteojug deleted the fix/throw-already-used-arg branch September 16, 2024 18:44
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.

3 participants