Skip to content

Comments

[ty] Create Definition for all place expressions#18890

Closed
dhruvmanila wants to merge 1 commit intomainfrom
dhruv/unpack-diagnostics-bug
Closed

[ty] Create Definition for all place expressions#18890
dhruvmanila wants to merge 1 commit intomainfrom
dhruv/unpack-diagnostics-bug

Conversation

@dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Jun 23, 2025

Summary

This PR was the first iteration on solving astral-sh/ty#185 but later realized there's a simpler solution instead.

Regardless, this PR does seem useful but it's not a priority so I'm just noting down the things that I've changed and learned:

  • Expands PlaceExpr so that it is constructed for every attribute / subscript expression and not only a subset of it. This allows us to create Definition for every attribute / subscript expression that's involved in an assignment.
  • Combine infer_target and infer_target_impl and remove the complexity of the closure parameter and streamline the logic so that it all boils down to calling infer_definition for the Definition that belongs to name / attribute / subscript expression.
  • Move the attribute assignment validation to add_binding since that's where the assignability check for name expressions are.

This also simplifies handling the target inference so that it's only a single infer_target call although it does has it's own complexity specifically around the fact that the value expression of the first comprehension needs to be inferred from the outer scope and not the comprehension scope.

Test Plan

@dhruvmanila dhruvmanila added the ty Multi-file analysis & type inference label Jun 23, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Jun 23, 2025

CodSpeed Instrumentation Performance Report

Merging #18890 will degrade performances by 7.8%

Comparing dhruv/unpack-diagnostics-bug (ae4f960) with main (e474f36)

Summary

❌ 4 regressions
✅ 33 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
ty_check_file[cold] 120.9 ms 127.9 ms -5.48%
ty_micro[many_string_assignments] 66.5 ms 72.2 ms -7.8%
anyio 868.5 ms 912.8 ms -4.86%
attrs 360.3 ms 383.2 ms -5.98%

@codspeed-hq
Copy link

codspeed-hq bot commented Jun 23, 2025

CodSpeed WallTime Performance Report

Merging #18890 will improve performances by 5.69%

Comparing dhruv/unpack-diagnostics-bug (ae4f960) with main (e474f36)

Summary

⚡ 1 improvements
✅ 7 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
small[freqtrade] 9 s 8.5 s +5.69%

dhruvmanila added a commit that referenced this pull request Jun 24, 2025
## Summary

This PR fixes astral-sh/ty#185 by avoiding to infer the value expression
for an unpacking.

This is done simply by only inferring the value expression in a
non-unpacking branch for assignment statement, for statement, with
statement and comprehensions.

This is a simpler alternative to
#18890 which I only realized in
hindsight! Ideally, the solution would to consider the "unpack" as it's
own region and do all of the inference of every expressions involved in
an unpacking inside the unpack query and then merge the results in the
outer query. This would require access to the `Unpack` ingredient which
is stored on the `Definition`. And, this would require create the said
`Definition`s for all attributes and subscript expressions. It does
simplify the target inference logic by streamlining it into a single
`infer_target` method instead of the `infer_target`/`infer_target_impl`
split.

Additionally, #18890 also solves a couple of TODOs around raising errors
around attribute / subscript assignment.

## Test Plan

Update the existing test, go through a couple of ecosystem diagnostic.
@dhruvmanila dhruvmanila force-pushed the dhruv/unpack-diagnostics-bug branch 2 times, most recently from c14bf1e to 6e5113a Compare June 24, 2025 05:36
@dhruvmanila dhruvmanila force-pushed the dhruv/unpack-diagnostics-bug branch from 6e5113a to ae4f960 Compare June 24, 2025 05:39
@dhruvmanila dhruvmanila changed the title [ty] [WIP] Remove duplicate unpack diagnostics [ty] Create Definition for all place expressions Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant