Skip to main content

alloc_size

Function alloc_size 

Source
pub fn alloc_size(
    ty: &AirType,
    types: &BTreeMap<TypeId, AirType>,
) -> Option<u64>
Expand description

Returns the allocation size in bytes for a type.

Uses a default pointer width of 8 bytes (64-bit). For target-aware layout, use alloc_size_with_ptr.

Returns None for Opaque types, variable-length arrays, or types that reference unknown TypeIds.

ยงSize rules

  • Pointer / Reference -> 8
  • Integer { bits } -> ceil(bits / 8)
  • Float { bits } -> bits / 8 (minimum 4)
  • Vector { element, lanes } -> alloc_size(element) * lanes
  • Array { element, count: Some(n) } -> n * alloc_size(element)
  • Array { element, count: None } -> None (VLA)
  • Struct { total_size, .. } -> total_size
  • Void -> 0
  • Function { .. } -> 0 (function types have no allocation size)
  • Opaque -> None