Prevent Hash#[]= on local variables from polluting parameter types#363
Open
sinsoku wants to merge 5 commits intoruby:masterfrom
Open
Prevent Hash#[]= on local variables from polluting parameter types#363sinsoku wants to merge 5 commits intoruby:masterfrom
Hash#[]= on local variables from polluting parameter types#363sinsoku wants to merge 5 commits intoruby:masterfrom
Conversation
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.
Contributor
Author
|
@mame 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)
Merge all Record type variants into a single output in `HashAsetBox#run0` instead of creating one output per input Record. This prevents 2^N type explosion when a hash has many conditional assignments (e.g. `h[:k] = v if cond`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
Hash#[]=was called on a local variable inside a method, theassigned 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 recursiveHash type.
Introduce HashAsetBox to handle
Hash#[]=on local variables withflow-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