Skip to content

Commit

Permalink
Emit CLIF even if compilation fails
Browse files Browse the repository at this point in the history
Just after bytecodealliance#10011 I ran into a case where I wanted to peek at CLIF after
compilation failed but the structure of the code failed to enable this,
so I've refactored `--emit-clif` to emit the CLIF even if the lowering
step fails.
  • Loading branch information
alexcrichton committed Jan 14, 2025
1 parent 21ab8ea commit 2ba60e4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions crates/cranelift/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,14 @@ impl FunctionCompiler<'_> {
) -> Result<(WasmFunctionInfo, CompiledFunction), CompileError> {
let context = &mut self.cx.codegen_context;
let isa = &*self.compiler.isa;
let mut compiled_code =
compile_maybe_cached(context, isa, self.cx.incremental_cache_ctx.as_mut())?;

// Run compilation, but don't propagate the error just yet. This'll
// mutate `context` and the IR contained within (optionally) but it may
// fail if the backend has a bug in it. Use `context` after this
// finishes to optionally emit CLIF and then after that's done actually
// propagate the error if one happened.
let compilation_result =
compile_maybe_cached(context, isa, self.cx.incremental_cache_ctx.as_mut());

if let Some(path) = &self.compiler.clif_dir {
use std::io::Write;
Expand All @@ -984,6 +990,8 @@ impl FunctionCompiler<'_> {
write!(output, "{}", context.func.display()).unwrap();
}

let mut compiled_code = compilation_result?;

// Give wasm functions, user defined code, a "preferred" alignment
// instead of the minimum alignment as this can help perf in niche
// situations.
Expand Down

0 comments on commit 2ba60e4

Please sign in to comment.