Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Wasm Interoperability #727

Open
jeromesimeon opened this issue Dec 18, 2019 · 7 comments
Open

Wasm Interoperability #727

jeromesimeon opened this issue Dec 18, 2019 · 7 comments

Comments

@jeromesimeon
Copy link
Member

jeromesimeon commented Dec 18, 2019

Is your feature request related to a problem? Please describe.

Would anyone like to call Wasm from Ergo?

Describe the solution you'd like

A way to call Wasm modules from Ergo contracts.

Additional context

WASM specification: https://webassembly.github.io/spec/core/

Reference implementation in OCaml: https://github.com/WebAssembly/spec

WASM/JS interface: https://webassembly.github.io/spec/js-api/index.html

Interesting bits about WASM/JS interop performances: https://hacks.mozilla.org/2018/10/calls-between-javascript-and-webassembly-are-finally-fast-🎉/

@jeromesimeon
Copy link
Member Author

Things we might need to get this working:

@jeromesimeon jeromesimeon changed the title WASM interoperability Wasm Interoperability Dec 18, 2019
@aksharma53
Copy link

aksharma53 commented Feb 21, 2020

I would like to work on this project.

@irmerk
Copy link
Member

irmerk commented Feb 21, 2020

Great @analystabhishek! If you're interested in the GSoC project around WASM, be sure to look into the resources we have pinned in our slack channel.

@aksharma53
Copy link

Yeah I'm already going through the post shared by Dan and Jerome on slack channel.

@aksharma53
Copy link

aksharma53 commented Feb 22, 2020

I'have finished my first task of understanding the whole documentation of Accord Project and has a prior knowledge on WASM as well as Ocaml. I have also set up the enviroment to start work on it, should I start making purposal ?

@jeromesimeon
Copy link
Member Author

jeromesimeon commented Jun 12, 2020

Some notes from today's discussion on the WASM backend.

Plan

  1. ImpWasm = Imp over EJson+SumTypes (i.e., do not encode left/right as objects) @jeromesimeon

  2. Mini compiler: take imp_ejson AST (just constant + a few operators) and compile to WASM AST + (static) link runtime + run @pkel

  3. Grow the runtime supported (& decide which runtime operators can be eliminated by the compiler) @pkel

  4. Grow the subset of imp_ejson AST being compiled

    1. if-then-else
    2. statements: for loops
    3. blocks?? probably need to eliminate blocks because of scoping

Blocks & scoping @jeromesimeon

WASM doesn't support block-level scoping (not 'let' only 'var')

Imp supports block-level scoping. e.g.,:

{ let x = 1;
  let y = 3;
  { let x = 2;
    x + y } }

Maybe removed by renaming/blocks merging:

{ let x1 = 1 ;
  let y = 3;
  let x2 = 2;
  x2 + y }

Runtime operators

Examples of runtime operators

concat: [a:1,b:2] + [c:3]     ==> [a:1,b:2,c:3]
concat: [a:1,b:2] + [c:3,b:4] ==> [a:1,c:3,b:4]

merge: [a:1,b:2] + [c:3]     ==> some([a:1,b:2,c:3])
merge: [a:1,b:2] + [c:3,b:2] ==> some([a:1,b:2,c:3])
merge: [a:1,b:2] + [c:3,b:4] ==> none

nth: [1,2,3] + 0 ==> some(1)
nth: [1,2,3] + 3 ==> none

@jeromesimeon jeromesimeon added the Backend: WASM WebAssembly Backend label Jun 14, 2020
@jeromesimeon
Copy link
Member Author

jeromesimeon commented Jul 16, 2020

Todo list, based on latest development in Q*cert (wasm branch) and Ergo (release-1.0 branch) :

  1. Get the release-1.0 branch of Ergo to build on the wasm branch of Q*cert (requires per-module extraction)
  2. Add a -target wasm option to the Ergo compiler, hook it up to a corresponding ErgoImptoWasm translation backed up by your compiler
    • Turn ImpEJson to Wasm translation into a functor so it can be used both in Q*cert and Ergo (@pkel)
  3. Support for objects ("branded values")
    • Turn type hierarchy into a proper constant in the generated code, or a parameter of the compilation rather than eval (@jeromesimeon)
    • Implement sub_brands_dec (or equivalent) in runtime (@pkel)
  4. Compile time elimination of runtime operators (@jeromesimeon)
    • Brand
    • Unbrand (is it possible?)
    • aggregate operators (e.g., count, sum, avg)
    • which other?
  5. Add a -target imp_ejson option to the Ergo compiler? Along with a proper pretty printer consistent with the new imp_ejson syntax we saw in the demo
  6. Figure out runtime/testing, missing runtime operators for helloworld etc. (@pkel)
  7. [Not Wasm Specific] Still need to update release-1.0 of Ergo to use the latest development version of Concerto (alpha of Concerto 1.0)
  8. [Not Wasm Specific] Merge release-1.0 branch of Ergo into master
  9. Merge wasm branch of Q*cert into master ; publish Q*cert ; publish Concerto ; publish Ergo
  10. Tada!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants