gccrs: intrinsic: Add size_of_val
gccrs now supports the `size_of_val` intrinsic for runtime size evaluation, including Dynamically Sized Types.
The gccrs compiler has incorporated the size_of_val intrinsic, enabling the evaluation of a value’s size at runtime. This feature extends to Dynamically Sized Types (DSTs), providing developers with a way to query memory usage dynamically. The implementation includes new handler functions and type-checking rules.
In Details
The size_of_val_handler has been implemented in rust-intrinsic-handlers.cc/.h and registered in generic_intrinsics within rust-compile-intrinsic.cc. Type checking for this intrinsic, including DSTs, is now managed by IntrinsicChecker::intrinsic_rules in rust-hir-type-check-intrinsic.cc. The SIZE_OF_VAL constexpr value is also added to rust-intrinsic-values.h. This intrinsic provides runtime evaluation of size, useful for memory management and introspection.
- gccrs
- The Rust front-end for GCC, enabling GCC to compile Rust code.
- intrinsic
- A function or operation that is directly supported by the compiler and often maps to a specific machine instruction or a highly optimized sequence of instructions. Intrinsics provide low-level access or specialized functionality.
- size_of_val
- A Rust intrinsic that returns the size in bytes of a given value at runtime. This is useful for memory management, serialization, and understanding data layout.
- Dynamically Sized Types (DSTs)
- In Rust, types whose size is not known at compile time, such as slices (
[T]) and trait objects (dyn Trait). Their size and alignment are determined at runtime. - runtime
- The period during which a program is executing. Runtime operations are performed while the program is running, as opposed to compile time.