srdatalog.ir.hir.pass_

HIR pass infrastructure: minimal Python port of src/srdatalog/hir/pass_infrastructure.nim + pass_manager.nim.

Ports the parts that are actually load-bearing today:

  • PassLevel enum (stage-in-pipeline classification)

  • Dialect enum (IR abstraction level, for metadata)

  • PassInfo dataclass (name/level/order/source-target dialect)

  • RuleRewritePass and HirTransformPass protocols

  • Pipeline class that runs registered passes in order

Deliberately DOES NOT port yet:

  • ConversionTarget / RewritePattern / PatternSet (MIR-level rewrites; Nim’s verifyLegality is itself a stub)

  • Compile-time macro registry (Python has no macros; runtime registration on a Pipeline instance is simpler and achieves the same goal)

When a new pass is ported, give it a PassInfo and register it via Pipeline.add_rule_rewrite or Pipeline.add_hir_transform.

Module Contents

Classes

HirTransformPass

HIR-level transform that runs AFTER stratification. Typically mutates the HirProgram in place but must return it for uniformity.

IRLevel

IR abstraction level (HIR / MIR variants).

PassInfo

Metadata for a registered pass.

PassLevel

Stage in the compilation pipeline. Mirrors Nim pass_manager.PassLevel.

Pipeline

HIR pipeline orchestrator. Mirrors the role of compileToHir in hir.nim.

RuleRewritePass

Rule-level transform that runs BEFORE stratification.

Functions

program_to_decls

Extract RelationDecls from a user-facing Program. Pipeline entry helper.

API

class srdatalog.ir.hir.pass_.HirTransformPass[source]

Bases: typing.Protocol

HIR-level transform that runs AFTER stratification. Typically mutates the HirProgram in place but must return it for uniformity.

info: srdatalog.ir.hir.pass_.PassInfo

None

run(hir: srdatalog.ir.hir.types.HirProgram) srdatalog.ir.hir.types.HirProgram[source]
class srdatalog.ir.hir.pass_.IRLevel(*args, **kwds)[source]

Bases: enum.Enum

IR abstraction level (HIR / MIR variants).

Renamed from Dialect to disambiguate from srdatalog.ir.core.dialect.Dialect, the framework registry record that catalogs ops/types per dialect (relation.sorted_array, iir.cf, etc.). This is purely an abstraction-level label used by PassInfo.source_dialect / target_dialect.

Mirrors Nim pass_infrastructure.Dialect.

Initialization

HIR

‘HIR’

MIR_BINARY

‘MIR_Binary’

MIR_MATERIALIZED

‘MIR_Materialized’

MIR_UNIFIED

‘MIR_Unified’

MIR_WCOJ

‘MIR_WCOJ’

class srdatalog.ir.hir.pass_.PassInfo[source]

Metadata for a registered pass.

level: srdatalog.ir.hir.pass_.PassLevel

None

name: str

None

order: int

None

source_dialect: srdatalog.ir.hir.pass_.IRLevel

None

target_dialect: srdatalog.ir.hir.pass_.IRLevel

None

class srdatalog.ir.hir.pass_.PassLevel(*args, **kwds)[source]

Bases: enum.Enum

Stage in the compilation pipeline. Mirrors Nim pass_manager.PassLevel.

Initialization

DIALECT_UNIFY

‘plDialectUnify’

HIR_TRANSFORM

‘plHirTransform’

LOWERING

‘plLowering’

MIR_OPTIMIZE

‘plMirOptimize’

RULE_REWRITE

‘plRuleRewrite’

class srdatalog.ir.hir.pass_.Pipeline(verbose: bool = False)[source]

HIR pipeline orchestrator. Mirrors the role of compileToHir in hir.nim.

Stratification is a fixed entry step (not registered) because it’s the point where (rules, decls) becomes HirProgram; every HIR pipeline needs it exactly once. Rule-rewrite passes run before it; HIR transform passes run after. Within each category, passes run in order-ascending order.

Initialization

add_hir_transform(p: srdatalog.ir.hir.pass_.HirTransformPass) srdatalog.ir.hir.pass_.Pipeline[source]
add_rule_rewrite(p: srdatalog.ir.hir.pass_.RuleRewritePass) srdatalog.ir.hir.pass_.Pipeline[source]
compile_to_hir(program: srdatalog.dsl.Program) srdatalog.ir.hir.types.HirProgram[source]

Run the full HIR pipeline on a Program. Returns the resulting HirProgram.

class srdatalog.ir.hir.pass_.RuleRewritePass[source]

Bases: typing.Protocol

Rule-level transform that runs BEFORE stratification.

Implementations must expose an info: PassInfo attribute and a run method. Use Protocol not ABC so existing bare functions can be adapted with a thin wrapper class.

info: srdatalog.ir.hir.pass_.PassInfo

None

run(rules: list[srdatalog.dsl.Rule], decls: list[srdatalog.ir.hir.types.RelationDecl]) tuple[list[srdatalog.dsl.Rule], list[srdatalog.ir.hir.types.RelationDecl]][source]
srdatalog.ir.hir.pass_.program_to_decls(program: srdatalog.dsl.Program) list[srdatalog.ir.hir.types.RelationDecl][source]

Extract RelationDecls from a user-facing Program. Pipeline entry helper.