About the ‘alloc’ Crate
The alloc crate introduces dynamic memory (heap) allocation capabilities to the Rust language. While the core crate is strictly limited to stack-based and statically sized operations, alloc provides the foundational primitives for heap management, such as the Box<T>, Vec<T>, and Reference Counted pointers (Rc<T>, Arc<T>).
However, enabling these capabilities comes with a high cost for the compiler.
To successfully compile alloc, the compiler must flawlessly support several advanced language features:
- Dynamic Sized Types (DSTs): Handling types whose size is unknown at compile time (like
[T]andstr). - Fat Pointers & Vtables: Generating and managing the memory layout for trait objects (dyn Trait).
- Unsized Coercions & Auto-Deref: Automatically converting thin pointers to fat pointers and resolving method calls on heap-allocated structs (like
Box).
The “Mock Core” Strategy
Architecturally, alloc sits directly on top of core and strictly demands full core support to function. Currently, gccrs is not yet able to compile the entire standard core crate end-to-end.
To bypass this blocker and make independent progress, we employ a “mock core” strategy in our test suite. By injecting a stripped-down, primitive core implementation as a submodule, we can isolate and test the new compiler features we built for alloc.