Module array

Module array 

Source
Expand description

Codegen for prelude array operations.

An array<n, T> is now lowered to a fat pointer {ptr, usize} that is allocated to at least n * sizeof(T) bytes. The extra usize is an offset pointing to the first element, i.e. the first element is at address ptr + offset * sizeof(T).

The rational behind the additional offset is the pop_left operation which bumps the offset instead of mutating the pointer. This way, we can still free the original pointer when the array is discarded after a pop.

We provide utility functions array_fat_pointer_ty, build_array_fat_pointer, and decompose_array_fat_pointer to work with array fat pointers.

The DefaultArrayCodegen extension allocates all arrays on the heap using the standard libc malloc and free functions. This behaviour can be customised by providing a different implementation for ArrayCodegen::emit_allocate_array and ArrayCodegen::emit_free_array.

Structs§

ArrayCodegenExtension
DefaultArrayCodegen
A trivial implementation of ArrayCodegen which passes all methods through to their default implementations.

Traits§

ArrayCodegen
A helper trait for customising the lowering of hugr_core::std_extensions::collections::array types, hugr_core::ops::constant::CustomConsts, and ops.

Functions§

array_fat_pointer_ty
Returns the LLVM representation of an array value as a fat pointer.
build_array_alloc
Helper function to allocate a fat array pointer.
build_array_fat_pointer
Constructs an array fat pointer value.
decompose_array_fat_pointer
Returns the underlying pointer and offset stored in a fat array pointer.
emit_array_discard
Emits an ArrayDiscard op.
emit_array_op
Emits an ArrayOp.
emit_array_value
Emits an array::ArrayValue.
emit_clone_op
Emits an ArrayClone op.
emit_repeat_op
Emits an ArrayRepeat op.
emit_scan_op
Emits an ArrayScan op.