bytecodealliance / wasm-tools

CLI and Rust libraries for low-level manipulation of WebAssembly modules
Apache License 2.0
1.21k stars 224 forks source link

wasm-tools validate do not give file location #1608

Open peter-jerry-ye opened 3 weeks ago

peter-jerry-ye commented 3 weeks ago

Hello,

I'm trying to validate a wat file with wasm-tools validate a.wat, and I'm getting an error message like this:

error: func 49 failed to validate

Caused by:
    0: type mismatch: expected f64, found i32 (at offset 0xb07)

I know I can figure out the error position by running wasm-tools parse a.wat | wasm-tools print -p, but is it possible that wasm-tools validate provide the file location directly? For example, wat2wasm would give me a.wat:592:3: error xxx

alexcrichton commented 3 weeks ago

Thanks for the report! This is due to how the text format is supported architecturally throughout subcommands which is that it's immediately converted to binary and then it's as-if only the binary was provided. Supporting mapping binary locations back to the original *.wat file would require source maps of some kind which aren't supported by the wast crate right now. It's thoeretically possible to do so but might be a chunk of work.