Skip to main content

Module error_recovery

Module error_recovery 

Source
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::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::*.

Structs§

Diagnostic
A single diagnostic produced during tolerant compilation.
DiagnosticCollector
Shared, thread-safe collector for Diagnostic values.
PartialCompilationResult
Result returned by TolerantCompiler::compile_program.
SourceSpan
Lightweight span into a source program — a byte range [start, end) plus an optional filename or logical label.
TolerantCompiler
Tolerant compilation façade.

Enums§

RecoveryAction
Action the tolerant driver takes after reporting a diagnostic.
RecoveryStrategy
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.