#[non_exhaustive]pub enum JitError {
InvalidIr(ValidationError),
Unsupported(&'static str),
Codegen(String),
Memory(PagerError),
}Expand description
The reason a function could not be compiled and made executable.
A compile runs three stages, and each contributes a variant: the input is
validated as well-formed SSA, translated and lowered to machine code, then placed
in executable memory. InvalidIr reports the first stage
rejecting malformed input; Unsupported reports a
function that is valid but uses something this back-end does not lower, or a host
the code generator cannot target; Codegen reports the code
generator itself failing; and Memory reports executable
memory being unavailable.
The enum is #[non_exhaustive]: a future release may add a variant without it
being a breaking change, so a match on it must keep a wildcard arm. It implements
Display and std::error::Error, and converts from the two
wrapped error types with From, so ? propagates them.
§Examples
use jit_lang::{compile, JitError};
use ir_lang::{Builder, Type};
// A function whose entry block never gets a terminator is not well-formed.
let func = Builder::new("f", &[], Type::Unit).finish();
match compile(&func) {
Err(JitError::InvalidIr(reason)) => {
assert!(reason.to_string().contains("terminator"));
}
other => panic!("expected InvalidIr, got {other:?}"),
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
InvalidIr(ValidationError)
The function did not pass Function::validate;
the wrapped ValidationError names the offending block or value. The code
generator is never handed input the IR already forbids.
Unsupported(&'static str)
The function is well-formed but uses something this back-end cannot lower, or
the host architecture has no code generator. The message says which — for
example a parameter typed Unit, which has no value at
the machine level, or an unsupported target CPU.
Codegen(String)
The native code generator rejected the translated function. This does not happen for a validated function the translator accepts; it is the surfaced form of an internal code-generation failure, carried as the generator’s own message rather than swallowed.
Memory(PagerError)
Executable memory for the compiled code could not be obtained or protected;
the wrapped PagerError says why (the mapping failed, or the
write-then-execute protection change was refused).
Trait Implementations§
Source§impl Error for JitError
impl Error for JitError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()