[ty] Fall back to ambiguous for large control flow graphs#23399
[ty] Fall back to ambiguous for large control flow graphs#23399charliermarsh merged 4 commits intomainfrom
Conversation
Typing conformance resultsNo changes detected ✅ |
|
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-await |
40 | 0 | 0 |
invalid-argument-type |
0 | 1 | 0 |
invalid-return-type |
1 | 0 | 0 |
| Total | 41 | 1 | 0 |
| if self.interiors.len() >= MAX_INTERIOR_NODES { | ||
| return AMBIGUOUS; | ||
| } |
There was a problem hiding this comment.
Why are these placed before, and not after the cache lookup?
| /// (e.g., a 5000-line while loop with hundreds of if-branches). This is sound: we lose | ||
| /// precision about what's definitely reachable/unreachable but never report incorrect results. |
There was a problem hiding this comment.
Well, that depends on how we interpret "incorrect results". Losing precision in the reachability and narrowing constraint BDD can lead to all sorts of incorrect results, both false positives and false negatives. I would probably write something like
| /// (e.g., a 5000-line while loop with hundreds of if-branches). This is sound: we lose | |
| /// precision about what's definitely reachable/unreachable but never report incorrect results. | |
| /// (e.g., a 5000-line while loop with hundreds of if-branches). This can lead to less precise | |
| /// reachability analysis and type narrowing. |
| /// operations return `AMBIGUOUS` to prevent exponential blowup on pathological inputs | ||
| /// (e.g., a 5000-line while loop with hundreds of if-branches). This is sound: we lose | ||
| /// precision about what's definitely reachable/unreachable but never report incorrect results. | ||
| const MAX_INTERIOR_NODES: usize = 512 * 1024; |
There was a problem hiding this comment.
I have no feeling for the magnitude of this number. I understand that it solves the Tauon problem, but I don't know how many other real world projects this might affect. Can we maybe push a test branch where we panic! if we exceed the threshold and see how many ecosystem projects fail (if any)?
Ideally, I think we would calibrate that number by e.g. decreasing the threshold until we hit panics, and then make it 10x or 100x larger to be "far away enough" from affecting any real projects (apart from Tauon, I guess).
I also tried to generate a test case for this feature, but my first attempt resulted in a relatively large input (which gives me some confidence that this threshold is high enough). I should probably add loops, because they seem to make the problem much worse.
There was a problem hiding this comment.
So it looks like 64 * 1024 leads to a panic in setuptools, but 128 * 1024 has no panic. I'll stick with 512 * 1024 for now as a reasonable increase atop that, though obviously somewhat arbitrary...
108580a to
f7729e1
Compare
My understanding is that it increased the number of nodes by about 50% (i.e., we were already creating around 2M nodes), though I don't fully understand why the runtime exploded at that threshold. |
…23399) ## Summary This [giant loop](https://github.com/Taiko2k/Tauon/blob/08bfd249f404817e58078a2cbce7a69d3f949f0c/src/tauon/t_modules/t_main.py#L44882-L49772) is causing us to create (per Claude) over 3 million nodes in the TDD graph. We now cap the analysis, which causes us to fall back to "ambiguous" -- so we can still detect most diagnostics, but lose some capabilities. Closes astral-sh/ty#2846.
Summary
This giant loop is causing us to create (per Claude) over 3 million nodes in the TDD graph. We now cap the analysis, which causes us to fall back to "ambiguous" -- so we can still detect most diagnostics, but lose some capabilities.
Closes astral-sh/ty#2846.