WebAssembly / WASI

WebAssembly System Interface
Other
4.75k stars 243 forks source link

What is the ABI of the Result<> type? #499

Open hehaoqian opened 1 year ago

hehaoqian commented 1 year ago

snapshot_docs uses Result<> type

For example, args_sizes_get() -> Result<(size, size), errno>

This type does not seems to be a C type, but looks like a type in the Rust programming language.

I do not find ABI definition in BasicCABI, for type similar to Result<>

Does Result<> has the same layout as

#[repr(C)]
enum Result<T, E> {
   Ok(T),
   Err(E),
}

What the layout of the following Result<>? args_get(argv: Pointer<Pointer<u8>>, argv_buf: Pointer<u8>) -> Result<(), errno> args_sizes_get() -> Result<(size, size), errno> fd_write(fd: fd, iovs: ciovec_array) -> Result<size, errno>

sunfishcode commented 1 year ago

There is no ABI for the Rust-style Result; tHe docs describing a Rust-style Result are describing a high-level language binding, which would be wrapped around the lower-level ABI into a more idiomatic Rust API.

hehaoqian commented 1 year ago

@sunfishcode Can you explain what exactly is the layout of the underlying lower-level stuff?