Improve error message for failed function compiles (#4340)

* Improve error message for failed function compiles

Add in the wasm function index, the name if specified, and the function
offset in the original file to assist in debugging failed function compiles.

* Review commments
This commit is contained in:
Alex Crichton
2022-06-28 12:20:25 -05:00
committed by GitHub
parent 17ed95ad8c
commit baabd40b94

View File

@@ -374,9 +374,21 @@ impl Module {
let functions = functions.into_iter().collect::<Vec<_>>(); let functions = functions.into_iter().collect::<Vec<_>>();
let funcs = engine let funcs = engine
.run_maybe_parallel(functions, |(index, func)| { .run_maybe_parallel(functions, |(index, func)| {
let offset = func.body.range().start;
engine engine
.compiler() .compiler()
.compile_function(&translation, index, func, tunables, types) .compile_function(&translation, index, func, tunables, types)
.with_context(|| {
let index = translation.module.func_index(index);
let name = match translation.debuginfo.name_section.func_names.get(&index) {
Some(name) => format!(" (`{}`)", name),
None => String::new(),
};
let index = index.as_u32();
format!(
"failed to compile wasm function {index}{name} at offset {offset:#x}"
)
})
})? })?
.into_iter() .into_iter()
.collect(); .collect();