1 //! Result and error types representing the outcome of compiling a function.
2 
3 use crate::verifier::VerifierErrors;
4 use 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)]
10 pub 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://github.com/bytecodealliance/wasmtime/blob/master/cranelift/docs/ir.md#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     /// A failure to map Cranelift register representation to a DWARF register representation.
35     #[cfg(feature = "unwind")]
36     #[error("Register mapping error")]
37     RegisterMappingError(crate::isa::unwind::systemv::RegisterMappingError),
38 }
39 
40 /// A convenient alias for a `Result` that uses `CodegenError` as the error type.
41 pub type CodegenResult<T> = Result<T, CodegenError>;
42