srdatalog.ir.mir.passes

MIR optimization passes. Mirror src/srdatalog/mir/{pre_reconstruct_rebuild, clause_order_reorder, prefix_source_reorder}.nim. Each operates on a seq[LoweredStep] (represented in Python as list[tuple[MirNode, bool]]).

Order (matches Nim’s registerMirOptimizePass priorities): 0. insert_pre_reconstruct_rebuilds

  1. apply_clause_order_reordering

  2. apply_prefix_source_reordering

  3. balanced_scan_pass — DEFERRED (DSL lacks balanced pragma)

Module Contents

Functions

apply_all_mir_passes

Run the ported MIR optimization passes in Nim order.

apply_balanced_scan_pass

Apply balanced-scan -> positioned-extract transform to every ExecutePipeline. No-op when the Python DSL hasn’t emitted a BalancedScan (current default: never, since balanced-scan lowering isn’t wired in).

apply_clause_order_reordering

Reorder every ColumnJoin/CartesianJoin’s sources by the enclosing ExecutePipeline’s clause_order. Mutates in place; returns steps for chain convenience.

apply_prefix_source_reordering

Move prefixed sources to the front of every ColumnJoin/CartesianJoin (avoids “galloping from root” on unprefixed sources). Mutates in place.

insert_pre_reconstruct_rebuilds

After every PostStratumReconstructInternCols step, insert any RebuildIndex(FULL) ops for indices of this relation that subsequent strata will read but that this stratum didn’t merge to FULL.

API

srdatalog.ir.mir.passes.apply_all_mir_passes(steps: list[tuple[srdatalog.ir.mir.types.MirNode, bool]]) list[tuple[srdatalog.ir.mir.types.MirNode, bool]][source]

Run the ported MIR optimization passes in Nim order.

srdatalog.ir.mir.passes.apply_balanced_scan_pass(steps: list[tuple[srdatalog.ir.mir.types.MirNode, bool]]) list[tuple[srdatalog.ir.mir.types.MirNode, bool]][source]

Apply balanced-scan -> positioned-extract transform to every ExecutePipeline. No-op when the Python DSL hasn’t emitted a BalancedScan (current default: never, since balanced-scan lowering isn’t wired in).

srdatalog.ir.mir.passes.apply_clause_order_reordering(steps: list[tuple[srdatalog.ir.mir.types.MirNode, bool]]) list[tuple[srdatalog.ir.mir.types.MirNode, bool]][source]

Reorder every ColumnJoin/CartesianJoin’s sources by the enclosing ExecutePipeline’s clause_order. Mutates in place; returns steps for chain convenience.

srdatalog.ir.mir.passes.apply_prefix_source_reordering(steps: list[tuple[srdatalog.ir.mir.types.MirNode, bool]]) list[tuple[srdatalog.ir.mir.types.MirNode, bool]][source]

Move prefixed sources to the front of every ColumnJoin/CartesianJoin (avoids “galloping from root” on unprefixed sources). Mutates in place.

srdatalog.ir.mir.passes.insert_pre_reconstruct_rebuilds(steps: list[tuple[srdatalog.ir.mir.types.MirNode, bool]]) list[tuple[srdatalog.ir.mir.types.MirNode, bool]][source]

After every PostStratumReconstructInternCols step, insert any RebuildIndex(FULL) ops for indices of this relation that subsequent strata will read but that this stratum didn’t merge to FULL.