Skip to main content

cranelift_codegen/
result.rs

1//! Result and error types representing the outcome of compiling a function.
2
3use crate::verifier::VerifierErrors;
4use thiserror::Error;
5
6/// A compilation error.
7///
8/// When Cranelift fails to compile a function, it will return one of these error codes.
9#[derive(Error, Debug, PartialEq, Eq)]
10pub enum CodegenError {
11    /// A list of IR verifier errors.
12    ///
13    /// This always represents a bug, either in the code that generated IR for Cranelift, or a bug
14    /// in Cranelift itself.
15    #[error("Verifier errors")]
16    Verifier(#[from] VerifierErrors),
17
18    /// An implementation limit was exceeded.
19    ///
20    /// Cranelift can compile very large and complicated functions, but the [implementation has
21    /// limits][limits] that cause compilation to fail when they are exceeded.
22    ///
23    /// [limits]: https://cranelift.readthedocs.io/en/latest/ir.html#implementation-limits
24    #[error("Implementation limit exceeded")]
25    ImplLimitExceeded,
26
27    /// The code size for the function is too large.
28    ///
29    /// Different target ISAs may impose a limit on the size of a compiled function. If that limit
30    /// is exceeded, compilation fails.
31    #[error("Code for function is too large")]
32    CodeTooLarge,
33}
34
35/// A convenient alias for a `Result` that uses `CodegenError` as the error type.
36pub type CodegenResult<T> = Result<T, CodegenError>;