-
Notifications
You must be signed in to change notification settings - Fork 140
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
base: master
Are you sure you want to change the base?
Conversation
Cadence Benchstat comparisonThis branch with compared with the base branch onflow:master commit 14086f2 Collapsed results for better readability
|
"math/big" | ||
"unsafe" | ||
|
||
"github.com/onflow/atree" | ||
|
||
"github.com/onflow/cadence/common" | ||
"github.com/onflow/cadence/format" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No interpreter imports, nice! 👌
o, ok := other.(IntValue) | ||
if !ok { | ||
return nil, InvalidOperandsError{} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could get rid of some of these type-casts by making the interfaces (NumberValue
, IntegerValue
) generic. e.g: https://github.com/onflow/cadence/compare/bastian/decouple-values-from-interpreter-4...supun/bind-interface-to-type?expand=1#diff-4ba970fa0343b83d635e65319f40746490752a9e69d40072f87221672ce16c81R23-R29
But the downside is, the interface, say IntegerValue
, can only be used to define the structure of all the integer values. e.g:
var _ IntegerValue[IntValue] = IntValue{} // Ensures the `IntValue` implements `IntegerValue`
But cannot be actually used in the code, because IntegerValue
interface type would always have to be used with a T
, making the type too-sepicific.
var someValue Value = ...
integerValue := someValue.(IntegerValue[IntValue]) // This becomes pointless since `IntegerValue[IntValue]` is not generic enough
Work towards #3693
Description
Move the core functionality of the value implementations of
Bool
andInt
out of theinterpreter
package and into a newvalues
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 theinterpreter
package'sBoolValue
andIntValue
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 theinterpreter
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 havingIntValue.LessEqual(other ComparableValue)
, just haveIntLessEqual(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.
master
branchFiles changed
in the Github PR explorer