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§
- Array
Codegen Extension - Default
Array Codegen - A trivial implementation of
ArrayCodegenwhich passes all methods through to their default implementations.
Traits§
- Array
Codegen - A helper trait for customising the lowering of
hugr_core::std_extensions::collections::arraytypes,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
ArrayDiscardop. - emit_
array_ op - Emits an
ArrayOp. - emit_
array_ value - Emits an
array::ArrayValue. - emit_
clone_ op - Emits an
ArrayCloneop. - emit_
repeat_ op - Emits an
ArrayRepeatop. - emit_
scan_ op - Emits an
ArrayScanop.