Trait StaticArrayCodegen

Source
pub trait StaticArrayCodegen: Clone {
    // Provided methods
    fn static_array_type<'c>(
        &self,
        session: TypingSession<'c, '_>,
        element_type: &HugrType,
    ) -> Result<BasicTypeEnum<'c>> { ... }
    fn static_array_value<'c, H: HugrView<Node = Node>>(
        &self,
        context: &mut EmitFuncContext<'c, '_, H>,
        value: &StaticArrayValue,
    ) -> Result<BasicValueEnum<'c>> { ... }
    fn static_array_op<'c, H: HugrView<Node = Node>>(
        &self,
        context: &mut EmitFuncContext<'c, '_, H>,
        args: EmitOpArgs<'c, '_, ExtensionOp, H>,
        op: StaticArrayOp,
    ) -> Result<()> { ... }
}
Expand description

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

Provided Methods§

Source

fn static_array_type<'c>( &self, session: TypingSession<'c, '_>, element_type: &HugrType, ) -> Result<BasicTypeEnum<'c>>

Return the llvm type of hugr_core::std_extensions::collections::static_array::STATIC_ARRAY_TYPENAME.

By default a static array of llvm type t and length l is stored in a global of type `struct { i64, [t * l] }``

The i64 stores the length of the array.

However a static_array HugrType is represented by an llvm pointer type struct {i64, [t * 0]}; i.e. the array is zero length. This gives all static arrays of the same element type a uniform llvm type.

It is legal to index past the end of an array (it is only undefined behaviour to index past the allocation).

Source

fn static_array_value<'c, H: HugrView<Node = Node>>( &self, context: &mut EmitFuncContext<'c, '_, H>, value: &StaticArrayValue, ) -> Result<BasicValueEnum<'c>>

Emit a hugr_core::std_extensions::collections::static_array::StaticArrayValue.

Note that the type of the return value must match the type returned by Self::static_array_type.

By default a global is created and we return a pointer to it.

Source

fn static_array_op<'c, H: HugrView<Node = Node>>( &self, context: &mut EmitFuncContext<'c, '_, H>, args: EmitOpArgs<'c, '_, ExtensionOp, H>, op: StaticArrayOp, ) -> Result<()>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§