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

[Compiler] Support basic casting operations in VM #3767

Merged
merged 5 commits into from
Feb 14, 2025

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented Feb 13, 2025

Work towards #3742

Description

Adds basic support for type-casting in the VM.

Conversion for values based on type (e.g: Int16 to Int32, etc.) is not yet supported (left a TODO). It makes more sense to add those once the interpreter values are re-used.


  • 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

@SupunS SupunS added the Feature label Feb 13, 2025
@SupunS SupunS self-assigned this Feb 13, 2025
@SupunS SupunS requested a review from turbolent as a code owner February 13, 2025 21:50
@SupunS SupunS requested a review from jsproz February 13, 2025 21:50
Copy link

github-actions bot commented Feb 13, 2025

Cadence Benchstat comparison

This branch with compared with the base branch onflow:feature/compiler commit 56c8fbd
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

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!

I guess the core functions of the implementation, like ConvertAndBox, Unbox, BoxOptional are "copies" of the one in the interpreter? Maybe we can refactor them (in a follow-up) so they only exist in one place so we can share the logic between interpreter and VM, and there is no chance their behaviour drifts in different directions?

@SupunS
Copy link
Member Author

SupunS commented Feb 14, 2025

Yes. It's not possible to refactor yet, because the values are different, and also interpreter's functions rely on sema.Type and the VM's functions rely on StaticTypes. For the latter, I think the better approach is probably to refactor both to use StaticTypes. But again for that, we need to figure out a way / refactor the entitlements to also use StaticTypes.

I've added a item to our laundry-list for the next milestone, for adding those.

@SupunS
Copy link
Member Author

SupunS commented Feb 14, 2025

Like discussed, I split the different variants of casts in to separate instructions: c76e75a.

Can you please have another look on the last commit? 🙏

@SupunS SupunS requested a review from turbolent February 14, 2025 18:37
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! Looks great 👍

@turbolent
Copy link
Member

Opened #3771 to also add some test cases for the compilation

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.

👌

@SupunS SupunS merged commit 63c1541 into feature/compiler Feb 14, 2025
9 checks passed
@SupunS SupunS deleted the supun/casting branch February 14, 2025 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants