Expand description
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());§Design
- Scope: recovery happens at the compile-one-expression boundary.
Each expression’s own compilation path keeps propagating
Result::Errinternally; the tolerant driver merely intercepts thatErr(and any panic, viastd::panic::catch_unwind) and converts it into aDiagnostic. Nocatch_unwindis sprinkled into inner passes. - Strict mode is untouched:
crate::compile_to_einsumandcrate::compile_to_einsum_with_contextretain their pre-existing behaviour. The tolerant driver is a new public entry point. - Configurable policy:
RecoveryStrategyselects one ofSkipOnError,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::*.
Structs§
- Diagnostic
- A single diagnostic produced during tolerant compilation.
- Diagnostic
Collector - Shared, thread-safe collector for
Diagnosticvalues. - Partial
Compilation Result - Result returned by
TolerantCompiler::compile_program. - Source
Span - Lightweight span into a source program — a byte range
[start, end)plus an optional filename or logical label. - Tolerant
Compiler - Tolerant compilation façade.
Enums§
- Recovery
Action - Action the tolerant driver takes after reporting a diagnostic.
- Recovery
Strategy - Configurable error-recovery policy for the tolerant compiler.
- Severity
- Diagnostic severity, ordered from least to most serious.
Functions§
- compile_
tolerant - Public free function — tolerant counterpart of
crate::compile_to_einsum. - compile_
tolerant_ with_ strategy - Public free function — tolerant compilation with a caller-chosen strategy.