1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Partial error recovery for multi-expression compilation.
//!
//! TensorLogic historically supported a single **strict** compilation mode:
//! [`crate::compile_to_einsum`] returns the first error it encounters and
//! aborts the whole compile. For real programs that carry several rules or
//! expressions this is overly brittle — a single bad rule prevents useful
//! feedback about the rest of the program.
//!
//! This module introduces a complementary **tolerant** mode. In tolerant
//! mode the compiler treats the input as a *program* (slice of
//! [`tensorlogic_ir::TLExpr`]), compiles each expression in isolation, and
//! collects per-expression diagnostics into a
//! [`DiagnosticCollector`]. Non-fatal problems in one expression never
//! prevent siblings from compiling.
//!
//! # Quick start
//!
//! ```
//! use tensorlogic_compiler::error_recovery::{
//! compile_tolerant, RecoveryStrategy, Severity,
//! };
//! use tensorlogic_ir::{TLExpr, Term};
//!
//! let program = vec![
//! TLExpr::pred("p", vec![Term::var("x")]),
//! TLExpr::pred("q", vec![Term::var("y")]),
//! ];
//! let result = compile_tolerant(&program);
//! assert_eq!(result.graphs.len(), 2);
//! assert!(result.is_all_success());
//! assert!(result.diagnostics.is_empty());
//! # let _ = RecoveryStrategy::SkipOnError;
//! # let _ = Severity::Error;
//! ```
//!
//! # Design
//!
//! * **Scope**: recovery happens at the *compile-one-expression boundary*.
//! Each expression's own compilation path keeps propagating `Result::Err`
//! internally; the tolerant driver merely intercepts that `Err` (and any
//! panic, via [`std::panic::catch_unwind`]) and converts it into a
//! [`Diagnostic`]. No `catch_unwind` is sprinkled into inner passes.
//! * **Strict mode is untouched**: [`crate::compile_to_einsum`] and
//! [`crate::compile_to_einsum_with_context`] retain their pre-existing
//! behaviour. The tolerant driver is a *new* public entry point.
//! * **Configurable policy**: [`RecoveryStrategy`] selects one of
//! `SkipOnError`, `SkipOnFatal`, `AbortOnAny` — see its docs for the
//! full decision table.
//!
//! # Re-exports
//!
//! The commonly used types are re-exported at the module root so downstream
//! callers can `use tensorlogic_compiler::error_recovery::*`.
pub use DiagnosticCollector;
pub use ;
pub use ;
pub use ;