mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 20:09:22 +00:00
Use a single node hierarchy to track statements and expressions (#6709)
## Summary This PR is a follow-up to the suggestion in https://github.com/astral-sh/ruff/pull/6345#discussion_r1285470953 to use a single stack to store all statements and expressions, rather than using separate vectors for each, which gives us something closer to a full-fidelity chain. (We can then generalize this concept to include all other AST nodes too.) This is in part made possible by the removal of the hash map from `&Stmt` to `StatementId` (#6694), which makes it much cheaper to store these using a single interface (since doing so no longer introduces the requirement that we hash all expressions). I'll follow-up with some profiling, but a few notes on how the data requirements have changed: - We now store a `BranchId` for every expression, not just every statement, so that's an extra `u32`. - We now store a single `NodeId` on every snapshot, rather than separate `StatementId` and `ExpressionId` IDs, so that's one fewer `u32` for each snapshot. - We're probably doing a few more lookups in general, since any calls to `current_statement()` etc. now have to iterate up the node hierarchy until they identify the first statement. ## Test Plan `cargo test`
This commit is contained in:
parent
abc5065fc7
commit
424b8d4ad2
12 changed files with 268 additions and 299 deletions
|
@ -3,22 +3,20 @@ mod binding;
|
|||
mod branches;
|
||||
mod context;
|
||||
mod definition;
|
||||
mod expressions;
|
||||
mod globals;
|
||||
mod model;
|
||||
mod nodes;
|
||||
mod reference;
|
||||
mod scope;
|
||||
mod star_import;
|
||||
mod statements;
|
||||
|
||||
pub use binding::*;
|
||||
pub use branches::*;
|
||||
pub use context::*;
|
||||
pub use definition::*;
|
||||
pub use expressions::*;
|
||||
pub use globals::*;
|
||||
pub use model::*;
|
||||
pub use nodes::*;
|
||||
pub use reference::*;
|
||||
pub use scope::*;
|
||||
pub use star_import::*;
|
||||
pub use statements::*;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue