tweag / asterius

DEPRECATED in favor of ghc wasm backend, see https://www.tweag.io/blog/2022-11-22-wasm-backend-merged-in-ghc
1.98k stars 55 forks source link

Use WASI to model the system interface #402

Open TerrorJack opened 4 years ago

TerrorJack commented 4 years ago

In the current runtime, we already have various ad hoc simulations of system interfaces like read, write, etc. The problem of these ad hoc simulations is:

In the WebAssembly ecosystem, there's now WASI which has the hope of becoming the target-independent ABI standard. We should start using WASI to model our system interface, provide node/browser default WASI capabilities, and allow certain parts of those capabilities to be overridden.

Note that using WASI doesn't mean our code can be run on environments like wasmtime, since we still depend on JS in a lot of places, and that situation will remain for quite some while. But moving system interfaces to WASI should still be a good move towards that direction.

TerrorJack commented 4 years ago

Major WASI reference list:

WASI Core API WASI Constants

TerrorJack commented 4 years ago

Since the WASI Core API depends on passing i64 across js/wasm boundary, this issue and #407 is blocked by #33. Better implement a uniform i64 FFI mechanism and clean up our ad-hoc type casts here and there.

TerrorJack commented 4 years ago

The WASI API documentation doesn't seem to match the implementation. I eyeballed the wasm-objdump of a "typical" wasi binary from https://wapm.io/package/lucklove/tidb#explore, and the wasi_unstable import function signatures don't match the API documentation.

One example: __wasi_clock_time_get, according to the doc, the signature should be (i32, i64) -> i64, but the actual signature found in the binary is (i32, i64, i32) -> i32.

I also checked wasmer source code; from the implementation the semantics is (clock_id, precision, result_ptr) -> errno. Maybe the doc is still correct and it's a semi-automatic handling of i64 return value thing, I don't know.

TerrorJack commented 4 years ago

See https://github.com/WebAssembly/WASI/issues/54 for upstream discussion of i64 FFI problem

The status quo seems to be:

So. When writing our wasi capabilities, we need to:

What a wild west we're dealing here..

theduke commented 2 years ago

Am I correct in assuming that there hasn't been any progress here since 2019?