Skip to main content

Compiler

Struct Compiler 

Source
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

Source

pub fn new() -> Self

Create a new compiler instance.

Source

pub fn set_max_active_rules(&mut self, max: usize)

Set the maximum active rules for TensorMaskedJoin (16..=128).

Source

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:

  1. Parsing (source → AST)
  2. Stratification (analyze dependencies, check for cycles)
  3. 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 execution
  • Err(XlogError) - If any compilation phase fails:
    • XlogError::Parse - Syntax errors in the source
    • XlogError::StratificationCycle - Unstratifiable negation/aggregation
    • XlogError::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-runtime
Source

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.

Source

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.

Source

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.

Source

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.

Source

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().

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn rel_ids(&self) -> &HashMap<String, RelId>

Get the mapping from predicate names to relation IDs after compilation.

This mapping is needed to register relations in the executor with the correct RelIds.

Source

pub fn schemas(&self) -> &HashMap<String, Schema>

Get the inferred schemas for predicates after compilation.

These schemas are needed to create GPU buffers with correct column types.

Trait Implementations§

Source§

impl Default for Compiler

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.