gccrs: Implement support for recursive types
gccrs now supports recursive algebraic data types (ADTs), enabling compilation of Rust code with self-referential structures.
GCC’s Rust frontend (gccrs) now supports recursive algebraic data types (ADTs). This complex feature involves registering ADT types with placeholder variants during initial type checking, allowing fields to resolve back to the root ADT. Recursion guards and a new ‘ActiveADT’ tracking mechanism are employed to manage this during type unification and code generation, fixing multiple reported issues.
In Details
Implementing recursive ADTs in gccrs required significant changes to the type checking and codegen infrastructure. During type checking, ADTs are provisionally registered with empty variant sets. Subsequent processing of fields within these variants can then resolve back to the parent ADT. This necessitates recursion guards in operations like is_concrete and a new ActiveADT mechanism in the Context to track recursive unify calls. For codegen, make_node must also incorporate recursion guards to handle potentially recursive GCC nodes representing Rust ADTs.
- gccrs
- The GCC frontend for the Rust programming language, enabling Rust code compilation within the GCC toolchain.
- Recursive ADT
- An Algebraic Data Type (ADT) that can contain a field referencing the ADT itself, allowing for self-referential data structures like linked lists or trees.
- Type Checking
- The process of verifying that a program's source code adheres to the language's type rules. In gccrs, this ensures that Rust types are used correctly.
- Type Unification
- A process in type systems where two types are compared, and if possible, made equivalent by finding a most general type that satisfies constraints from both.
- Code Generation
- The phase of a compiler where intermediate representation code is translated into target machine code or another lower-level representation.