gccrs: Separate scopes for function arguments and bodies
gccrs enhances scope management for function arguments and bodies, improving drop order.
GCC’s Rust front-end, gccrs, now separates scope management for function arguments and their bodies. The argument scope is created before parameter compilation, ensuring argument drops are registered correctly. The function body is compiled in a nested scope, and its scope is cleaned up before the argument scope, guaranteeing that body locals are dropped before parameters.
In Details
In gccrs, the compiler creates distinct scopes for function argument declarations and the function body to manage the lifetime of variables and their associated drop calls correctly. This change ensures that argument scope is established prior to processing function parameters, so that any drop actions related to arguments are localized to that scope. Subsequently, the function's body is compiled within a nested scope. The cleanup order is reversed: the inner body scope is dropped before the outer argument scope, ensuring that local variables within the body are deallocated before argum…
- scope
- A region of the code where a declared variable or name is valid and can be accessed. In
gccrs, scopes are used to manage the lifetime of variables and their associated cleanup actions (likedrop). - drop
- In Rust, a
dropis an action that runs when a value goes out of scope, typically to deallocate memory or release resources.gccrsneeds to manage thesedropcalls correctly. - HIR lowering
- The process in
gccrsof transforming the Abstract Syntax Tree (AST) into a High-Level Intermediate Representation (HIR). This stage typically simplifies code structure and prepares it for further optimization and code generation. - argument scope
- A scope specifically created in
gccrsto manage variables and their lifetimes related to function parameters. - function body scope
- A scope created within
gccrsfor the variables declared inside a function's implementation.