srdatalog.ir.hir.types

Python mirror of src/srdatalog/hir/hir_types.nim.

These are the high-level IR types that HIR passes (stratification, planning, index selection, lowering) read and write. The Python pipeline must produce HIR that serializes byte-identically to the Nim golden for differential testing.

Keep field names in sync with the Nim side; the canonical emitter (hir_emit.py, TBD) will translate between snake_case Python and the camelCase keys used in json_printer.nim’s output.

Module Contents

Classes

AccessPattern

Access pattern for a single body clause.

HirProgram

The complete HIR program. Mirrors HirProgram.

HirRuleVariant

One delta variant of a rule (mirrors HirRuleVariant).

HirStratum

An SCC + its rule variants. Mirrors HirStratum.

RelationDecl

Relation declaration; subset of syntax.nim RelationDecl.

Version

Mirrors Nim hir_types.Version.

API

class srdatalog.ir.hir.types.AccessPattern[source]

Access pattern for a single body clause.

Mirrors hir_types.nim AccessPattern. All fields default-initialized for ease of construction inside passes; the planner fills them in.

access_order: list[str]

‘field(…)’

clause_idx: int

None

const_args: list[tuple[int, int]]

‘field(…)’

index_cols: list[int]

‘field(…)’

prefix_len: int

0

rel_name: str = <Multiline-String>
version: srdatalog.ir.hir.types.Version

None

class srdatalog.ir.hir.types.HirProgram[source]

The complete HIR program. Mirrors HirProgram.

global_index_map: dict[str, list[list[int]]]

‘field(…)’

relation_decls: list[srdatalog.ir.hir.types.RelationDecl]

‘field(…)’

strata: list[srdatalog.ir.hir.types.HirStratum]

‘field(…)’

class srdatalog.ir.hir.types.HirRuleVariant[source]

One delta variant of a rule (mirrors HirRuleVariant).

Non-recursive rules have delta_idx == -1 and a single base variant. Recursive rules fan out into N variants (one delta per recursive body clause).

access_patterns: list[srdatalog.ir.hir.types.AccessPattern]

‘field(…)’

balanced_root: list[str]

‘field(…)’

balanced_sources: list[str]

‘field(…)’

block_group: bool

False

clause_order: list[int]

‘field(…)’

clause_versions: list[srdatalog.ir.hir.types.Version]

‘field(…)’

count: bool

False

dedup_hash: bool

False

delta_idx: int

None

fanout: bool

False

join_vars: set[str]

‘field(…)’

negation_patterns: list[srdatalog.ir.hir.types.AccessPattern]

‘field(…)’

original_rule: srdatalog.dsl.Rule

None

split_at: int

None

temp_rel_name: str = <Multiline-String>
temp_vars: list[str]

‘field(…)’

var_order: list[str]

‘field(…)’

work_stealing: bool

False

class srdatalog.ir.hir.types.HirStratum[source]

An SCC + its rule variants. Mirrors HirStratum.

after_hook: str = <Multiline-String>
base_variants: list[srdatalog.ir.hir.types.HirRuleVariant]

‘field(…)’

before_hook: str = <Multiline-String>
canonical_index: dict[str, list[int]]

‘field(…)’

is_generated: bool

False

is_recursive: bool

False

recursive_variants: list[srdatalog.ir.hir.types.HirRuleVariant]

‘field(…)’

required_indices: dict[str, list[list[int]]]

‘field(…)’

scc_members: set[str]

‘field(…)’

stratum_rules: list[srdatalog.dsl.Rule]

‘field(…)’

class srdatalog.ir.hir.types.RelationDecl[source]

Relation declaration; subset of syntax.nim RelationDecl.

NimNode-typed fields in Nim (relname, types, semiring) are reduced to strings here. Python emitter must reproduce the same repr() the Nim emitter writes.

count_only: bool

False

index_type: str = <Multiline-String>
input_file: str = <Multiline-String>
is_generated: bool

False

is_temp: bool

False

output_file: str = <Multiline-String>
print_size: bool

False

rel_name: str

None

semiring: str

‘BooleanSR’

types: list[str]

None

class srdatalog.ir.hir.types.Version(*args, **kwds)[source]

Bases: enum.Enum

Mirrors Nim hir_types.Version.

.value stays the plain string ("FULL", "DELTA", "NEW") so the MIR S-expr emitter’s byte-match against Nim continues to work. For C++ codegen the extra properties below surface the forms the backend needs:

  • .method — method-suffix used in C++ helpers (full, delta, newt)

  • .number — numeric index Nim’s template backend uses ("0", "1", "2")

  • .code*_VER macro the non-template codegen emits into types

Initialization

DELTA

‘DELTA’

FULL

‘FULL’

NEW

‘NEW’

property code: str
property method: str
property number: str