Skip to main content

relon_codegen_llvm/
error.rs

1//! Error types surfaced by the LLVM AOT pipeline.
2//!
3//! Modelled after `relon_codegen_cranelift::CraneliftError` so the
4//! relon facade can wrap both backends through the same
5//! `BackendError` shape — switching backends should not change which
6//! variants the host needs to match on.
7
8use thiserror::Error;
9
10/// Top-level error type for the LLVM AOT backend. Construction sites
11/// fall into four buckets:
12///
13/// * [`LlvmError::Parse`] — the parser rejected the source. Only
14///   produced through `from_source` paths; the direct-IR entry
15///   points cannot hit this arm.
16/// * [`LlvmError::Analyze`] — analyzer rejected the source. Reports
17///   the diagnostic count instead of the full message bundle to keep
18///   the error variant cheap to clone; hosts that want the full
19///   diagnostic stream should drive `relon_analyzer::analyze`
20///   directly.
21/// * [`LlvmError::UnsupportedSignature`] — the IR module's entry
22///   signature is outside the Phase A bootstrap envelope (legacy
23///   `(I64...) -> I64`). Buffer-protocol entries fall here today.
24/// * [`LlvmError::Codegen`] — the LLVM emitter / JIT engine refused
25///   the input (unsupported op, IR builder failure, JIT setup
26///   failure). The carried `String` is the inkwell builder's own
27///   message; we don't try to map it to a typed enum at this stage.
28#[derive(Debug, Error)]
29pub enum LlvmError {
30    /// Parser failure. Only reachable through `from_source`-style
31    /// entry points (Phase B+); direct-IR paths skip this stage.
32    #[error("parse error: {0}")]
33    Parse(String),
34
35    /// Analyzer rejected the source with `count` errors. Phase A
36    /// returns the count so the relon facade can wrap it without
37    /// having to allocate a diagnostic vector.
38    #[error("analyze error: {0} diagnostic(s)")]
39    Analyze(usize),
40
41    /// The IR module's entry function does not match the Phase A
42    /// envelope (legacy `(I64...) -> I64`). The carried string names
43    /// the rejected param / return type so the host can decide
44    /// whether to retry through the cranelift backend.
45    #[error("unsupported entry signature: {0}")]
46    UnsupportedSignature(String),
47
48    /// LLVM emitter / JIT engine surfaced an error during compile.
49    /// Wraps the inkwell builder message rather than a typed enum
50    /// — Phase A keeps the surface narrow so the bootstrap test can
51    /// fail loudly without locking us into a permanent error
52    /// taxonomy.
53    #[error("LLVM codegen failed: {0}")]
54    Codegen(String),
55}