ruff/crates/ruff_python_semantic/src
Charlie Marsh 424b8d4ad2
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`
2023-08-21 21:32:57 -04:00
..
analyze Add branch detection to the semantic model (#6694) 2023-08-19 21:28:17 +00:00
binding.rs Use a single node hierarchy to track statements and expressions (#6709) 2023-08-21 21:32:57 -04:00
branches.rs Add branch detection to the semantic model (#6694) 2023-08-19 21:28:17 +00:00
context.rs Remove separate ReferenceContext enum (#4631) 2023-05-24 15:12:38 +00:00
definition.rs Use dedicated AST nodes on MemberKind (#6374) 2023-08-07 17:17:58 +00:00
globals.rs Remove async AST node variants for with, for, and def (#6369) 2023-08-07 16:36:02 +00:00
lib.rs Use a single node hierarchy to track statements and expressions (#6709) 2023-08-21 21:32:57 -04:00
model.rs Use a single node hierarchy to track statements and expressions (#6709) 2023-08-21 21:32:57 -04:00
nodes.rs Use a single node hierarchy to track statements and expressions (#6709) 2023-08-21 21:32:57 -04:00
reference.rs Implement Ranged on more structs (#6639) 2023-08-17 11:22:39 -04:00
scope.rs Remove async AST node variants for with, for, and def (#6369) 2023-08-07 16:36:02 +00:00
star_import.rs Move StarImport to its own module (#5186) 2023-06-20 13:12:46 -04:00