srdatalog.ir.mir.types

Python mirror of src/srdatalog/mir/mir_types.nim.

Pure IR data. Distinct from the existing python/mir_commands.py which emits C++ for mhk’s codegen and carries codegen-side state (cursor slots, program backref). My MirNode types carry only what the Nim MIR carries; they are suitable for S-expr printing and byte-diff against Nim golden.

Mapping to Nim: moColumnSource -> ColumnSource moScan -> Scan moColumnJoin -> ColumnJoin moCartesianJoin -> CartesianJoin moFilter -> Filter moNegation -> Negation moInsertInto -> InsertInto moExecutePipeline -> ExecutePipeline moRebuildIndex -> RebuildIndex moClearRelation -> ClearRelation moCheckSize -> CheckSize moComputeDelta -> ComputeDelta moComputeDeltaIndex -> ComputeDeltaIndex moMergeIndex -> MergeIndex moMergeRelation -> MergeRelation moRebuildIndexFromIndex -> RebuildIndexFromIndex moFixpointPlan -> FixpointPlan moBlock -> Block moProgram -> Program

All registered Nim MIR op kinds are now covered. Advanced ops (Aggregate, CreateFlatView, InnerPipeline, ProbeJoin, GatherColumn) have types + emitters but aren’t yet produced by Python lowering; they’re here so downstream codegen bridges and future lowering extensions have the node shapes to target.

Module Contents

Classes

Aggregate

(aggregate #:var cnt #:func AggCount #:index (Rel 0 1) #:ver FULL #:prefix (x y))

BalancedScan

(balanced-scan #:group-var v #:source1 (…) #:source2 (…))

Block

(block <instructions…>)

CartesianJoin

(cartesian-join #:vars (…) #:var-from-source ((…)) #:sources (…))

CheckSize

(check-size #:schema R #:ver V)

ClearRelation

(clear-relation #:schema R #:ver V)

ColumnJoin

(column-join #:var x #:sources (…))

ColumnSource

(column-source #:index (Rel cols…) #:ver V #:prefix (vars))

ComputeDelta

(compute-delta #:schema R)

ComputeDeltaIndex

(compute-delta-index #:schema R #:canonical-index (cols…))

ConstantBind

(constant-bind #:var v #:code “…” #:deps (…))

CreateFlatView

(create-flat-view #:schema R #:index (cols…) #:ver V)

ExecutePipeline

(execute-pipeline #:rule N #:sources (tuple …) #:dests (tuple …) )

Filter

(filter #:vars (…) #:code “…”)

FixpointPlan

(fixpoint-plan <instructions…>)

GatherColumn

(gather-column …) — binary-join mode node. Dereferences input_buffer of row IDs into values of column from rel_name, binding the result to output_var.

InjectCppHook

(inject-cpp-hook #:rule R #:code “…”) — raw C++ injection point.

InnerPipeline

(inner-pipeline #:rule R #:bound-vars (…) #:handles (…) #:ops (…))

InsertInto

(insert-into #:schema R #:ver V #:dedup-index (cols…) #:terms (vars))

MergeIndex

(merge-index #:index (R cols…))

MergeRelation

(merge-relation #:schema R)

Negation

(negation #:schema R #:ver V #:index (R cols…) #:prefix (…))

ParallelGroup

(parallel-group <ops…>) — independent ops that can run concurrently.

PositionedExtract

(positioned-extract #:var v #:sources ((…) (…)) #:bind (…))

PostStratumReconstructInternCols

(post-stratum-reconstruct-intern-cols #:rel R #:canonical-index (cols…))

ProbeJoin

(probe-join …) — binary-join mode node. Performs a binary-search probe of probe_rel keyed on join_key, writing row-id pairs into output_buffer. Uses merge-path balancing for unbalanced output.

Program

(program (step #:recursive b ) …)

RebuildIndex

(rebuild-index #:index (R cols…) #:ver V)

RebuildIndexFromIndex

(rebuild-index-from-index #:source (R cols…) #:target (R cols…) #:ver V)

Scan

(scan #:vars (…) #:index (Rel cols…) #:ver V #:prefix (…))

Data

API

class srdatalog.ir.mir.types.Aggregate[source]

(aggregate #:var cnt #:func AggCount #:index (Rel 0 1) #:ver FULL #:prefix (x y))

Aggregation body clause lowered to MIR. result_var is the variable bound by the aggregate; func is the C++ aggregation type (AggCount / AggSum / … / custom). prefix_vars are join-prefix vars read by the aggregate’s index lookup.

agg_func: str

None

handle_start: int

None

index: list[int]

None

prefix_vars: list[str]

‘field(…)’

rel_name: str

None

result_var: str

None

version: srdatalog.ir.hir.types.Version

None

class srdatalog.ir.mir.types.BalancedScan[source]

(balanced-scan #:group-var v #:source1 (…) #:source2 (…))

Pre-computes a work-distribution histogram for a skewed join: partition work across (source1 × source2) pairs grouped by group_var (the “balanced root”). Emitted by lowering when a rule’s plan specifies balanced_root + balanced_sources.

group_var: str

None

handle_start: int

None

source1: srdatalog.ir.mir.types.ColumnSource

None

source2: srdatalog.ir.mir.types.ColumnSource

None

vars1: list[str]

‘field(…)’

vars2: list[str]

‘field(…)’

class srdatalog.ir.mir.types.Block[source]

(block <instructions…>)

instructions: list[MirNode]

None

class srdatalog.ir.mir.types.CartesianJoin[source]

(cartesian-join #:vars (…) #:var-from-source ((…)) #:sources (…))

handle_start: int

None

sources: list[srdatalog.ir.mir.types.ColumnSource]

None

var_from_source: list[list[str]]

‘field(…)’

vars: list[str]

None

class srdatalog.ir.mir.types.CheckSize[source]

(check-size #:schema R #:ver V)

rel_name: str

None

version: srdatalog.ir.hir.types.Version

None

class srdatalog.ir.mir.types.ClearRelation[source]

(clear-relation #:schema R #:ver V)

rel_name: str

None

version: srdatalog.ir.hir.types.Version

None

class srdatalog.ir.mir.types.ColumnJoin[source]

(column-join #:var x #:sources (…))

handle_start: int

None

sources: list[srdatalog.ir.mir.types.ColumnSource]

None

var_name: str

None

class srdatalog.ir.mir.types.ColumnSource[source]

(column-source #:index (Rel cols…) #:ver V #:prefix (vars))

clause_idx: int

None

handle_start: int

None

index: list[int]

None

prefix_vars: list[str]

‘field(…)’

rel_name: str

None

version: srdatalog.ir.hir.types.Version

None

class srdatalog.ir.mir.types.ComputeDelta[source]

(compute-delta #:schema R)

index: list[int]

‘field(…)’

rel_name: str

None

class srdatalog.ir.mir.types.ComputeDeltaIndex[source]

(compute-delta-index #:schema R #:canonical-index (cols…))

canonical_index: list[int]

None

rel_name: str

None

class srdatalog.ir.mir.types.ConstantBind[source]

(constant-bind #:var v #:code “…” #:deps (…))

Generated by head-constant rewriting: a HIR LetClause lowers to this MIR node, which binds var_name to code once deps are bound.

code: str

None

deps: list[str]

None

var_name: str

None

class srdatalog.ir.mir.types.CreateFlatView[source]

(create-flat-view #:schema R #:index (cols…) #:ver V)

Emitted by split-rule lowering to expose temp-relation intern columns as an unsorted view (avoids a GPU sort between Pipeline A and B).

index: list[int]

None

rel_name: str

None

version: srdatalog.ir.hir.types.Version

None

class srdatalog.ir.mir.types.ExecutePipeline[source]

(execute-pipeline #:rule N #:sources (tuple …) #:dests (tuple …) )

block_group: bool

False

clause_order: list[int]

‘field(…)’

concurrent_write: bool

False

count: bool

False

dedup_hash: bool

False

dest_specs: list[srdatalog.ir.mir.types.InsertInto]

None

pipeline: list[MirNode]

None

rule_name: str = <Multiline-String>
source_specs: list[Union[srdatalog.ir.mir.types.ColumnSource, srdatalog.ir.mir.types.Scan, srdatalog.ir.mir.types.Negation, srdatalog.ir.mir.types.Aggregate]]

None

use_fan_out: bool

False

work_stealing: bool

False

class srdatalog.ir.mir.types.Filter[source]

(filter #:vars (…) #:code “…”)

code: str

None

vars: list[str]

None

class srdatalog.ir.mir.types.FixpointPlan[source]

(fixpoint-plan <instructions…>)

instructions: list[MirNode]

None

schema_arities: list[tuple[str, int]]

‘field(…)’

class srdatalog.ir.mir.types.GatherColumn[source]

(gather-column …) — binary-join mode node. Dereferences input_buffer of row IDs into values of column from rel_name, binding the result to output_var.

column: int

None

input_buffer: str = <Multiline-String>
output_var: str

None

rel_name: str

None

rel_version: srdatalog.ir.hir.types.Version

None

class srdatalog.ir.mir.types.InjectCppHook[source]

(inject-cpp-hook #:rule R #:code “…”) — raw C++ injection point.

The Nim emitter prints #:code “…” without the actual code body (just the ellipsis), matching debug/tooling display; real content stays in the node’s code field for codegen.

code: str

None

rule_name: str = <Multiline-String>
class srdatalog.ir.mir.types.InnerPipeline[source]

(inner-pipeline #:rule R #:bound-vars (…) #:handles (…) #:ops (…))

JIT-generated inner device function for nested joins (Level 2+). Nim emits an explicit C++ functor rather than recursive template metaprogramming.

bound_vars: list[str]

‘field(…)’

inner_ops: list[MirNode]

‘field(…)’

input_handles: list[MirNode]

‘field(…)’

rule_name: str

None

class srdatalog.ir.mir.types.InsertInto[source]

(insert-into #:schema R #:ver V #:dedup-index (cols…) #:terms (vars))

index: list[int]

None

rel_name: str

None

vars: list[str]

None

version: srdatalog.ir.hir.types.Version

None

class srdatalog.ir.mir.types.MergeIndex[source]

(merge-index #:index (R cols…))

index: list[int]

None

rel_name: str

None

class srdatalog.ir.mir.types.MergeRelation[source]

(merge-relation #:schema R)

rel_name: str

None

srdatalog.ir.mir.types.MirNode

None

class srdatalog.ir.mir.types.Negation[source]

(negation #:schema R #:ver V #:index (R cols…) #:prefix (…))

const_args: list[tuple[int, int]]

‘field(…)’

handle_start: int

None

index: list[int]

None

prefix_vars: list[str]

‘field(…)’

rel_name: str

None

version: srdatalog.ir.hir.types.Version

None

class srdatalog.ir.mir.types.ParallelGroup[source]

(parallel-group <ops…>) — independent ops that can run concurrently.

ops: list[MirNode]

None

class srdatalog.ir.mir.types.PositionedExtract[source]

(positioned-extract #:var v #:sources ((…) (…)) #:bind (…))

After a BalancedScan binds its group variable, any subsequent ColumnJoin for that variable becomes a positioned extract: point-lookup rather than iteration.

bind_vars: list[str]

‘field(…)’

sources: list[srdatalog.ir.mir.types.ColumnSource]

None

var_name: str

None

class srdatalog.ir.mir.types.PostStratumReconstructInternCols[source]

(post-stratum-reconstruct-intern-cols #:rel R #:canonical-index (cols…))

Emitted once per stratum per relation: single cleanup step that replaces a per-index RebuildIndex loop, pushing complexity into the C++ runtime.

canonical_index: list[int]

None

rel_name: str

None

class srdatalog.ir.mir.types.ProbeJoin[source]

(probe-join …) — binary-join mode node. Performs a binary-search probe of probe_rel keyed on join_key, writing row-id pairs into output_buffer. Uses merge-path balancing for unbalanced output.

input_buffer: str = <Multiline-String>
join_key: str

None

output_buffer: str = <Multiline-String>
probe_index: list[int]

None

probe_rel: str

None

probe_version: srdatalog.ir.hir.types.Version

None

class srdatalog.ir.mir.types.Program[source]

(program (step #:recursive b ) …)

steps: list[tuple[MirNode, bool]]

None

class srdatalog.ir.mir.types.RebuildIndex[source]

(rebuild-index #:index (R cols…) #:ver V)

index: list[int]

None

rel_name: str

None

version: srdatalog.ir.hir.types.Version

None

class srdatalog.ir.mir.types.RebuildIndexFromIndex[source]

(rebuild-index-from-index #:source (R cols…) #:target (R cols…) #:ver V)

rel_name: str

None

source_index: list[int]

None

target_index: list[int]

None

version: srdatalog.ir.hir.types.Version

None

class srdatalog.ir.mir.types.Scan[source]

(scan #:vars (…) #:index (Rel cols…) #:ver V #:prefix (…))

handle_start: int

None

index: list[int]

None

prefix_vars: list[str]

‘field(…)’

rel_name: str

None

vars: list[str]

None

version: srdatalog.ir.hir.types.Version

None