Skip to main content

lower_range

Function lower_range 

Source
pub fn lower_range(
    elem_ty: &ResolvedType,
    left: &IrExpr,
    right: &IrExpr,
    sink: &mut InstructionSink<'_>,
    ctx: &LowerContext<'_>,
) -> Result<(), LowerError>
Expand description

Lower a BinaryOp { op: Range, left, right } expression.

Allocates a Range<T> value as a two-field aggregate { start: T, end: T } in linear memory:

  1. Plan the range layout via plan_range from the expression’s declared element type.
  2. Allocate layout.size bytes through the bump allocator and park the base pointer in a fresh scratch local.
  3. Lower left, store at start_offset = 0. Lower right, store at layout.end_offset. Both stores use the primitive width appropriate to the bound type.
  4. Leave the base pointer on the stack as the range value.

The element type must be a primitive (validated upstream by plan_range); aggregate-bound ranges surface as LayoutError::NotYetSupported.