Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

WASM: Priority list of runtime & operators #133

Open
88 of 92 tasks
jeromesimeon opened this issue Jul 10, 2020 · 13 comments
Open
88 of 92 tasks

WASM: Priority list of runtime & operators #133

jeromesimeon opened this issue Jul 10, 2020 · 13 comments
Assignees

Comments

@jeromesimeon
Copy link
Member

jeromesimeon commented Jul 10, 2020

Part of #153.

Operators

  • EJsonOpNot
  • EJsonOpNeg
  • EJsonOpAnd
  • EJsonOpOr
  • EJsonOpLt
  • EJsonOpLe
  • EJsonOpGt
  • EJsonOpGe
  • EJsonOpAddString
  • EJsonOpAddNumber
  • EJsonOpSub
  • EJsonOpMult
  • EJsonOpDiv
  • EJsonOpStrictEqual ( currently = EJsonRuntimeEqual)
  • EJsonOpStrictDisequal ( currently = not EJsonRuntimeEqual)
  • EJsonOpArray (n-ary, handled by compiler)
  • EJsonOpArrayLength
  • EJsonOpArrayPush
  • EJsonOpArrayAccess
  • EJsonOpObject _ (n-ary, handled by compiler)
  • EJsonOpAccess _
  • EJsonOpHasOwnProperty _
  • EJsonOpMathMin
  • EJsonOpMathMax
  • EJsonOpMathPow
  • EJsonOpMathExp
  • EJsonOpMathAbs
  • EJsonOpMathLog
  • EJsonOpMathLog10
  • EJsonOpMathSqrt
  • EJsonOpMathCeil
  • EJsonOpMathFloor
  • EJsonOpMathTrunc

Runtime

  • EJsonRuntimeEqual (** XXX First *)
  • EJsonRuntimeCompare
  • EJsonRuntimeToString ( XXX Third )
  • EJsonRuntimeToText ( will be removed )

Record

  • EJsonRuntimeRecConcat (** XXX First *)
  • EJsonRuntimeRecMerge (** XXX Second *)
  • EJsonRuntimeRecRemove (** XXX Second *)
  • EJsonRuntimeRecProject (** XXX Second *)
  • EJsonRuntimeRecDot (** XXX First *) ( = EJsonOpAccess)

Array

  • EJsonRuntimeArray (n-ary, handled by compiler) = EJsonOpArray
  • EJsonRuntimeArrayLength (= EJsonOpArrayLength)
  • EJsonRuntimeArrayPush (** XXX Third = EJsonOpArrayPush **)
  • EJsonRuntimeArrayAccess (** XXX Third = EJsonOpArrayAccess **)

Sum

  • EJsonRuntimeEither (** XXX First *)
  • EJsonRuntimeToLeft (** XXX First *)
  • EJsonRuntimeToRight (** XXX First *)

Brand

  • EJsonRuntimeBrand (** XXX Second -- not existing / eliminated? *)
  • EJsonRuntimeUnbrand (** XXX Second -- eliminate with runtimeRecDot "$data" ? *)
  • EJsonRuntimeCast (** XXX Second -- maybe eliminate *)

Collection

  • EJsonRuntimeDistinct
  • EJsonRuntimeSingleton (** XXX Second *)
  • EJsonRuntimeFlatten (** XXX Second *)
  • EJsonRuntimeUnion (** XXX Second *)
  • EJsonRuntimeMinus (** XXX Second *)
  • EJsonRuntimeMin
  • EJsonRuntimeMax
  • EJsonRuntimeNth (** XXX Second *)
  • EJsonRuntimeCount (** XXX Second *) ( redundant with OpArrayLength )
  • EJsonRuntimeContains
  • EJsonRuntimeSort (** XXX Ignore *)
  • EJsonRuntimeGroupBy (** XXX Ignore *)

String

  • EJsonRuntimeLength
  • EJsonRuntimeSubstring
  • EJsonRuntimeSubstringEnd
  • EJsonRuntimeStringJoin
  • EJsonRuntimeLike (** XXX Not used in Ergo *)

Integer

  • EJsonRuntimeNatLt
  • EJsonRuntimeNatLe
  • EJsonRuntimeNatPlus
  • EJsonRuntimeNatMinus
  • EJsonRuntimeNatMult
  • EJsonRuntimeNatDiv
  • EJsonRuntimeNatRem
  • EJsonRuntimeNatAbs
  • EJsonRuntimeNatLog2
  • EJsonRuntimeNatSqrt
  • EJsonRuntimeNatMinPair
  • EJsonRuntimeNatMaxPair
  • EJsonRuntimeNatSum
  • EJsonRuntimeNatMin
  • EJsonRuntimeNatMax
  • EJsonRuntimeNatArithMean
  • EJsonRuntimeFloatOfNat

Float

  • EJsonRuntimeFloatSum
  • EJsonRuntimeFloatArithMean
  • EJsonRuntimeFloatMin
  • EJsonRuntimeFloatMax
  • EJsonRuntimeNatOfFloat

Foreign

  • EJsonRuntimeForeign ( to be implemented before toString )
@jeromesimeon jeromesimeon changed the title WASM: Priority list of runtime operators WASM: Priority list of runtime & operators Jul 10, 2020
pkel added a commit to pkel/qcert that referenced this issue Jul 10, 2020
@pkel
Copy link
Collaborator

pkel commented Jul 13, 2020

The array operators are missing on this list. They are probably important?

https://github.com/querycert/qcert/blob/wasm/compiler/core/EJson/Operators/EJsonRuntimeOperators.v#L48-L51

RuntimeArray is n-ary and the n is not known locally. I need to know the n for compilation.

@pkel
Copy link
Collaborator

pkel commented Jul 17, 2020

Just updated the list to reflect the latest state. Also added the non-runtime operators.

@pkel
Copy link
Collaborator

pkel commented Mar 8, 2021

I made some progress in 9578251.
I think implementing and debugging the runtime would benefit from a set of unit tests per operator. How would you do it? My current best guess is to add Imp tests per operator under /tests/operators/<operatorName>.imp_ejson. Or do you have something like this already?

@jeromesimeon
Copy link
Member Author

I made some progress in 9578251.
I think implementing and debugging the runtime would benefit from a set of unit tests per operator. How would you do it? My current best guess is to add Imp tests per operator under /tests/operators/<operatorName>.imp_ejson. Or do you have something like this already?

hm. that's a really good question. And no, we don't have anything of the kind even for JS. This would be super great though.

I think one question is whether those tests are written in imp_ejson or are they written against the runtime itself (i.e., in JS, AssemblyScript).

@pkel
Copy link
Collaborator

pkel commented Mar 10, 2021

I'd implement them in imp_ejson. Makes them reusable for other backends / runtime implementations.

@jeromesimeon
Copy link
Member Author

I'd implement them in imp_ejson. Makes them reusable for other backends / runtime implementations.

agreed. Not sure how to make those systematic, would we like a syntax for those things.

@pkel
Copy link
Collaborator

pkel commented Mar 10, 2021

Your imp_ejson parser undestands runtime operators like Runtime.array(arg0, ...). How much effort is it to do something similar for non-runtime Operators? E.g. something like Op.object(keys)(val1, val2) which translates directly to the variant type in EJsonOperators.v.

Currently, I do not fully understand the semantics of imp_ejson. Maybe such a change will help.

@jeromesimeon
Copy link
Member Author

Your imp_ejson parser undestands runtime operators like Runtime.array(arg0, ...). How much effort is it to do something similar for non-runtime Operators? E.g. something like Op.object(keys)(val1, val2) which translates directly to the variant type in EJsonOperators.v.

Currently, I do not fully understand the semantics of imp_ejson. Maybe such a change will help.

🤔 I forgot we had two kinds of operators in Imp... Let me look at the parser, I think there was a reason why I only did it for runtime operators, but let me double check.

@pkel
Copy link
Collaborator

pkel commented Mar 10, 2021

Now I get what you meant with "syntax for those things". I think we could do something like this.

{ "name": "Runtime Operator Equal",
  "operator": "EJsonRuntimeEqual",
  "type": "ejson_runtime_op",
  "inputs": [ [ ejson_test0_arg0, ejson_test0_arg1 ],
              [ ejson_test1_arg1, ejson_test1_arg2 ],
              ...
]}

The ejson_* parts would be actual EJson values. The semantics of the test would be

  1. parse above json
  2. foreach args in inputs
    1. a := imp eval operator with arguments in verified system
    2. b := wasm/js eval compiled version of the statement in unverified system
    3. if a != b then fail and print name/operator/type/args

That would be super useful. Requires some plumping on your side, though.

@jeromesimeon
Copy link
Member Author

Now I get what you meant with "syntax for those things". I think we could do something like this.

{ "name": "Runtime Operator Equal",
  "operator": "EJsonRuntimeEqual",
  "type": "ejson_runtime_op",
  "inputs": [ [ ejson_test0_arg0, ejson_test0_arg1 ],
              [ ejson_test1_arg1, ejson_test1_arg2 ],
              ...
]}

yes that's what I was wondering!

The ejson_* parts would be actual EJson values. The semantics of the test would be

  1. parse above json

  2. foreach args in inputs

    1. a := imp eval operator with arguments in verified system
    2. b := wasm/js eval compiled version of the statement in unverified system
    3. if a != b then fail and print name/operator/type/args

That would be super useful. Requires some plumping on your side, though.

Sounds good. Let me see if I can get some traction on this, will need to page in current status. Thanks for a concrete proposal! I'll see if I can start with that.

Will need to figure out how to write ejson values (in JSON? maybe that's too obvious)

@pkel
Copy link
Collaborator

pkel commented Mar 10, 2021

Will need to figure out how to write ejson values (in JSON? maybe that's too obvious)

Yes in JSON. I think you already have serializer/parsers? That's my main reason for writing the tests in JSON. I'd appreciate another format for writing the tests. Something supporting comments. But I guess that would be more work?

@jeromesimeon
Copy link
Member Author

Will need to figure out how to write ejson values (in JSON? maybe that's too obvious)

Yes in JSON. I think you already have serializer/parsers? That's my main reason for writing the tests in JSON. I'd appreciate another format for writing the tests. Something supporting comments. But I guess that would be more work?

JSON = 👍

proper syntax would be more work, but yes I'd love that too. main factor will be available time I'm afraid.

@pkel
Copy link
Collaborator

pkel commented May 4, 2021

Coming back to the operator unit test proposed above.

I think we save a lot of time by coding the tests in OCaml. I've a basic proof-of-concept working. I compose small Imp functions with one expression and one operator. Then I evaluate these function using Imp's eval and Wasm's eval and compare the result. In my opinion, the syntax is effective.

let _ =
let open Const in
test_op
EJsonOpAddNumber
[ [number 41.; number 1.]
; [number (-1.); number 1e32]
; [number (-1.); number Float.infinity]
];
test_rtop
EJsonRuntimeNatPlus
[ [bigint 41; bigint 1]
; [bigint 43; bigint (-1)]
]

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants