gccrs: backend: Add DST ADT support
gccrs backend now supports Dynamically Sized Types (DSTs) in Algebraic Data Types (ADTs).
The gccrs compiler’s backend has gained support for Dynamically Sized Types (DSTs) within Algebraic Data Types (ADTs). Previously, DST fields were embedded directly, but now the compiler correctly identifies unsized ADTs, preserves their layout, and generates fat pointers for references. This enables correct handling of unsized ADTs that follow unsize coercion rules.
In Details
gccrs' backend now correctly handles DSTs within ADTs. Instead of embedding DST fields directly, it identifies unsized ADTs, maintains their static layout, and generates fat pointers for references. This involves changes in CompileExpr::visit for indirect field access and borrow handling, TyTyResolveCompile::visit for DST ADT creation, and intrinsic handlers for size_of_val and min_align_of_val. The type system (rust-tyty.cc) has also been updated with new functions like is_unsized and is_dyn_adt_type.
- DST
- Dynamically Sized Type. A type whose size is not known at compile time, such as a slice
[T]or a trait objectdyn Trait. DSTs can only be used behind pointers like&orBox. - ADT
- Algebraic Data Type. A composite type formed by combining other types. In Rust, this typically refers to structs and enums.
- fat pointer
- A pointer that contains not only the memory address of the data but also additional metadata. For slices, this is the length; for trait objects, this is a vtable pointer.
- unsize coercion
- A conversion in Rust that allows a sized type to be coerced into a DST behind a pointer. For example,
&[T; N]can be coerced into&[T].