Improve error messages received from Cranelift (#583)
As discussed in https://github.com/bytecodealliance/cranelift/pull/1226, the context of Cranelift errors is lost after exiting the scope containing the Cranelift function. `CodegenError` then only contains something like `inst2: arg 0 (v4) has type i16x8, expected i8x16`, which is rarely enough information for investigating a codegen failure. This change uses Cranelift's `pretty_error` function to improve the error messages wrapped in `CompileError`; `CompileError` has lost the reference to `CodegenError` due to `pretty_error` taking ownership but this seems preferable since no backtrace is attached and losing the pretty-printed context would be worse (if `CodegenError` gains a `Backtrace` or implements `Clone` we can revisit this).
This commit is contained in:
@@ -5,7 +5,7 @@ use crate::address_map::{ModuleAddressMap, ValueLabelsRanges};
|
||||
use crate::module;
|
||||
use crate::module_environ::FunctionBodyData;
|
||||
use alloc::vec::Vec;
|
||||
use cranelift_codegen::{binemit, ir, isa, CodegenError};
|
||||
use cranelift_codegen::{binemit, ir, isa};
|
||||
use cranelift_entity::PrimaryMap;
|
||||
use cranelift_wasm::{DefinedFuncIndex, FuncIndex, ModuleTranslationState, WasmError};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -156,8 +156,8 @@ pub enum CompileError {
|
||||
Wasm(#[from] WasmError),
|
||||
|
||||
/// A compilation error occured.
|
||||
#[error("Compilation error")]
|
||||
Codegen(#[from] CodegenError),
|
||||
#[error("Compilation error: {0}")]
|
||||
Codegen(String),
|
||||
|
||||
/// A compilation error occured.
|
||||
#[error("Debug info is not supported with this configuration")]
|
||||
|
||||
Reference in New Issue
Block a user