TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Fixed `anyFunctionType` leak

Open Andarist opened this issue 5 months ago • 8 comments

fixes https://github.com/microsoft/TypeScript/issues/61979

Andarist avatar Jun 30 '25 22:06 Andarist

@typescript-bot test it

jakebailey avatar Jun 30 '25 22:06 jakebailey

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started ✅ Results
user test this ✅ Started ✅ Results
run dt ✅ Started ✅ Results
perf test this faster ✅ Started 👀 Results

typescript-bot avatar Jun 30 '25 22:06 typescript-bot

Hey @jakebailey, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

typescript-bot avatar Jun 30 '25 22:06 typescript-bot

@jakebailey Here are the results of running the user tests with tsc comparing main and refs/pull/61980/merge:

Everything looks good!

typescript-bot avatar Jun 30 '25 22:06 typescript-bot

@jakebailey The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 34 34 ~ ~ ~ p=1.000 n=6
Symbols 62,370 62,370 ~ ~ ~ p=1.000 n=6
Types 50,386 50,386 ~ ~ ~ p=1.000 n=6
Memory used 194,759k (± 1.03%) 195,995k (± 0.73%) ~ 193,078k 196,692k p=0.173 n=6
Parse Time 1.60s (± 1.51%) 1.60s (± 0.92%) ~ 1.58s 1.62s p=0.459 n=6
Bind Time 0.88s (± 2.03%) 0.87s (± 1.92%) ~ 0.84s 0.89s p=0.285 n=6
Check Time 11.80s (± 0.79%) 11.83s (± 0.76%) ~ 11.70s 11.93s p=0.686 n=6
Emit Time 3.34s (± 3.76%) 3.33s (± 3.48%) ~ 3.25s 3.56s p=1.000 n=6
Total Time 17.62s (± 0.94%) 17.64s (± 0.64%) ~ 17.47s 17.78s p=0.630 n=6
angular-1 - node (v18.15.0, x64)
Errors 56 56 ~ ~ ~ p=1.000 n=6
Symbols 948,753 948,753 ~ ~ ~ p=1.000 n=6
Types 410,846 410,846 ~ ~ ~ p=1.000 n=6
Memory used 1,225,228k (± 0.00%) 1,225,209k (± 0.00%) ~ 1,225,181k 1,225,231k p=0.470 n=6
Parse Time 7.93s (± 0.60%) 7.94s (± 0.56%) ~ 7.88s 7.99s p=0.747 n=6
Bind Time 2.27s (± 0.72%) 2.26s (± 0.46%) ~ 2.25s 2.28s p=0.210 n=6
Check Time 37.91s (± 0.48%) 37.91s (± 0.22%) ~ 37.74s 37.97s p=0.688 n=6
Emit Time 17.77s (± 0.40%) 17.78s (± 0.55%) ~ 17.61s 17.90s p=0.375 n=6
Total Time 65.88s (± 0.30%) 65.89s (± 0.18%) ~ 65.69s 66.02s p=1.000 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,509,183 2,509,183 ~ ~ ~ p=1.000 n=6
Types 892,716 892,716 ~ ~ ~ p=1.000 n=6
Memory used 2,804,395k (± 0.01%) 2,804,479k (± 0.00%) ~ 2,804,337k 2,804,557k p=0.810 n=6
Parse Time 10.50s (± 0.35%) 10.50s (± 0.48%) ~ 10.45s 10.58s p=1.000 n=6
Bind Time 2.73s (± 0.55%) 2.74s (± 0.72%) ~ 2.72s 2.77s p=0.934 n=6
Check Time 101.98s (± 1.24%) 101.21s (± 0.29%) ~ 100.64s 101.45s p=0.689 n=6
Emit Time 0.78s (±129.01%) 0.37s (± 2.67%) ~ 0.36s 0.38s p=0.611 n=6
Total Time 115.99s (± 1.77%) 114.81s (± 0.28%) ~ 114.19s 115.10s p=0.810 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,227,081 1,227,081 ~ ~ ~ p=1.000 n=6
Types 267,474 267,474 ~ ~ ~ p=1.000 n=6
Memory used 2,730,873k (±14.64%) 2,731,389k (±14.64%) ~ 2,365,119k 3,097,551k p=0.575 n=6
Parse Time 6.64s (± 1.19%) 6.60s (± 1.66%) ~ 6.46s 6.73s p=0.630 n=6
Bind Time 2.16s (± 1.30%) 2.19s (± 1.57%) ~ 2.15s 2.23s p=0.253 n=6
Check Time 42.63s (± 0.32%) 42.84s (± 0.53%) ~ 42.51s 43.17s p=0.065 n=6
Emit Time 3.55s (± 4.31%) 3.44s (± 0.95%) 🟩-0.11s (- 3.05%) 3.40s 3.48s p=0.045 n=6
Total Time 54.99s (± 0.26%) 55.06s (± 0.53%) ~ 54.66s 55.44s p=0.810 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,227,081 1,227,081 ~ ~ ~ p=1.000 n=6
Types 267,474 267,474 ~ ~ ~ p=1.000 n=6
Memory used 3,039,830k (± 9.78%) 2,918,915k (±12.90%) ~ 2,431,851k 3,163,406k p=0.810 n=6
Parse Time 6.92s (± 1.40%) 6.86s (± 1.63%) ~ 6.67s 6.95s p=0.423 n=6
Bind Time 2.18s (± 1.57%) 2.16s (± 2.18%) ~ 2.11s 2.22s p=0.520 n=6
Check Time 42.85s (± 0.63%) 43.06s (± 0.27%) ~ 42.90s 43.23s p=0.128 n=6
Emit Time 3.54s (± 2.72%) 3.60s (± 0.54%) ~ 3.58s 3.63s p=0.470 n=6
Total Time 55.48s (± 0.65%) 55.67s (± 0.15%) ~ 55.58s 55.80s p=0.470 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 262,548 262,548 ~ ~ ~ p=1.000 n=6
Types 107,156 107,156 ~ ~ ~ p=1.000 n=6
Memory used 441,957k (± 0.02%) 441,912k (± 0.02%) ~ 441,851k 442,049k p=0.298 n=6
Parse Time 3.52s (± 0.71%) 3.52s (± 0.79%) ~ 3.47s 3.55s p=1.000 n=6
Bind Time 1.33s (± 1.00%) 1.32s (± 1.35%) ~ 1.29s 1.34s p=0.458 n=6
Check Time 18.88s (± 0.29%) 18.89s (± 0.32%) ~ 18.78s 18.94s p=0.574 n=6
Emit Time 1.53s (± 1.09%) 1.52s (± 0.97%) ~ 1.50s 1.54s p=0.560 n=6
Total Time 25.26s (± 0.36%) 25.25s (± 0.23%) ~ 25.18s 25.32s p=0.872 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 71 71 ~ ~ ~ p=1.000 n=6
Symbols 225,367 225,367 ~ ~ ~ p=1.000 n=6
Types 94,290 94,290 ~ ~ ~ p=1.000 n=6
Memory used 371,137k (± 0.03%) 371,265k (± 0.08%) ~ 371,099k 371,887k p=0.261 n=6
Parse Time 3.58s (± 0.72%) 3.59s (± 0.53%) ~ 3.57s 3.61s p=1.000 n=6
Bind Time 1.97s (± 0.87%) 1.98s (± 0.95%) ~ 1.95s 2.00s p=0.627 n=6
Check Time 20.32s (± 0.25%) 20.31s (± 0.33%) ~ 20.22s 20.43s p=0.687 n=6
Emit Time 0.00s 0.00s (±244.70%) ~ 0.00s 0.01s p=0.405 n=6
Total Time 25.87s (± 0.26%) 25.88s (± 0.30%) ~ 25.78s 25.99s p=1.000 n=6
vscode - node (v18.15.0, x64)
Errors 33 33 ~ ~ ~ p=1.000 n=6
Symbols 3,499,297 3,499,297 ~ ~ ~ p=1.000 n=6
Types 1,177,214 1,177,214 ~ ~ ~ p=1.000 n=6
Memory used 3,549,841k (± 0.01%) 3,549,767k (± 0.01%) ~ 3,549,455k 3,550,012k p=0.378 n=6
Parse Time 14.98s (± 0.41%) 15.00s (± 0.31%) ~ 14.94s 15.08s p=0.747 n=6
Bind Time 4.90s (± 0.60%) 4.89s (± 0.42%) ~ 4.86s 4.92s p=1.000 n=6
Check Time 95.52s (± 3.15%) 96.59s (± 4.04%) ~ 93.48s 101.82s p=0.936 n=6
Emit Time 30.04s (± 2.34%) 30.65s (± 4.07%) ~ 29.64s 32.81s p=0.173 n=6
Total Time 145.44s (± 2.39%) 147.13s (± 2.89%) ~ 143.75s 152.75s p=0.471 n=6
webpack - node (v18.15.0, x64)
Errors 2 2 ~ ~ ~ p=1.000 n=6
Symbols 318,019 318,019 ~ ~ ~ p=1.000 n=6
Types 137,705 137,705 ~ ~ ~ p=1.000 n=6
Memory used 472,012k (± 0.01%) 471,991k (± 0.01%) ~ 471,908k 472,090k p=0.688 n=6
Parse Time 3.58s (± 0.41%) 3.59s (± 0.58%) ~ 3.55s 3.61s p=0.373 n=6
Bind Time 1.44s (± 0.68%) 1.43s (± 0.73%) ~ 1.42s 1.45s p=0.673 n=6
Check Time 17.38s (± 0.39%) 17.36s (± 0.41%) ~ 17.26s 17.46s p=0.688 n=6
Emit Time 0.00s (±244.70%) 0.00s ~ ~ ~ p=0.405 n=6
Total Time 22.40s (± 0.26%) 22.38s (± 0.41%) ~ 22.27s 22.52s p=0.568 n=6
xstate-main - node (v18.15.0, x64)
Errors 30 30 ~ ~ ~ p=1.000 n=6
Symbols 665,978 665,978 ~ ~ ~ p=1.000 n=6
Types 199,345 199,345 ~ ~ ~ p=1.000 n=6
Memory used 570,269k (± 0.03%) 570,339k (± 0.02%) ~ 570,088k 570,480k p=0.748 n=6
Parse Time 4.24s (± 0.50%) 4.25s (± 0.73%) ~ 4.20s 4.28s p=0.806 n=6
Bind Time 1.33s (± 0.41%) 1.33s (± 0.67%) ~ 1.32s 1.34s p=0.341 n=6
Check Time 20.01s (± 0.98%) 19.99s (± 1.67%) ~ 19.77s 20.66s p=0.471 n=6
Emit Time 0.00s (±244.70%) 0.00s (±244.70%) ~ 0.00s 0.01s p=1.000 n=6
Total Time 25.60s (± 0.84%) 25.56s (± 1.35%) ~ 25.36s 26.26s p=0.471 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6
Developer Information:

Download Benchmarks

typescript-bot avatar Jun 30 '25 23:06 typescript-bot

@jakebailey Here are the results of running the top 400 repos with tsc comparing main and refs/pull/61980/merge:

Everything looks good!

typescript-bot avatar Jul 01 '25 00:07 typescript-bot

This feels plausible, but I find it surprising that we haven't used this trick elsewhere?

jakebailey avatar Dec 05 '25 18:12 jakebailey

This leak is quite specific to generic functions containing context-sensitive parts when other parts of the argument(s) are context-sensitive too.

The problem is that the generic function itself is not treated as context-sensitive per-se (despite it containing context-sensitive functions inside it) so without other context-sensitive parts of the arguments the initial argCheckMode stays as CheckMode.Normal. In that scenario, only a single inference pass happens and the inner context-sensitive function gets resolved correctly.

But in the other situation, the argCheckMode gets set to CheckMode.SkipContextSensitive and if that gets propagate to the inner context-sensitive function, its return type gets cached incorrectly. Remember that its being cached while checking a supposedly non-context sensitive parent - whereas normally, a parent is always~ context-sensitive when it contains context-sensitive descendants as that "trait" propagates from descandants to ancestors.

Andarist avatar Dec 05 '25 19:12 Andarist