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: let params of internal functions be mutable #3473

Merged
merged 7 commits into from
Jun 14, 2023

Conversation

tserg
Copy link
Collaborator

@tserg tserg commented May 31, 2023

What I did

Fix #3449.

How I did it

Update attributes in VarInfo and VariableRecord.

How to verify it

See tests.

Commit message

feat: let params of internal functions be mutable

This PR sets the data location of internal functions' params to
memory. Additionally, they are now mutable unlike an external
function's params.

Description for the changelog

Let params of internal functions be mutable.

Cute Animal Picture

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

@codecov-commenter
Copy link

codecov-commenter commented May 31, 2023

Codecov Report

Merging #3473 (f7a7472) into master (e97e9f2) will increase coverage by 0.05%.
The diff coverage is 100.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master    #3473      +/-   ##
==========================================
+ Coverage   89.30%   89.35%   +0.05%     
==========================================
  Files          84       84              
  Lines       10792    10777      -15     
  Branches     2461     2456       -5     
==========================================
- Hits         9638     9630       -8     
+ Misses        756      751       -5     
+ Partials      398      396       -2     
Impacted Files Coverage Δ
.../codegen/function_definitions/internal_function.py 100.00% <100.00%> (ø)
vyper/semantics/analysis/local.py 91.97% <100.00%> (+0.02%) ⬆️

... and 9 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@charles-cooper
Copy link
Member

please add some tests with complex types: static arrays, dynarrays and structs.

Comment on lines 177 to 179
# allow internal function params to be mutable
location = DataLocation.MEMORY if self.func.is_internal else DataLocation.CALLDATA
is_immutable = False if self.func.is_internal else True
Copy link
Member

Choose a reason for hiding this comment

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

i don't really like repeating branches in general. here i think we can get rid of it with either squashing all into a single ternary like so

Suggested change
# allow internal function params to be mutable
location = DataLocation.MEMORY if self.func.is_internal else DataLocation.CALLDATA
is_immutable = False if self.func.is_internal else True
# allow internal function params to be mutable
location, is_immutable = (DataLocation.MEMORY, False) if self.func.is_internal else (DataLocation.CALLDATA, True)

or two assignments per branch

Suggested change
# allow internal function params to be mutable
location = DataLocation.MEMORY if self.func.is_internal else DataLocation.CALLDATA
is_immutable = False if self.func.is_internal else True
if self.func.is_internal:
location = DataLocation.MEMORY
is_immutable = False
else:
location = DataLocation.CALLDATA
is_immutable = True

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.

can you also add tests which check that struct fields / array members are mutable?

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.

lgtm - thanks!

@charles-cooper charles-cooper merged commit c90ab2f into vyperlang:master Jun 14, 2023
@tserg tserg deleted the feat/internal_calldata branch June 14, 2023 17:31
pcaversaccio added a commit to pcaversaccio/snekmate that referenced this pull request Aug 14, 2024
### 🕓 Changelog

Given that the function parameters of `internal` functions are mutable
(as implemented [here](vyperlang/vyper#3473)),
this PR refines the internal logic of the `_log2`, `_log10`, `_log256`,
`_wad_ln`, and `_wad_exp` functions to align with this behaviour.
Additionally, it removes the unnecessary `denominator` variable
declaration in the `erc2981` contract and addresses minor formatting
issues in code comments.

---------
Signed-off-by: Pascal Marco Caversaccio <pascal.caversaccio@hotmail.ch>
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.

location of an internal function's argument should be memory
3 participants