1 //! Result and error types representing the outcome of compiling a function.
2 
3 use crate::verifier::VerifierErrors;
4 use std::string::String;
5 use thiserror::Error;
6 
7 /// A compilation error.
8 ///
9 /// When Cranelift fails to compile a function, it will return one of these error codes.
10 #[derive(Error, Debug, PartialEq, Eq)]
11 pub enum CodegenError {
12     /// A list of IR verifier errors.
13     ///
14     /// This always represents a bug, either in the code that generated IR for Cranelift, or a bug
15     /// in Cranelift itself.
16     #[error("Verifier errors")]
17     Verifier(#[from] VerifierErrors),
18 
19     /// An implementation limit was exceeded.
20     ///
21     /// Cranelift can compile very large and complicated functions, but the [implementation has
22     /// limits][limits] that cause compilation to fail when they are exceeded.
23     ///
24     /// [limits]: https://github.com/bytecodealliance/wasmtime/blob/master/cranelift/docs/ir.md#implementation-limits
25     #[error("Implementation limit exceeded")]
26     ImplLimitExceeded,
27 
28     /// The code size for the function is too large.
29     ///
30     /// Different target ISAs may impose a limit on the size of a compiled function. If that limit
31     /// is exceeded, compilation fails.
32     #[error("Code for function is too large")]
33     CodeTooLarge,
34 
35     /// Something is not supported by the code generator. This might be an indication that a
36     /// feature is used without explicitly enabling it, or that something is temporarily
37     /// unsupported by a given target backend.
38     #[error("Unsupported feature: {0}")]
39     Unsupported(String),
40 
41     /// A failure to map Cranelift register representation to a DWARF register representation.
42     #[cfg(feature = "unwind")]
43     #[error("Register mapping error")]
44     RegisterMappingError(crate::isa::unwind::systemv::RegisterMappingError),
45 }
46 
47 /// A convenient alias for a `Result` that uses `CodegenError` as the error type.
48 pub type CodegenResult<T> = Result<T, CodegenError>;
49