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

Decouple interpreter values from interpreter – Part 4 #3766

Merged
merged 6 commits into from
Feb 25, 2025

Conversation

turbolent
Copy link
Member

Work towards #3693

Description

Move the core functionality of the value implementations of Bool and Int out of the interpreter package and into a new values package. This demonstrates how we could decouple at least some of the more basic values from the interpreter and use them in the VM.

If this approach looks good, we can also refactor the other number value types, and some other primitive value types like e.g. String.

I'm happy with the values package itself, but honestly not really happy with how the integration looks in the interpreter package's BoolValue and IntValue types, especially all the unwrapping and wrapping, casting, type checking, error handling, etc. Maybe this is just temporary, and once we have refactored the value types in the interpreter package fully from the interpreter this ugliness will go away.

Another idea I had was not to create a whole new values.Value type hierarchy with methods, but instead just have global functions, e.g. instead of having IntValue.LessEqual(other ComparableValue), just have IntLessEqual(IntValue, IntValue).

Alternatively we would have to duplicate this code in the VM, which seems worse to me (e.g. potential for mismatch).

Let's discuss this in the Implemention Sync.


  • 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

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

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit 14086f2
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

@turbolent turbolent requested a review from SupunS February 24, 2025 22:37
@turbolent
Copy link
Member Author

@SupunS Could you please have a final look at the added commits? 🙏

Once merged, I'll also refactor UFix64 value for #3791, and then we can sync master into the compiler branch, and start using the new values package in the VM

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.

Looks great!

@turbolent turbolent merged commit 4ceea50 into master Feb 25, 2025
10 of 12 checks passed
@turbolent turbolent deleted the bastian/decouple-values-from-interpreter-4 branch February 25, 2025 17:12
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