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

Allow mutable parameters in messages #2004

Merged
merged 6 commits into from
Nov 28, 2023
Merged

Allow mutable parameters in messages #2004

merged 6 commits into from
Nov 28, 2023

Conversation

SkymanOne
Copy link
Contributor

@SkymanOne SkymanOne commented Nov 23, 2023

Summary

Closes #826

  • [n] y/n | Does it introduce breaking changes?
  • [n] y/n | Is it dependant on the specific version of cargo-contract or pallet-contracts?

Allows message to have mut parameters.

Description

Constructor already provides the ability to have mut parameters as the parameter idents are replaced with ink_binding_{n} during codegen. The main problem with messages occurring before had to do with the contract_ref call builder. when extracting the ident from pat for input binding during codegen, syn automatically includes mut keyword. The solution is to go down the AST of Pat and extract ident from there. This is what input_message_idents() function does.

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • I have added an entry to CHANGELOG.md
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

@SkymanOne SkymanOne changed the title Gn/mut args Allow mutable parameters in messages Nov 23, 2023
Copy link

github-actions bot commented Nov 23, 2023

🦑 📈 ink! Example Contracts ‒ Changes Report 📉 🦑

These are the results when building the integration-tests/* contracts from this branch with cargo-contract and comparing them to ink! master:

Contract Upstream Size (kB) PR Size (kB) Diff (kB) Diff (%) Change
basic-contract-caller 2.967 2.967 0 0
basic-contract-caller/other-contract 1.337 1.337 0 0
call-builder-return-value 8.735 8.735 0 0
call-runtime 1.769 1.769 0 0
conditional-compilation 1.209 1.209 0 0
contract-storage 7.171 7.171 0 0
contract-terminate 1.092 1.092 0 0
contract-transfer 1.444 1.444 0 0
custom-allocator 7.428 7.428 0 0
dns 7.249 7.249 0 0
e2e-call-runtime 1.058 1.058 0 0
e2e-runtime-only-backend 1.635 1.635 0 0
erc1155 13.962 13.968 0.006 0.0429738 📈
erc20 6.687 6.687 0 0
erc721 9.64 9.64 0 0
events 4.763 4.763 0 0
flipper 1.393 1.393 0 0
incrementer 1.221 1.221 0 0
lang-err-integration-tests/call-builder-delegate 2.317 2.317 0 0
lang-err-integration-tests/call-builder 4.847 4.847 0 0
lang-err-integration-tests/constructors-return-value 1.773 1.773 0 0
lang-err-integration-tests/contract-ref 4.328 4.328 0 0
lang-err-integration-tests/integration-flipper 1.571 1.571 0 0
mapping-integration-tests 7.685 7.685 0 0
mother 9.508 12.544 3.036 31.931 📈
multi-contract-caller 5.924 5.924 0 0
multi-contract-caller/accumulator 1.095 1.095 0 0
multi-contract-caller/adder 1.669 1.669 0 0
multi-contract-caller/subber 1.689 1.689 0 0
multisig 21.471 21.471 0 0
payment-channel 5.501 5.501 0 0
sr25519-verification 0.865 0.865 0 0
static-buffer 1.405 1.405 0 0
trait-dyn-cross-contract-calls 2.466 2.466 0 0
trait-dyn-cross-contract-calls/contracts/incrementer 1.305 1.305 0 0
trait-erc20 7.063 7.063 0 0
trait-flipper 1.209 1.209 0 0
trait-incrementer 1.37 1.37 0 0
upgradeable-contracts/delegator 2.908 2.908 0 0
upgradeable-contracts/delegator/delegatee 1.369 1.369 0 0
upgradeable-contracts/set-code-hash 1.464 1.464 0 0
upgradeable-contracts/set-code-hash/updated-incrementer 1.443 1.443 0 0
wildcard-selector 2.622 2.622 0 0

Link to the run | Last update: Tue Nov 28 18:09:16 CET 2023

@codecov-commenter
Copy link

codecov-commenter commented Nov 24, 2023

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (d4c57a3) 53.23% compared to head (e2e23e1) 53.37%.
Report is 4 commits behind head on master.

Files Patch % Lines
crates/ink/codegen/src/generator/arg_list.rs 0.00% 5 Missing ⚠️
...odegen/src/generator/as_dependency/contract_ref.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2004      +/-   ##
==========================================
+ Coverage   53.23%   53.37%   +0.13%     
==========================================
  Files         220      220              
  Lines        6845     6884      +39     
==========================================
+ Hits         3644     3674      +30     
- Misses       3201     3210       +9     

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

Copy link
Collaborator

@ascjones ascjones left a comment

Choose a reason for hiding this comment

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

LGTM. Would be nice to have a ui/pass test too for the specification, but I suppose it is covered by the unit test + integration test.

@SkymanOne
Copy link
Contributor Author

SkymanOne commented Nov 28, 2023

LGTM. Would be nice to have a ui/pass test too for the specification, but I suppose it is covered by the unit test + integration test.

The unit test already covers that mut is parsed correctly. Everything else stays the same.

@ascjones
Copy link
Collaborator

LGTM. Would be nice to have a ui/pass test too for the specification, but I suppose it is covered by the unit test + integration test.

The unit test already covers that must is parsed correctly. Everything else stays the same.

Indeed it does, so fine without it. Just pointing out that for the other cases in the unit test there is also a ui test. Maybe overkill, up to you.

@SkymanOne SkymanOne merged commit 1bd7f4e into master Nov 28, 2023
22 checks passed
@SkymanOne SkymanOne deleted the gn/mut_args branch November 28, 2023 17:10
@SkymanOne SkymanOne mentioned this pull request Nov 30, 2023
@SkymanOne SkymanOne mentioned this pull request Jan 15, 2024
@SkymanOne SkymanOne mentioned this pull request Feb 8, 2024
@SkymanOne SkymanOne mentioned this pull request Mar 4, 2024
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.

Cannot add mut to message arguments
3 participants