Skip to content

[ty] Simplify mapped intersections through aliases - #29154

Closed
charliermarsh wants to merge 1 commit into
charlie/ty-shared-recursion-guardsfrom
charlie/ty-alias-aware-intersections
Closed

charliermarsh wants to merge 1 commit into
charlie/ty-shared-recursion-guardsfrom
charlie/ty-alias-aware-intersections

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

Builds on #29152.

We now simplify mapped intersections through aliases without expanding the alias unless a simplification changes the result. For example:

from typing import Literal
from ty_extensions import Intersection, Not

type Minus[T, U] = Intersection[T, Not[U]]
type Boolean = bool
type TrueLiteral = Literal[True]

def f(x: Minus[Boolean, TrueLiteral]):
    reveal_type(x)  # Literal[False]

Previously, we revealed Boolean & ~Literal[True]. The alias was retained to avoid unfolding recursive types, but that hid the boolean from the normal simplification rule.

Intersection construction still expands unions, nested intersections, and enum complements so it can distribute and flatten them. The inner builder now inspects the underlying types when applying simplification rules, including truthiness, enum exclusions, constrained type variables, and gradual generics. Unchanged aliases retain their identity. This removes the separate lists of positive and negated alias shapes that could be preserved.

@charliermarsh charliermarsh added bug An issue describing something that isn't working, or a PR that fixes a bug ty The ty type checker labels Oct 6, 2026
@charliermarsh
charliermarsh added this pull request to stack #29153 October 6, 2026 23:40
@astral-sh-bot

astral-sh-bot Bot commented Oct 6, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 98.24%. The percentage of expected errors that received a diagnostic held steady at 98.24%. The number of fully passing files held steady at 134/146.

@astral-sh-bot

astral-sh-bot Bot commented Oct 6, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Oct 6, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@codspeed

codspeed Bot commented Oct 6, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 7.58%

❌ 6 regressed benchmarks
✅ 156 untouched benchmarks
⏩ 74 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ WallTime auto_imports[regular-package/after-module-create] 22.5 ms 25.7 ms -12.73%
❌ WallTime auto_imports[namespace-package/after-module-create] 26 ms 29.2 ms -10.87%
❌ Simulation ty_micro[pandas_tdd] 904.6 ms 992.7 ms -8.87%
❌ Simulation attrs (frozen inputs) 1.3 s 1.4 s -4.38%
❌ Simulation attrs 1.4 s 1.5 s -4.19%
❌ Simulation attrs (all rules) 1.4 s 1.5 s -4.06%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing charlie/ty-alias-aware-intersections (df4f9a4) with charlie/ty-shared-recursion-guards (bca1de0)

Open in CodSpeed

Footnotes

  1. 74 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@charliermarsh
charliermarsh removed this pull request from stack #29153 October 7, 2026 00:09

This branch was successfully deployed

1 active deployment
automations — df4f9a4d Deployed Oct 6, 2026 by charliermarsh via security-review / security review #90880
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant