srdatalog.ir.hir.stratify

HIR Pass 1: Stratification.

Input: Program (DSL-level: relations + rules) Output: HirProgram with strata populated (scc_members, is_recursive, stratum_rules)

Mirrors src/srdatalog/hir/stratification.nim. Key behavior: for a recursive SCC that has some rules with no SCC dependency in their body (true base case) and some with SCC dependency (recursive step), we emit TWO separate strata – base first, then recursive – so the base runs once before the fixpoint loop.

The subsequent fusion pass merges consecutive non-recursive strata that have no inter-dependency, enabling parallel execution at the MIR/codegen level.

NOTE: Python’s set iteration order depends on the hash-random seed across runs. To keep SCC ordering reproducible, we sort every set iteration that feeds into downstream ordering (dependency edges, SCC membership iteration).

Module Contents

Classes

Functions

stratify

HIR Pass 1 entry point. Takes (rules, decls) after any rule-rewrite passes; produces a HirProgram with strata populated. Mirrors stratify() in src/srdatalog/hir/stratification.nim.

API

class srdatalog.ir.hir.stratify.StratificationPass[source]
info

‘PassInfo(…)’

run(rules: list[srdatalog.dsl.Rule], decls: list[srdatalog.ir.hir.types.RelationDecl]) srdatalog.ir.hir.types.HirProgram[source]
srdatalog.ir.hir.stratify.stratify(rules: list[srdatalog.dsl.Rule], decls: list[srdatalog.ir.hir.types.RelationDecl]) srdatalog.ir.hir.types.HirProgram[source]

HIR Pass 1 entry point. Takes (rules, decls) after any rule-rewrite passes; produces a HirProgram with strata populated. Mirrors stratify() in src/srdatalog/hir/stratification.nim.

This is the fixed entry of the HIR pipeline — it’s the point where (rules, decls) becomes HirProgram. See hir_pass.Pipeline.compile_to_hir.