gccrs: lang: Add DST support to Box and improve Box dispatch
gccrs now supports DSTs in Box and improves auto-dereferencing for Box.
This patch enhances gccrs’ support for Rust’s Box type by enabling it to handle Dynamically Sized Types (DSTs). It also refines the auto-deref mechanism for Box, ensuring method dispatch, indexing, and tuple field access function correctly. Changes include modifications to how DST guards are handled, fat pointer creation, and expression type checking.
In Details
gccrs now better handles Dynamically Sized Types (DSTs) within Box. This commit removes a DST guard in compile_box, introduces fat pointer control in build_box_inner_ptr, and enhances CompileExpr::visit with auto-dereferencing for Box. This facilitates correct method dispatch, indexing, and field access for boxed DSTs by correctly resolving dereference adjustments to fat pointers. The ADTType now includes an is_box method.
- 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. - Box
- A smart pointer in Rust that owns data on the heap. It's analogous to a unique pointer in C++.
- auto-deref
- An automatic dereferencing mechanism in Rust that allows method calls and field access on a smart pointer (like
Boxor&) to automatically follow the pointer to the underlying data. - 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.