Skip to content

[Compiler] Test optional arguments #3997

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

Merged
merged 10 commits into from
Jun 5, 2025
Merged

Conversation

RZhang05
Copy link
Contributor

@RZhang05 RZhang05 commented Jun 3, 2025

Closes #3996

Description

Renames Transfer instruction to TransferAndConvert and introduces a new Transfer instruction which only calls Transfer on the value. This is necessary for optional arguments in method invocation where the parameter type is unknown.


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@RZhang05 RZhang05 changed the title Add tests showing optional arguments. Optional arguments Jun 3, 2025
Copy link

github-actions bot commented Jun 3, 2025

Cadence Benchstat comparison

This branch with compared with the base branch onflow:feature/compiler commit 39e93d7
The command for i in {1..N}; do go test ./... -run=XXX -bench=. -benchmem -shuffle=on; done was used.
Bench tests were run a total of 7 times on each branch.

Collapsed results for better readability

@RZhang05 RZhang05 self-assigned this Jun 3, 2025
@RZhang05 RZhang05 marked this pull request as ready for review June 4, 2025 14:32
@RZhang05 RZhang05 requested review from turbolent and SupunS as code owners June 4, 2025 14:32
Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

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

Nice!
So I guess because we already provide the argument-count in the invoke instructions, we don't have to do anything specific?

@SupunS SupunS changed the title Optional arguments [Compiler] Test optional arguments Jun 4, 2025
@SupunS SupunS added the Testing label Jun 4, 2025
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Nice! Great to see this already works for function invocations.

We also have built-in methods that have optional/variable arguments, like e.g. the Account.Contract.add method (

Account_ContractsTypeAddFunctionType.Arity = &Arity{Min: 2}
). Could you please add some tests for method invocations as well?

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Great work! 👏

Co-authored-by: Bastian Müller <[email protected]>
@RZhang05 RZhang05 merged commit 499dad1 into feature/compiler Jun 5, 2025
8 of 9 checks passed
@RZhang05 RZhang05 deleted the raymond/optional-args branch June 5, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants