Expand description
Incremental compilation for efficient recompilation when expressions change.
This module provides an incremental compilation system that tracks dependencies and recompiles only the parts of expressions that have changed. This is crucial for interactive environments like REPLs, notebooks, and IDEs where expressions are frequently modified.
§Architecture
The incremental compilation system consists of three main components:
-
DependencyTracker: Tracks what each expression depends on (predicates, variables, domains, configurations).
-
ChangeDetector: Detects changes to the compilation context (predicate signatures, domains, configurations) and determines what needs recompilation.
-
IncrementalCompiler: Manages the compilation state, computes minimal invalidation sets, and recompiles only affected sub-expressions.
§Example
use tensorlogic_compiler::{CompilerContext, incremental::IncrementalCompiler};
use tensorlogic_ir::{TLExpr, Term};
let mut ctx = CompilerContext::new();
ctx.add_domain("Person", 100);
let mut compiler = IncrementalCompiler::new(ctx);
// Initial compilation
let expr1 = TLExpr::pred("knows", vec![Term::var("x"), Term::var("y")]);
let graph1 = compiler.compile(&expr1).unwrap();
// Compile similar expression - some parts will be reused
let expr2 = TLExpr::and(
TLExpr::pred("knows", vec![Term::var("x"), Term::var("y")]),
TLExpr::pred("likes", vec![Term::var("x"), Term::var("z")]),
);
let graph2 = compiler.compile(&expr2).unwrap();
// Check incremental compilation stats
let stats = compiler.stats();
println!("Nodes reused: {}", stats.nodes_reused);
println!("Nodes compiled: {}", stats.nodes_compiled);
println!("Reuse rate: {:.1}%", stats.reuse_rate() * 100.0);Structs§
- Change
Detector - Detects changes to the compilation context.
- Change
Set - Describes what has changed in the compilation context.
- Expression
Dependencies - Tracks dependencies of compiled expressions.
- Incremental
Compiler - Incremental compiler that reuses previously compiled expressions.
- Incremental
Stats - Statistics for incremental compilation.