-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[red-knot] unify LoopState and saved_break_states #16406
Conversation
41e8d59
to
01b0235
Compare
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
* main: [red-knot] unify LoopState and saved_break_states (#16406) [`pylint`] Also reports `case np.nan`/`case math.nan` (`PLW0177`) (#16378) [FURB156] Do not consider docstring(s) (#16391) Use `is_none_or` in `stdlib-module-shadowing` (#16402) [red-knot] Upgrade salsa to include `AtomicPtr` perf improvement (#16398) [red-knot] Fix file watching for new non-project files (#16395) document MSRV policy (#16384) [red-knot] fix non-callable reporting for unions (#16387) bump MSRV to 1.83 (#16294) Avoid unnecessary info at non-trace server log level (#16389) Expand `ruff.configuration` to allow inline config (#16296) Start detecting version-related syntax errors in the parser (#16090)
* dcreager/dont-have-a-cow: [red-knot] unify LoopState and saved_break_states (#16406) [`pylint`] Also reports `case np.nan`/`case math.nan` (`PLW0177`) (#16378) [FURB156] Do not consider docstring(s) (#16391) Use `is_none_or` in `stdlib-module-shadowing` (#16402) [red-knot] Upgrade salsa to include `AtomicPtr` perf improvement (#16398) [red-knot] Fix file watching for new non-project files (#16395) document MSRV policy (#16384) [red-knot] fix non-callable reporting for unions (#16387) bump MSRV to 1.83 (#16294) Avoid unnecessary info at non-trace server log level (#16389) Expand `ruff.configuration` to allow inline config (#16296) Start detecting version-related syntax errors in the parser (#16090)
#[derive(Clone, Debug, Default)] | ||
struct Loop { | ||
/// Flow states at each `break` in the current loop. | ||
break_states: Vec<FlowSnapshot>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked through all usages but I'm wondering if we could use a single break_states
struct stored on SemanticIndexBuilder
instead of allocating a Vec
for each Loop
.
What I'm thinking about:
Loop
: stores the length of the "arena" at the time this loop was pushed- Getting all break states for the current loop is the same as
arena[start..]
- When popping a loop, truncate the arena to
start
to remove all snapshots belonging to the current state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had originally thought I might invest more time in reducing vec allocations here, but the simple version was completely neutral on benchmarks, so I'm not sure it's worth putting more time into this right now. I think perf optimization work should be motivated by some evidence.
I suspect that in practice loops are relatively uncommon, and loops with break
in them even more uncommon, so in the great majority of cases we never allocate for this vec at all. I think if we want to improve performance of semantic indexing, there will be much higher-ROI things to look at.
* main: [red-knot] unify LoopState and saved_break_states (#16406) [`pylint`] Also reports `case np.nan`/`case math.nan` (`PLW0177`) (#16378) [FURB156] Do not consider docstring(s) (#16391) Use `is_none_or` in `stdlib-module-shadowing` (#16402) [red-knot] Upgrade salsa to include `AtomicPtr` perf improvement (#16398) [red-knot] Fix file watching for new non-project files (#16395) document MSRV policy (#16384) [red-knot] fix non-callable reporting for unions (#16387) bump MSRV to 1.83 (#16294) Avoid unnecessary info at non-trace server log level (#16389) Expand `ruff.configuration` to allow inline config (#16296) Start detecting version-related syntax errors in the parser (#16090)
We currently keep two separate pieces of state regarding the current loop on
SemanticIndexBuilder
. One is an enum simply reflecting whether we are currently inside a loop, and the other is the saved flow states forbreak
statements found in the current loop.For adding loopy control flow, I'll need to add some additional loop state (
continue
states, for example). Prepare for this by consolidating our existing loop state into a single struct and simplifying the API for pushing and popping a loop.This is purely a refactor, so tests are not changed.