-
Notifications
You must be signed in to change notification settings - Fork 29
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
Make native function signatures type-safe, fix broken SDK.Basics ops #363
Conversation
✅ Deploy Preview for magical-donut-e8221d ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
648372f
to
fee402a
Compare
199753f
to
9c29543
Compare
else | ||
v.toInt | ||
case _: Primitive[_, _, _] => | ||
throw new Exception( |
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.
These should be a sublass of MorphirRuntimeError
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.
All the errors thrown in this file should be a sublass of MorphirRuntimeError
or EvaluationError
(which is also a MorphirRuntime error)
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.
LGTM
@@ -132,7 +142,7 @@ object EvaluatorQuick { | |||
case TT.Reference(_, typeName, typeArgs) => | |||
val lookedUp = dists.lookupTypeSpecification(typeName.packagePath, typeName.modulePath, typeName.localName) | |||
val conceptArgs = typeArgs.map(typeToConcept(_, dists, boundTypes)) | |||
lookedUp.getOrElse(throw new Exception(s"Could not find spec for $typeName")) match { | |||
lookedUp.getOrElse(throw new UnexpectedType(s"Could not find spec for $typeName")) match { |
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.
There's a particular error for something being missing, and the return from Dists should be an either with a helpful error type for specifying what's missing
val divide: SDKValue[Unit, Type.UType] = | ||
SDKValue.SDKNativeFunction.fun2 { (a: Result[Unit, Type.UType], b: Result[Unit, Type.UType]) => | ||
handleSameNumerics(a, b) { (aNum, bNum, helper) => | ||
// scala.Numeric does not handle division, it's part of scala.Fractional or scala.Integral, need to get the right one |
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.
divide
as specified in morphir.SDK is only for floats - integerDivide is a completely different function
@@ -324,7 +325,7 @@ object EvaluatorQuick { | |||
curry(constructor, mappedArgs) | |||
case (a, b) => V.tuple(Chunk(scalaToIR(a), scalaToIR(b))) | |||
case (a, b, c) => V.tuple(Chunk(scalaToIR(a), scalaToIR(b), scalaToIR(c))) | |||
case other => throw new Exception(s"I don't know how to decompose $other") | |||
case other => throw new UnmatchedPattern(s"I don't know how to decompose $other") |
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.
UnmatchedPattern is specifically for pattern matching in terms of morphir - this should be UnsupportedType
Two major things have been done here, evaluator fixes and the basic implementation of higher-order native functions.
Evaluator Fixes and Improvements
This problem was fixed by adding an enumeration of the only functions that are actually possible:
arity
function is now gone. We can infer it automatically.EvaluatorMDMTests
file.scala.Numeric
, andscala.Integral
(orscala.Fractional
) based on the type. The former can be used to do +/-/* on all our needed types T, the latter is needed to do division (believe it or notscala.Numeric
doesn't do that!).unwrapNumericsWithHelper
was added together that summons both typesT
as well as thescala.Numeric[T]
instance for them (andFractional[T]
orIntegral[T]
as well).Higher Order Native Functions
Store
variable.NativeFunctionSignatureAdv
class that also contains the Store. Any users of it in Native.scala can access the the store in order to evaluate Result values.