Skip to main content

cubecl_cpp/
error.rs

1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum CompileError {
5    #[error("Encountered unsupported type `{0}`")]
6    UnsupportedType(String),
7    #[error("Encountered unsupported operation `{0}`")]
8    UnsupportedOp(String),
9}
10
11pub type Result<T> = core::result::Result<T, CompileError>;
12
13/// Errors gathered while emitting C++ source, stored on the [`Context`](pliron::context::Context)
14/// as an aux type. Emission runs under `Display` and can't fail, so ops without a lowering are
15/// recorded here and `compile_ir` fails the compilation once emission finishes.
16#[derive(Default)]
17pub struct EmissionErrors(core::cell::RefCell<Vec<CompileError>>);
18
19impl EmissionErrors {
20    /// Record an error hit while emitting an operation.
21    pub fn record(&self, error: CompileError) {
22        self.0.borrow_mut().push(error);
23    }
24
25    /// Take everything recorded so far, leaving the list empty.
26    pub fn take(&self) -> Vec<CompileError> {
27        core::mem::take(&mut self.0.borrow_mut())
28    }
29}