Skip to content

Stack move

stack_move dialect — 1:1 SSA image of the bytecode.

AwaitMeasure

Bases: Statement


              flowchart TD
              bloqade.lanes.dialects.stack_move.AwaitMeasure[AwaitMeasure]

              

              click bloqade.lanes.dialects.stack_move.AwaitMeasure href "" "bloqade.lanes.dialects.stack_move.AwaitMeasure"
            

Synchronisation — consumes a measurement future (linear) and produces a 1-D array of measurement results.

Matches the bytecode's await_measure: pops a measure future, pushes an array ref containing the measurement results.

Result type is ArrayType[MeasurementResultType, Any, Literal(0)], a 1-D array in the bytecode convention (dim1 == 0). Element ordering is defined by the ArchSpec: for each zone covered by the originating measurement (in order), the results appear in the order produced by arch_spec.yield_zone_locations(zone).

Dup

Bases: Statement


              flowchart TD
              bloqade.lanes.dialects.stack_move.Dup[Dup]

              

              click bloqade.lanes.dialects.stack_move.Dup href "" "bloqade.lanes.dialects.stack_move.Dup"
            

Duplicate the top of the virtual stack. Semantically result ≡ value; preserved as an explicit op to give downstream passes a hook for non-cloning invariants.

GetItem

Bases: Statement


              flowchart TD
              bloqade.lanes.dialects.stack_move.GetItem[GetItem]

              

              click bloqade.lanes.dialects.stack_move.GetItem href "" "bloqade.lanes.dialects.stack_move.GetItem"
            

Index into an array — pops len(indices) indices and the array, pushes the element of type ElemType.

Arrays are bounded at 2-D by the bytecode's new_array construction (only dim0 and dim1 fields), so len(indices) ∈ {1, 2} for well-formed programs — one index for a 1-D array (dim1 == 0), two indices for a 2-D array (dim1 > 0). This invariant is implicit rather than encoded in the dialect type: splitting into GetItem1D / GetItem2D would break the 1:1 bytecode-to-statement mapping the dialect commits to. A type-inference pass can enforce the invariant later, the same way the Rust validator defers to type simulation.

HasArity dataclass

HasArity(n_fixed: int = 0)

Bases: StmtTrait


              flowchart TD
              bloqade.lanes.dialects.stack_move.HasArity[HasArity]

              

              click bloqade.lanes.dialects.stack_move.HasArity href "" "bloqade.lanes.dialects.stack_move.HasArity"
            

Marks a statement whose bytecode opcode takes a variable-length arity argument.

arity(stmt) returns len(stmt.args) - n_fixed, where n_fixed is the number of leading scalar (non-variadic) SSA arguments — e.g. 2 for LocalR (axis_angle + rotation_angle), 1 for LocalRz/GetItem, 0 for statements whose only args are the variadic group.

Measure

Measure(zones: Sequence[SSAValue])

Bases: Statement


              flowchart TD
              bloqade.lanes.dialects.stack_move.Measure[Measure]

              

              click bloqade.lanes.dialects.stack_move.Measure href "" "bloqade.lanes.dialects.stack_move.Measure"
            

Matches bytecode measure(arity): pops arity zone values and pushes arity measure futures. Zone grouping (dedup of distinct zones when lowering to move.Measure) happens in stack_move2move.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/dialects/stack_move.py
220
221
222
223
224
225
226
def __init__(self, zones: typing.Sequence[ir.SSAValue]) -> None:
    arity = len(zones)
    super().__init__(
        args=tuple(zones),
        args_slice={"zones": slice(0, arity)},
        result_types=(MeasurementFutureType,) * arity,
    )

NewArray

NewArray(
    values: Sequence[SSAValue],
    type_tag: int,
    dim0: int,
    dim1: int,
)

Bases: Statement


              flowchart TD
              bloqade.lanes.dialects.stack_move.NewArray[NewArray]

              

              click bloqade.lanes.dialects.stack_move.NewArray href "" "bloqade.lanes.dialects.stack_move.NewArray"
            

Create an array.

Bytecode stack effect: doesn't pop (empty-array placeholder). Python construction accepts values=() in that case or a non-empty tuple when authoring stack_move IR directly from Python.

The result type is a fully-parameterised ArrayType[ElemType, Literal[dim0], Literal[dim1]] derived from the type_tag byte (via TYPE_TAG) and the two dimension attributes.

Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/dialects/stack_move.py
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
def __init__(
    self,
    values: typing.Sequence[ir.SSAValue],
    type_tag: int,
    dim0: int,
    dim1: int,
) -> None:
    elem_type = TYPE_TAG.get(type_tag)
    if elem_type is None:
        supported = ", ".join(str(tag) for tag in sorted(TYPE_TAG))
        raise ValueError(
            f"Unsupported NewArray type_tag {type_tag!r}; "
            f"supported tags are: {supported}"
        )
    result_type = ArrayType[
        elem_type,
        types.Literal(dim0),
        types.Literal(dim1),
    ]
    super().__init__(
        args=tuple(values),
        args_slice={"values": slice(0, len(values))},
        result_types=(result_type,),
        attributes={
            "type_tag": ir.PyAttr(type_tag),
            "dim0": ir.PyAttr(dim0),
            "dim1": ir.PyAttr(dim1),
        },
    )

Pop

Bases: Statement


              flowchart TD
              bloqade.lanes.dialects.stack_move.Pop[Pop]

              

              click bloqade.lanes.dialects.stack_move.Pop href "" "bloqade.lanes.dialects.stack_move.Pop"
            

Pop and discard the top of the virtual stack.

SetDetector

Bases: Statement


              flowchart TD
              bloqade.lanes.dialects.stack_move.SetDetector[SetDetector]

              

              click bloqade.lanes.dialects.stack_move.SetDetector href "" "bloqade.lanes.dialects.stack_move.SetDetector"
            

Build a detector record from a 1-D array of measurement results. Matches annotate.SetDetector's signature — produces a Detector.

The array type is tightened to require MeasurementResult elements (the output of AwaitMeasure) and a 1-D shape (dim1=0 per the bytecode convention). Validation of this constraint is the job of type-inference passes, not the decoder.

SetObservable

Bases: Statement


              flowchart TD
              bloqade.lanes.dialects.stack_move.SetObservable[SetObservable]

              

              click bloqade.lanes.dialects.stack_move.SetObservable href "" "bloqade.lanes.dialects.stack_move.SetObservable"
            

Build an observable record from a 1-D array of measurement results. Matches annotate.SetObservable's signature — produces an Observable.

The array type is tightened to require MeasurementResult elements and a 1-D shape (dim1=0 per the bytecode convention). Validation of this constraint is the job of type-inference passes, not the decoder.

Swap

Bases: Statement


              flowchart TD
              bloqade.lanes.dialects.stack_move.Swap[Swap]

              

              click bloqade.lanes.dialects.stack_move.Swap href "" "bloqade.lanes.dialects.stack_move.Swap"
            

Swap the top two virtual-stack values. out_top ≡ in_bot; out_bot ≡ in_top.