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:
Andrew Brown
2019-11-16 11:42:17 -08:00
committed by Dan Gohman
parent 7d47a04277
commit ea04aa5b98
4 changed files with 38 additions and 12 deletions

View File

@@ -10,6 +10,7 @@ use alloc::vec::Vec;
use core::convert::TryFrom;
use cranelift_codegen::ir::InstBuilder;
use cranelift_codegen::isa::{TargetFrontendConfig, TargetIsa};
use cranelift_codegen::print_errors::pretty_error;
use cranelift_codegen::Context;
use cranelift_codegen::{binemit, ir};
use cranelift_entity::{EntityRef, PrimaryMap};
@@ -336,7 +337,13 @@ fn make_trampoline(
&mut trap_sink,
&mut stackmap_sink,
)
.map_err(|error| SetupError::Compile(CompileError::Codegen(error)))?;
.map_err(|error| {
SetupError::Compile(CompileError::Codegen(pretty_error(
&context.func,
Some(isa),
error,
)))
})?;
context.emit_unwind_info(isa, &mut unwind_info);