-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[ty] more precise lazy scope place lookup #19932
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
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
CodSpeed Instrumentation Performance ReportMerging #19932 will not alter performanceComparing Summary
|
CodSpeed WallTime Performance ReportMerging #19932 will not alter performanceComparing Summary
|
…hether to keep the lazy snapshot
f785733
to
69f82c7
Compare
69f82c7
to
4225c28
Compare
04f57df
to
5a07823
Compare
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.
Thank you!
Took a quick look, made one comment -- I want to take a closer look at some of the changes in use-def map, will try to do that tomorrow.
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.
Thanks for your work on this, and sorry it took me a while to complete review! I think this is an important issue to solve, and this definitely improves the behavior. That said, I'm not convinced that the approach taken is really correct. I commented inline on the specific problematic point. Currently this PR marks snapshots as "incomplete" and then later tries to figure out how to "merge" that incomplete snapshot with all-reachable-bindings. This makes it quite difficult to figure out which of the "all-reachable" bindings should be considered vs ignored.
I think a more robust approach here might be to actually update the snapshot with new bindings, as we encounter new bindings after the snapshot was created.
crates/ty_python_semantic/src/semantic_index/use_def/place_state.rs
Outdated
Show resolved
Hide resolved
81dbc63
to
de6e9db
Compare
48eaf75
to
3fc81ab
Compare
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.
Looks good, thank you!
## Summary This is a follow-up to astral-sh#19321. Now lazy snapshots are updated to take into account new bindings on every symbol reassignment. ```python def outer(x: A | None): if x is None: x = A() reveal_type(x) # revealed: A def inner() -> None: # lazy snapshot: {x: A} reveal_type(x) # revealed: A inner() def outer() -> None: x = None x = 1 def inner() -> None: # lazy snapshot: {x: Literal[1]} -> {x: Literal[1, 2]} reveal_type(x) # revealed: Literal[1, 2] inner() x = 2 ``` Closes astral-sh/ty#559. ## Test Plan Some TODOs in `public_types.md` now work properly. --------- Co-authored-by: Carl Meyer <[email protected]>
Summary
This is a follow-up to #19321.
This PR introduces the concept of "completeness" toEnclosingSnapshot
, making lookup of nonlocal symbols more precise.Here's the new mechanism we'll add: bindings that appear before the lazy nested scope can be analyzed exactly for reachability and narrowing. We record them in enclosing snapshots, and if bindings appear after the lazy nested scope, instead of sweeping the snapshot, we mark it as "incomplete." Then, at load time, we analyze bindings before the nested scope exactly, and always treat bindings after the nested scope as bound.Now lazy snapshots are updated to take into account new bindings on every symbol reassignment.
Closes astral-sh/ty#559.
Test Plan
Some TODOs in
public_types.md
now work properly.