Skip to content

Conversation

@sinsoku
Copy link
Contributor

@sinsoku sinsoku commented Feb 8, 2026

When Hash#[]= was called on a local variable inside a method, the
assigned key/value types flowed back into the method's parameter type.
This caused type explosion in real-world code like Action Pack's
url_for, where the parameter type grew into a deeply nested recursive
Hash type.

Introduce HashAsetBox to handle Hash#[]= on local variables with
flow-sensitive tracking. Instead of modifying the original hash type
via backflow, it creates a new variable version with the updated type,
so the parameter type only reflects types from call sites.

fixes #362

When `Hash#[]=` was called on a local variable inside a method, the
assigned key/value types flowed back into the method's parameter type.
This caused type explosion in real-world code like Action Pack's
`url_for`, where the parameter type grew into a deeply nested recursive
Hash type.

Introduce HashAsetBox to handle `Hash#[]=` on local variables with
flow-sensitive tracking. Instead of modifying the original hash type
via backflow, it creates a new variable version with the updated type,
so the parameter type only reflects types from call sites.
@sinsoku
Copy link
Contributor Author

sinsoku commented Feb 8, 2026

@mame
Sorry, the tests never finished. 😢
The changes in this PR may have put tool/dog_bench.rb into an infinite loop.
I was unable to cancel the job.
https://github.com/ruby/typeprof/actions/runs/21793213134

The default timeout for GitHub Actions is 360 minutes, so it would be helpful if you could cancel it before it wastes execution time.

HashAsetBox.run0 created new Vertex objects on every invocation.
Since Type memoization relies on object identity, each run produced
"new" types that fed back through loop back-edges, preventing the
graph from reaching a fixed point.

Cache Vertex objects as instance variables so they are reused across
runs, allowing Type memoization to recognize identical structures
and the analysis to converge.
sinsoku added a commit to sinsoku/typeprof that referenced this pull request Feb 8, 2026
TypeProf may cause infinite loops due to implementation mistakes,
so set a timeout to avoid wasting CI execution time.

ref: ruby#363 (comment)
mame pushed a commit that referenced this pull request Feb 9, 2026
TypeProf may cause infinite loops due to implementation mistakes,
so set a timeout to avoid wasting CI execution time.

ref: #363 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parameter type includes values assigned via Hash#[]= on local variable

1 participant