srdatalog.ir.dialects.relation.sorted_array.lowerings

MIR -> IIR lowering for the sorted_array dialect.

Each milestone extends lower_scan_pipeline to handle more MIR op kinds. The supported predicate _supported_pipeline documents which shapes the dialect can faithfully reproduce against the legacy emitter.

M1: [Scan, InsertInto] M2: [Scan, (Filter | ConstantBind), InsertInto] M3: [CJ_multi (Filter | ConstantBind | CJ_multi), InsertInto]

Counter management mirrors the legacy pipeline.py save/restore pattern: the body of a root op is lowered with a fresh counter trajectory, then the root op’s own scaffold takes the counter from the same starting point. The numeric suffixes baked into IIR names match what gen_unique_name would have produced in legacy.

Module Contents

Classes

LoweringCtx

Mutable state during MIR -> IIR walk.

NegPreNarrowInfo

Pre-narrowed handle info for a Negation that follows a Cartesian.

Functions

lower_scan_pipeline

Lower a supported pipeline shape to IIR.

API

class srdatalog.ir.dialects.relation.sorted_array.lowerings.LoweringCtx[source]

Mutable state during MIR -> IIR walk.

Mirrors the legacy CodeGenContext for the fields that matter to the dialect’s emission decisions today. Other legacy fields (tiled_cartesian state, ws state, etc.) aren’t needed yet — milestones add them as they cover those paths.

bg_enabled: bool

False

bound_vars: list[str]

‘field(…)’

cartesian_bound_vars: list[str]

‘field(…)’

debug: bool

True

dedup_hash: bool

False

fresh(prefix: str) str[source]
handle_vars: dict[str, str]

‘field(…)’

inside_cartesian: bool

False

is_counting: bool

False

name_counter: int

0

neg_pre_narrow: dict[int, srdatalog.ir.dialects.relation.sorted_array.lowerings.NegPreNarrowInfo]

‘field(…)’

output_var: str

‘output’

output_var_overrides: dict[str, str]

‘field(…)’

rel_index_types: dict[str, str]

‘field(…)’

tile_var: str

‘tile’

tiled_cartesian: bool

False

tiled_cartesian_valid_var: str = <Multiline-String>
view_slot_bases: dict[str, int]

‘field(…)’

view_var_names: dict[str, str]

‘field(…)’

ws_cartesian_valid_var: str = <Multiline-String>
ws_enabled: bool

False

class srdatalog.ir.dialects.relation.sorted_array.lowerings.NegPreNarrowInfo[source]

Pre-narrowed handle info for a Negation that follows a Cartesian.

When a Negation’s prefix vars are all (or partly) bound before the Cartesian, those vars don’t change inside the Cartesian loop — so we can apply them once cooperatively before the loop, then cheaply check valid() per iteration. The remaining (in-Cartesian) vars are applied per-thread inside the loop via prefix_seq.

Mirrors the legacy NegPreNarrowInfo in ir/dialects/target/cuda/context.py.

in_cartesian_vars: list[str]

None

pre_consts: list[tuple[int, int]]

None

pre_vars: list[str]

None

rel_name: str

None

var_name: str

None

view_var: str

None

srdatalog.ir.dialects.relation.sorted_array.lowerings.lower_scan_pipeline(ops: list[srdatalog.ir.mir.types.MirNode], ctx: srdatalog.ir.dialects.relation.sorted_array.lowerings.LoweringCtx) srdatalog.ir.core.Op[source]

Lower a supported pipeline shape to IIR.

The function name is historical (M1 only handled Scan-rooted pipelines); it now dispatches on the head op. Raises ValueError if the shape isn’t supported.