Rust: Compiling the alloc crate - Status Report 3
Progress report on compiling Rust's 'alloc' crate with GCCRS, detailing refactoring, intrinsic implementation, and unblocking issues.
Enes Cevik’s third status report on compiling Rust’s ‘alloc’ crate with GCCRS outlines progress and current challenges. Key achievements include refactoring the fat pointer structure to use a static struct for vtables, ensuring a consistent two-word size for fat pointers. This enabled the implementation of ‘size_of_val’ and ‘min_align_of_val’ intrinsics. A bug in trait method dispatch was fixed. However, progress on ‘coerce_unsized’ is blocked by an issue with the compiler ignoring where clauses in impl blocks, which is currently under investigation. As a workaround, ‘write_bytes’ and ‘arith_offset’ intrinsics have been implemented.
- proposer
Reports on progress in compiling Rust's 'alloc' crate with GCCRS, including refactoring, implementing intrinsics, fixing a bug, and investigating an issue blocking 'coerce_unsized'.
In Details
This report is about ongoing work within the GCC Rust front-end (GCCRS) to compile Rust's standard library alloc crate. The focus is on implementing several core Rust language features and intrinsics required for alloc. This includes structural changes to fat pointers to ensure a stable memory layout, implementing necessary runtime functions (intrinsics like size_of_val), and fixing bugs related to trait dispatch. A current blocker is the compiler's improper handling of where clauses in impl blocks, which prevents the implementation of coerce_unsized.
- GCCRS
- GCC Rust, the Rust front-end for the GNU Compiler Collection.
- alloc crate
- A core Rust crate that provides fundamental memory allocation and collection types, such as
VecandBox. - Fat pointer
- A pointer in Rust that contains not only a memory address but also additional information, such as a table of function pointers (vtable) for trait objects or a length for dynamically sized types (DSTs).
- Vtable
- Virtual Method Table, a data structure used in some object-oriented systems to support dynamic dispatch, mapping method names to their actual addresses.
- Intrinsic
- A function or operation that is recognized and optimized by the compiler, often mapping to a specific machine instruction.
- Coerce_unsized
- A Rust language feature that allows a pointer to a sized type to be converted into a pointer to an unsized type (e.g., coercing
&Tto&[T]or&dyn Trait). - Where clauses
- In Rust,
whereclauses are used in generic function or type signatures to specify constraints on type parameters. For example,T: Displaymeans type T must implement theDisplaytrait.