wasmerio / wasmer

🚀 The leading Wasm Runtime supporting WASIX and WASI
https://wasmer.io
MIT License
18.97k stars 812 forks source link

Wasm value kind enum WASM_ANYREF doesn't align with Wasm C API #5082

Closed ashtonmeuser closed 2 months ago

ashtonmeuser commented 2 months ago

Describe the bug

Wasmer does not use Wasm value types as defined by the Wasm C API.

The Wasm C API defines value types as follows (source):

typedef uint8_t wasm_valkind_t;
enum wasm_valkind_enum {
  WASM_I32,
  WASM_I64,
  WASM_F32,
  WASM_F64,
  WASM_EXTERNREF = 128,
  WASM_FUNCREF,
};

Wasmer uses enum WASM_ANYREF instead of WASM_EXTERNREF as follows:

typedef uint8_t wasm_valkind_t;
enum wasm_valkind_enum {
  WASM_I32,
  WASM_I64,
  WASM_F32,
  WASM_F64,
  WASM_ANYREF = 128,
  WASM_FUNCREF,
};

This means that Wasmer can not be swapped in in place of other libraries adhering to the Wasm C API (e.g. Wasmtime). The following error is produced when compiling:

error: use of undeclared identifier 'WASM_EXTERNREF'; did you mean 'WASM_ANYREF'?
          if (results->data[i].kind == WASM_EXTERNREF) return ERR_INVALID_DATA;
                                       ^~~~~~~~~~~
                                       WASM_ANYREF

Steps to reproduce

Compile using Wasmer via the Wasm C API. Make use of WASM_EXTERNREF.

Expected behavior

Program compiles using WASM_EXTERNREF.

Actual behavior

The WASM_EXTERNREF enum is undefined.

error: use of undeclared identifier 'WASM_EXTERNREF'; did you mean 'WASM_ANYREF'?
          if (results->data[i].kind == WASM_EXTERNREF) return ERR_INVALID_DATA;
                                       ^~~~~~~~~~~
                                       WASM_ANYREF
syrusakbary commented 2 months ago

This is indeed something to fix. Thanks for reporting @ashtonmeuser