ruff
fd9568a7 - [ty] prevent "tainted" unions in cycle normalization (#23563)

Commit
51 days ago
[ty] prevent "tainted" unions in cycle normalization (#23563) ## Summary There are some issues with our current cycle handling, particularly with our implementation of `Type::cycle_normalized`. To prevent values ​​from oscillating endlessly within a fixed-point iteration, `cycle_normalized` unions the type of the previous iteration with the current type. This ensures monotonicity of the type inference calculation. However, we've observed that always applying this union can sometimes produce undesirable results. Therefore, we make some exceptions where this union isn't applied (see #21909, #21910). However, these prescriptions are likely not exhaustive, and #22794 also confirmed the occurrence of "divergent pollution" when narrowing. The core issue in #22794 is that `Divergent` can inhibit narrowing. The result type itself does not contain `Divergent`, but `Divergent` indirectly affects it. This suggests that determining whether a type contains `Divergent` is not a perfect indicator of "taintedness". After carefully examining these cases, I found that the problematic "low-precision types" only appear in the first few iterations: `Divergent` itself and the type of the next iteration constructed by referencing it. Therefore, we shouldn't union these few iterations. I found that this simple change can remove all of the exceptional handling for `Divergent` introduced in #21909, #21910, and #22794. I also found that this change removes the too-many-cycle panic blocking #22633. ## Test Plan mdtest updated --------- Co-authored-by: Carl Meyer <carl@astral.sh>
Author
Parents
Loading