Module spacetimedb_table::row_type_visitor

source ·
Expand description

A VarLenMembers visitor for [AlgebraicType], supporting any non-recursive AlgebraicType, including sums and products.

The general architecture is: first, we walk the AlgebraicType to construct a [VarLenRoseTree], a Rose Tree with a structure that matches the original AlgebraicType, but with non-var-len members stripped out and var-len members resolved to their offsets within a row.

We then flatten the VarLenRoseTree into a VarLenVisitorProgram, a simple bytecode language which can be interpreted relatively efficiently to visit the var-len members in a row.

A VarLenVisitorProgram for a fixed-length-only row will be empty.

A VarLenVisitorProgram for a (potentially nested) product type will be a sequence of VisitOffset instructions, with no control flow.

SumTypes which contain var-len refs will introduce control-flow to the VarLenVisitorProgram using SwitchOnTag to visit the appropriate variant, and Goto to return to the part of the var-len object after the sum.

The VarLenMembers impl for VarLenVisitorProgram implements a simple interpreter loop for the var-len visitor bytecode.

Structs§

Functions§