qcert icon indicating copy to clipboard operation
qcert copied to clipboard

WASM: W-Imp intermediate representation

Open pkel opened this issue 5 years ago • 0 comments

The current Wasm backend is implemented in OCaml and translates from Imp to the AST used in the Webassembly reference implementation.

Doing Imp -> Wasm in OCaml was fine for quickly providing a seemingly working Webassembly backend. However, the gap between Imp and Wasm is quite big. The former was designed to resemble Javascript, the latter is much more low level. In the long run, it might be worth narrowing this gap by adding a more Wasm-like intermediate representation to Q*Cert.

My incomplete wish-list for W-Imp:

  • Function-scope variables instead of block scoped variables (see #145).
  • Use integers for variable names instead of string .
  • ~listing free variables in blocks would allow to translate Imp blocks to Wasm functions~ not true because Wasm functions can return only one value.
  • Replace for(each) with something closer to Wasm's loop construct.
  • Merge EJsonOperator and EJsonRuntimeOperator into a single WasmOperator. Avoid ADT features, WasmOperator should be an enumeration.
  • Introduce wasm data model (e.g. type wasm_model = string ejson).

On a later stage:

  • Replace WasmOperator with (namespace, opname) : (string * string). We import operators from the runtime anyway and this is all information we need. Most operators will have namespace = "runtime" to call into the runtime.wasm, but certain operators might be provided by the environment (e.g. logging) or separate wasm modules.
  • Use the backward mapping (string * string) -> WasmOperator to test functional equivalence of compiled Wasm contracts linked with operators implemented in Coq/OCaml versus operators implemented in the production runtime.wasm.
  • Maybe, we can unbox immediate values such as integers and floats after avoiding polymorphic operators.

pkel avatar Aug 20 '20 10:08 pkel