gccrs: Unify node trees for shared memory representation
Refactors ForeverStack to share node trees across instances, improving memory efficiency.
This change unifies node trees within gccrs’s ForeverStack, allowing multiple instances to share the same set of nodes. Previously, each ForeverStack built its own tree, leading to redundant memory usage. By introducing ForeverStackBase and making nodes shareable, this commit reduces memory overhead and simplifies the handling of node objects originating from ForeverStacks with different namespaces. This is a key step towards more efficient memory management in the Rust frontend.
In Details
The ForeverStack in gccrs represents a resolution scope, with nodes forming a tree structure. This commit factors out the Node definition and related members into a new base class, ForeverStackBase, allowing multiple ForeverStack instances to share the same underlying node memory. This is achieved by making root, lang_prelude, and extern_prelude references in ForeverStackBase and passing top-level nodes by reference to the ForeverStack constructor. This change specifically targets memory efficiency and the ability to handle nodes across different namespaces within the name resol…
- gccrs
- The GCC Rust frontend, responsible for parsing, type-checking, and generating code for Rust programs using the GCC compiler infrastructure.
- ForeverStack
- A data structure in gccrs used to represent and manage a stack of resolution scopes during name resolution. It organizes nodes hierarchically to track namespaces, types, and other linguistic constructs.
- Node
- An element within the ForeverStack's tree structure, representing a specific linguistic construct or scope. Nodes are interconnected to form a hierarchical representation of the code's structure.