pub struct Compiler { /* private fields */ }Expand description
The XLOG compiler orchestrates the full compilation pipeline.
This is the core AST-to-RIR compiler. It does not resolve imports or expand
user-defined functions; callers must perform those source-level steps first,
or use the execution-facing LogicProgram compilation APIs.
§Example
use xlog_logic::compile::Compiler;
let mut compiler = Compiler::new();
let plan = compiler.compile(r#"
edge(1, 2).
edge(2, 3).
reach(X, Y) :- edge(X, Y).
reach(X, Z) :- reach(X, Y), edge(Y, Z).
"#)?;Implementations§
Source§impl Compiler
impl Compiler
Sourcepub fn set_max_active_rules(&mut self, max: usize)
pub fn set_max_active_rules(&mut self, max: usize)
Set the maximum active rules for TensorMaskedJoin (16..=128).
Sourcepub fn compile(&mut self, source: &str) -> Result<ExecutionPlan>
pub fn compile(&mut self, source: &str) -> Result<ExecutionPlan>
Compile XLOG source code into an execution plan.
This is the main entry point for core compilation. It chains together:
- Parsing (source → AST)
- Stratification (analyze dependencies, check for cycles)
- Lowering (AST → Relational IR execution plan)
Function definitions and calls must already be expanded into the core
language. Use an execution-facing LogicProgram API when source-level
import resolution and function normalization are required.
§Arguments
source- The XLOG source code as a string
§Returns
Ok(ExecutionPlan)- The compiled execution plan ready for executionErr(XlogError)- If any compilation phase fails:XlogError::Parse- Syntax errors in the sourceXlogError::StratificationCycle- Unstratifiable negation/aggregationXlogError::Compilation- Other semantic errors
§Example
let mut compiler = Compiler::new();
// Compile a simple transitive closure program
let plan = compiler.compile(r#"
edge(1, 2).
edge(2, 3).
reach(X, Y) :- edge(X, Y).
reach(X, Z) :- reach(X, Y), edge(Y, Z).
"#)?;
// The plan can now be executed by xlog-runtimeSourcepub fn compile_with_stats_snapshot(
&mut self,
source: &str,
stats_snapshot: Option<&StatsSnapshot>,
) -> Result<ExecutionPlan>
pub fn compile_with_stats_snapshot( &mut self, source: &str, stats_snapshot: Option<&StatsSnapshot>, ) -> Result<ExecutionPlan>
Compile XLOG source code into an execution plan, optionally seeding the optimizer with a runtime statistics snapshot.
This entry point delegates through the composable config-aware API
with CompilerConfig::default(), which preserves existing triangle,
4-cycle, recursive, and selectivity-aware dispatch behavior
bit-identically.
Sourcepub fn compile_with_config_and_stats_snapshot(
&mut self,
source: &str,
config: &CompilerConfig,
stats_snapshot: Option<&StatsSnapshot>,
) -> Result<ExecutionPlan>
pub fn compile_with_config_and_stats_snapshot( &mut self, source: &str, config: &CompilerConfig, stats_snapshot: Option<&StatsSnapshot>, ) -> Result<ExecutionPlan>
Composable entry point that accepts a CompilerConfig.
Default-config callers should keep using compile() /
compile_with_stats_snapshot(). This entry point exists so callers can
enable the variable-ordering cost model per call without an environment
override.
Sourcepub fn compile_program(&mut self, program: &Program) -> Result<ExecutionPlan>
pub fn compile_program(&mut self, program: &Program) -> Result<ExecutionPlan>
Compile a parsed XLOG program into an execution plan.
This is useful for callers that want to inspect the AST (facts, queries, constraints) while compiling without reparsing. The parsed program must already be normalized to the core language, including function expansion.
Sourcepub fn compile_prepared_program(
&mut self,
program: &Program,
) -> Result<ExecutionPlan>
pub fn compile_prepared_program( &mut self, program: &Program, ) -> Result<ExecutionPlan>
Compile a program whose authored constraint identities were prepared at the outer full-program boundary.
Sourcepub fn compile_program_with_stats_snapshot(
&mut self,
program: &Program,
stats_snapshot: Option<&StatsSnapshot>,
) -> Result<ExecutionPlan>
pub fn compile_program_with_stats_snapshot( &mut self, program: &Program, stats_snapshot: Option<&StatsSnapshot>, ) -> Result<ExecutionPlan>
Compile a parsed XLOG program into an execution plan, optionally seeding the optimizer.
Delegates to Self::compile_program_with_config_and_stats_snapshot
with CompilerConfig::default().
Sourcepub fn compile_prepared_program_with_stats_snapshot(
&mut self,
program: &Program,
stats_snapshot: Option<&StatsSnapshot>,
) -> Result<ExecutionPlan>
pub fn compile_prepared_program_with_stats_snapshot( &mut self, program: &Program, stats_snapshot: Option<&StatsSnapshot>, ) -> Result<ExecutionPlan>
Compile an already prepared program with an optional statistics snapshot.
Sourcepub fn compile_program_with_config_and_stats_snapshot(
&mut self,
program: &Program,
config: &CompilerConfig,
stats_snapshot: Option<&StatsSnapshot>,
) -> Result<ExecutionPlan>
pub fn compile_program_with_config_and_stats_snapshot( &mut self, program: &Program, config: &CompilerConfig, stats_snapshot: Option<&StatsSnapshot>, ) -> Result<ExecutionPlan>
Composable program-level entry point.
config is currently consumed only by the promoter when it wires the
variable-ordering cost model. With CompilerConfig::default(), the
promoter keeps the default variable order.
Sourcepub fn compile_owned_program_with_config_and_stats_snapshot(
&mut self,
program: Program,
config: &CompilerConfig,
stats_snapshot: Option<&StatsSnapshot>,
) -> Result<ExecutionPlan>
pub fn compile_owned_program_with_config_and_stats_snapshot( &mut self, program: Program, config: &CompilerConfig, stats_snapshot: Option<&StatsSnapshot>, ) -> Result<ExecutionPlan>
Self::compile_program_with_config_and_stats_snapshot for a program
the caller hands over by value (no clone of the AST).
Sourcepub fn compile_prepared_program_with_config_and_stats_snapshot(
&mut self,
program: &Program,
config: &CompilerConfig,
stats_snapshot: Option<&StatsSnapshot>,
) -> Result<ExecutionPlan>
pub fn compile_prepared_program_with_config_and_stats_snapshot( &mut self, program: &Program, config: &CompilerConfig, stats_snapshot: Option<&StatsSnapshot>, ) -> Result<ExecutionPlan>
Config-aware compilation for an already prepared program.
Sourcepub fn compile_prepared_owned_program_with_config_and_stats_snapshot(
&mut self,
program: Program,
config: &CompilerConfig,
stats_snapshot: Option<&StatsSnapshot>,
) -> Result<ExecutionPlan>
pub fn compile_prepared_owned_program_with_config_and_stats_snapshot( &mut self, program: Program, config: &CompilerConfig, stats_snapshot: Option<&StatsSnapshot>, ) -> Result<ExecutionPlan>
Self::compile_prepared_program_with_config_and_stats_snapshot for a
program handed over by value.
The frontend passes (desugar → meta → list → magic sets) each take and
return the Program by value, so a fact-heavy AST is never cloned
between passes; the &Program entry points clone exactly once.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the compiler state for a fresh compilation.
This creates a new lowerer, clearing any cached schemas or relation IDs from previous compilations.