Skip to content

Fix getRecursionIdentity function to always return some identity #43527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 5, 2021

Conversation

ahejlsberg
Copy link
Member

Fixes #43493.

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Apr 5, 2021
@ahejlsberg
Copy link
Member Author

ahejlsberg commented Apr 5, 2021

This PR implements the fix I describe here. Basically, getRecursionIdentity now always returns some identity, which by default is the type itself.

The PR reverts the changes from #43435 since they're no longer required and don't fix the core issue. However, I'm keeping the tests from that PR.

Regarding the baseline changes, two tests that previously failed now succeed--as they did when they were originally created.

The mappedTypeRecursiveInference.ts test would previously fail with an Excessive stack depth comparing types... error. That error no longer occurs, which is good. However, instead the test involving XMLHttpRequest ultimately fails with Type_instantiation_is_excessively_deep_and_possibly_infinite, which is expected but takes about twice as long as our test timeout limit. For that reason, I've deleted that particular test.

@ahejlsberg
Copy link
Member Author

@typescript-bot test this
@typescript-bot user test this
@typescript-bot run dt
@typescript-bot perf test this faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 5, 2021

Heya @ahejlsberg, I've started to run the perf test suite on this PR at 90382b2. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 5, 2021

Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 90382b2. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 5, 2021

Heya @ahejlsberg, I've started to run the abridged perf test suite on this PR at 90382b2. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 5, 2021

Heya @ahejlsberg, I've started to run the parallelized community code test suite on this PR at 90382b2. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 5, 2021

Heya @ahejlsberg, I've started to run the extended test suite on this PR at 90382b2. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..43527

Metric master 43527 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 344,904k (± 0.02%) 344,867k (± 0.03%) -37k (- 0.01%) 344,706k 345,193k
Parse Time 1.93s (± 0.41%) 1.93s (± 0.45%) +0.00s (+ 0.21%) 1.92s 1.95s
Bind Time 0.83s (± 0.87%) 0.83s (± 0.41%) +0.00s (+ 0.12%) 0.83s 0.84s
Check Time 5.09s (± 0.26%) 5.10s (± 0.62%) +0.01s (+ 0.28%) 5.06s 5.19s
Emit Time 5.91s (± 0.60%) 5.92s (± 0.89%) +0.00s (+ 0.02%) 5.85s 6.08s
Total Time 13.76s (± 0.31%) 13.78s (± 0.46%) +0.02s (+ 0.15%) 13.66s 13.92s
Compiler-Unions - node (v10.16.3, x64)
Memory used 203,345k (± 0.03%) 203,340k (± 0.04%) -5k (- 0.00%) 203,197k 203,530k
Parse Time 0.78s (± 0.43%) 0.78s (± 0.93%) -0.00s (- 0.13%) 0.77s 0.80s
Bind Time 0.52s (± 1.13%) 0.52s (± 1.06%) -0.00s (- 0.38%) 0.51s 0.53s
Check Time 7.46s (± 0.58%) 7.47s (± 0.32%) +0.01s (+ 0.13%) 7.41s 7.52s
Emit Time 2.60s (± 1.35%) 2.57s (± 0.96%) -0.03s (- 1.04%) 2.53s 2.64s
Total Time 11.37s (± 0.55%) 11.35s (± 0.30%) -0.02s (- 0.21%) 11.29s 11.41s
Monaco - node (v10.16.3, x64)
Memory used 342,642k (± 0.02%) 342,650k (± 0.02%) +9k (+ 0.00%) 342,541k 342,804k
Parse Time 1.55s (± 0.52%) 1.56s (± 0.49%) +0.00s (+ 0.32%) 1.54s 1.57s
Bind Time 0.74s (± 0.92%) 0.74s (± 0.49%) 0.00s ( 0.00%) 0.73s 0.74s
Check Time 5.26s (± 0.65%) 5.24s (± 0.42%) -0.02s (- 0.30%) 5.19s 5.28s
Emit Time 3.12s (± 0.41%) 3.10s (± 0.39%) -0.02s (- 0.61%) 3.08s 3.14s
Total Time 10.67s (± 0.37%) 10.64s (± 0.17%) -0.03s (- 0.28%) 10.60s 10.68s
TFS - node (v10.16.3, x64)
Memory used 304,257k (± 0.02%) 304,314k (± 0.02%) +57k (+ 0.02%) 304,164k 304,406k
Parse Time 1.21s (± 0.48%) 1.20s (± 0.57%) -0.00s (- 0.25%) 1.19s 1.22s
Bind Time 0.70s (± 0.93%) 0.70s (± 1.19%) -0.00s (- 0.43%) 0.67s 0.71s
Check Time 4.72s (± 0.54%) 4.72s (± 0.61%) +0.00s (+ 0.11%) 4.66s 4.78s
Emit Time 3.25s (± 1.05%) 3.22s (± 1.29%) -0.04s (- 1.17%) 3.13s 3.29s
Total Time 9.87s (± 0.38%) 9.84s (± 0.41%) -0.04s (- 0.39%) 9.75s 9.96s
material-ui - node (v10.16.3, x64)
Memory used 465,406k (± 0.02%) 465,540k (± 0.01%) +133k (+ 0.03%) 465,431k 465,679k
Parse Time 2.00s (± 0.70%) 2.00s (± 0.70%) +0.00s (+ 0.10%) 1.98s 2.05s
Bind Time 0.66s (± 0.98%) 0.66s (± 0.71%) +0.00s (+ 0.30%) 0.65s 0.67s
Check Time 14.22s (± 0.36%) 14.19s (± 0.39%) -0.03s (- 0.18%) 14.10s 14.32s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.88s (± 0.29%) 16.85s (± 0.37%) -0.03s (- 0.15%) 16.76s 17.03s
Angular - node (v12.1.0, x64)
Memory used 322,629k (± 0.03%) 322,648k (± 0.02%) +19k (+ 0.01%) 322,433k 322,774k
Parse Time 1.92s (± 0.52%) 1.91s (± 0.43%) -0.00s (- 0.16%) 1.90s 1.93s
Bind Time 0.81s (± 0.55%) 0.81s (± 0.42%) -0.00s (- 0.12%) 0.80s 0.81s
Check Time 5.00s (± 0.45%) 4.99s (± 0.52%) -0.01s (- 0.26%) 4.95s 5.06s
Emit Time 5.97s (± 0.41%) 6.05s (± 1.63%) +0.08s (+ 1.32%) 5.93s 6.41s
Total Time 13.69s (± 0.31%) 13.75s (± 0.82%) +0.06s (+ 0.44%) 13.61s 14.14s
Compiler-Unions - node (v12.1.0, x64)
Memory used 190,339k (± 0.16%) 190,026k (± 0.22%) -313k (- 0.16%) 189,129k 190,898k
Parse Time 0.77s (± 0.89%) 0.77s (± 0.58%) +0.00s (+ 0.26%) 0.76s 0.78s
Bind Time 0.53s (± 0.95%) 0.53s (± 1.23%) +0.00s (+ 0.57%) 0.52s 0.55s
Check Time 6.95s (± 0.38%) 7.00s (± 0.45%) +0.05s (+ 0.71%) 6.94s 7.09s
Emit Time 2.53s (± 0.89%) 2.57s (± 1.52%) +0.04s (+ 1.58%) 2.48s 2.70s
Total Time 10.76s (± 0.38%) 10.86s (± 0.45%) +0.10s (+ 0.91%) 10.77s 10.98s
Monaco - node (v12.1.0, x64)
Memory used 325,088k (± 0.02%) 325,015k (± 0.02%) -73k (- 0.02%) 324,807k 325,168k
Parse Time 1.53s (± 0.71%) 1.53s (± 0.53%) -0.00s (- 0.13%) 1.52s 1.55s
Bind Time 0.72s (± 0.56%) 0.72s (± 0.66%) -0.00s (- 0.28%) 0.71s 0.73s
Check Time 5.07s (± 0.50%) 5.08s (± 0.50%) +0.01s (+ 0.18%) 5.02s 5.13s
Emit Time 3.08s (± 0.47%) 3.08s (± 0.30%) -0.00s (- 0.06%) 3.06s 3.10s
Total Time 10.40s (± 0.25%) 10.41s (± 0.27%) +0.00s (+ 0.03%) 10.34s 10.45s
TFS - node (v12.1.0, x64)
Memory used 288,785k (± 0.02%) 288,733k (± 0.02%) -52k (- 0.02%) 288,555k 288,884k
Parse Time 1.21s (± 0.58%) 1.21s (± 0.90%) +0.00s (+ 0.08%) 1.19s 1.23s
Bind Time 0.69s (± 0.68%) 0.69s (± 1.01%) +0.00s (+ 0.14%) 0.68s 0.71s
Check Time 4.64s (± 0.57%) 4.67s (± 0.53%) +0.03s (+ 0.67%) 4.61s 4.72s
Emit Time 3.16s (± 0.63%) 3.16s (± 0.61%) -0.01s (- 0.22%) 3.11s 3.20s
Total Time 9.71s (± 0.44%) 9.73s (± 0.45%) +0.02s (+ 0.23%) 9.64s 9.82s
material-ui - node (v12.1.0, x64)
Memory used 443,470k (± 0.06%) 443,502k (± 0.09%) +32k (+ 0.01%) 442,452k 443,844k
Parse Time 2.03s (± 0.55%) 2.02s (± 0.44%) -0.00s (- 0.15%) 2.00s 2.04s
Bind Time 0.64s (± 0.53%) 0.64s (± 0.90%) +0.00s (+ 0.47%) 0.63s 0.65s
Check Time 12.84s (± 0.49%) 12.88s (± 0.77%) +0.04s (+ 0.34%) 12.75s 13.16s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.51s (± 0.38%) 15.54s (± 0.61%) +0.04s (+ 0.25%) 15.41s 15.81s
Angular - node (v14.15.1, x64)
Memory used 321,325k (± 0.01%) 321,364k (± 0.01%) +39k (+ 0.01%) 321,309k 321,402k
Parse Time 1.93s (± 0.42%) 1.92s (± 0.31%) -0.01s (- 0.78%) 1.90s 1.93s
Bind Time 0.86s (± 0.47%) 0.86s (± 0.35%) -0.00s (- 0.12%) 0.85s 0.86s
Check Time 4.99s (± 0.55%) 5.00s (± 0.67%) +0.01s (+ 0.20%) 4.93s 5.10s
Emit Time 6.29s (± 0.55%) 6.30s (± 0.53%) +0.01s (+ 0.11%) 6.23s 6.36s
Total Time 14.08s (± 0.29%) 14.08s (± 0.36%) 0.00s ( 0.00%) 13.96s 14.17s
Compiler-Unions - node (v14.15.1, x64)
Memory used 189,403k (± 0.02%) 189,397k (± 0.01%) -6k (- 0.00%) 189,353k 189,463k
Parse Time 0.80s (± 0.72%) 0.80s (± 1.21%) +0.00s (+ 0.12%) 0.79s 0.83s
Bind Time 0.55s (± 0.40%) 0.55s (± 0.62%) +0.00s (+ 0.36%) 0.55s 0.56s
Check Time 7.05s (± 0.47%) 7.03s (± 0.54%) -0.02s (- 0.23%) 6.94s 7.09s
Emit Time 2.55s (± 0.54%) 2.54s (± 1.02%) -0.01s (- 0.55%) 2.50s 2.62s
Total Time 10.96s (± 0.37%) 10.93s (± 0.36%) -0.03s (- 0.25%) 10.82s 10.98s
Monaco - node (v14.15.1, x64)
Memory used 324,044k (± 0.01%) 324,039k (± 0.01%) -5k (- 0.00%) 324,004k 324,089k
Parse Time 1.56s (± 0.37%) 1.56s (± 0.52%) +0.00s (+ 0.19%) 1.55s 1.58s
Bind Time 0.74s (± 0.49%) 0.74s (± 0.66%) 0.00s ( 0.00%) 0.74s 0.76s
Check Time 5.03s (± 0.44%) 5.02s (± 0.40%) -0.00s (- 0.06%) 4.99s 5.07s
Emit Time 3.17s (± 0.53%) 3.17s (± 0.57%) -0.01s (- 0.19%) 3.12s 3.21s
Total Time 10.50s (± 0.29%) 10.50s (± 0.41%) -0.00s (- 0.01%) 10.42s 10.62s
TFS - node (v14.15.1, x64)
Memory used 287,658k (± 0.01%) 287,669k (± 0.01%) +11k (+ 0.00%) 287,585k 287,742k
Parse Time 1.26s (± 0.67%) 1.27s (± 1.23%) +0.01s (+ 0.48%) 1.23s 1.30s
Bind Time 0.71s (± 0.63%) 0.72s (± 0.46%) +0.01s (+ 1.12%) 0.71s 0.73s
Check Time 4.65s (± 0.40%) 4.67s (± 0.45%) +0.01s (+ 0.24%) 4.62s 4.72s
Emit Time 3.24s (± 0.45%) 3.25s (± 0.67%) +0.01s (+ 0.31%) 3.21s 3.32s
Total Time 9.86s (± 0.22%) 9.90s (± 0.33%) +0.03s (+ 0.32%) 9.83s 9.96s
material-ui - node (v14.15.1, x64)
Memory used 441,589k (± 0.08%) 441,900k (± 0.06%) +311k (+ 0.07%) 440,906k 442,054k
Parse Time 2.09s (± 0.75%) 2.09s (± 0.46%) +0.00s (+ 0.00%) 2.07s 2.11s
Bind Time 0.69s (± 0.80%) 0.69s (± 0.84%) -0.01s (- 0.72%) 0.68s 0.70s
Check Time 13.04s (± 0.82%) 13.03s (± 0.90%) -0.00s (- 0.01%) 12.88s 13.45s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.82s (± 0.72%) 15.81s (± 0.69%) -0.01s (- 0.03%) 15.67s 16.20s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory10 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
Benchmark Name Iterations
Current 43527 10
Baseline master 10

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..43527

Metric master 43527 Delta Best Worst
Angular - node (v14.15.1, x64)
Memory used 321,325k (± 0.01%) 321,364k (± 0.01%) +39k (+ 0.01%) 321,280k 321,438k
Parse Time 1.93s (± 0.42%) 1.93s (± 0.49%) +0.00s (+ 0.00%) 1.91s 1.95s
Bind Time 0.86s (± 0.47%) 0.86s (± 0.52%) +0.00s (+ 0.35%) 0.85s 0.87s
Check Time 4.99s (± 0.55%) 5.02s (± 0.70%) +0.02s (+ 0.48%) 4.94s 5.08s
Emit Time 6.29s (± 0.55%) 6.33s (± 0.64%) +0.04s (+ 0.57%) 6.26s 6.45s
Total Time 14.08s (± 0.29%) 14.14s (± 0.48%) +0.06s (+ 0.45%) 14.00s 14.31s
Compiler-Unions - node (v14.15.1, x64)
Memory used 189,403k (± 0.02%) 189,410k (± 0.01%) +8k (+ 0.00%) 189,354k 189,460k
Parse Time 0.80s (± 0.72%) 0.80s (± 1.11%) +0.00s (+ 0.50%) 0.79s 0.83s
Bind Time 0.55s (± 0.40%) 0.56s (± 0.53%) +0.01s (+ 1.27%) 0.55s 0.56s
Check Time 7.05s (± 0.47%) 7.06s (± 0.53%) +0.01s (+ 0.14%) 6.99s 7.13s
Emit Time 2.55s (± 0.54%) 2.54s (± 0.57%) -0.01s (- 0.51%) 2.51s 2.57s
Total Time 10.96s (± 0.37%) 10.96s (± 0.41%) +0.01s (+ 0.05%) 10.88s 11.06s
Monaco - node (v14.15.1, x64)
Memory used 324,044k (± 0.01%) 324,027k (± 0.01%) -17k (- 0.01%) 323,996k 324,060k
Parse Time 1.56s (± 0.37%) 1.57s (± 0.42%) +0.01s (+ 0.83%) 1.56s 1.59s
Bind Time 0.74s (± 0.49%) 0.75s (± 0.64%) +0.00s (+ 0.40%) 0.74s 0.76s
Check Time 5.03s (± 0.44%) 5.04s (± 0.50%) +0.01s (+ 0.20%) 4.98s 5.10s
Emit Time 3.17s (± 0.53%) 3.20s (± 0.94%) +0.03s (+ 0.88%) 3.15s 3.30s
Total Time 10.50s (± 0.29%) 10.55s (± 0.48%) +0.05s (+ 0.50%) 10.47s 10.68s
TFS - node (v14.15.1, x64)
Memory used 287,658k (± 0.01%) 287,663k (± 0.01%) +6k (+ 0.00%) 287,607k 287,742k
Parse Time 1.26s (± 0.67%) 1.26s (± 0.99%) +0.00s (+ 0.24%) 1.23s 1.28s
Bind Time 0.71s (± 0.63%) 0.72s (± 0.97%) +0.01s (+ 0.98%) 0.71s 0.74s
Check Time 4.65s (± 0.40%) 4.69s (± 0.58%) +0.03s (+ 0.71%) 4.63s 4.76s
Emit Time 3.24s (± 0.45%) 3.27s (± 0.74%) +0.04s (+ 1.08%) 3.21s 3.32s
Total Time 9.86s (± 0.22%) 9.94s (± 0.50%) +0.08s (+ 0.79%) 9.82s 10.05s
material-ui - node (v14.15.1, x64)
Memory used 441,589k (± 0.08%) 441,894k (± 0.06%) +306k (+ 0.07%) 440,880k 442,064k
Parse Time 2.09s (± 0.75%) 2.10s (± 0.58%) +0.01s (+ 0.34%) 2.07s 2.12s
Bind Time 0.69s (± 0.80%) 0.70s (± 0.86%) +0.00s (+ 0.43%) 0.68s 0.70s
Check Time 13.04s (± 0.82%) 13.11s (± 0.85%) +0.08s (+ 0.61%) 12.86s 13.44s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.82s (± 0.72%) 15.91s (± 0.75%) +0.09s (+ 0.57%) 15.63s 16.26s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory10 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v14.15.1, x64)
Benchmark Name Iterations
Current 43527 10
Baseline master 10

Developer Information:

Download Benchmark

@ahejlsberg
Copy link
Member Author

Tests all look good, performance is unaffected.

andrewbranch
andrewbranch previously approved these changes Apr 5, 2021
Copy link
Member

@andrewbranch andrewbranch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

@weswigham
Copy link
Member

which is expected but takes about twice as long as our test timeout limit. For that reason, I've deleted that particular test.

That doesn't seem like a good outcome - a reverse mapped type over something with a pointer to a deep type hierarchy adding 40s to a compilation seems unacceptable to me? I just tested it out - #42485 can bring the runtime of that test down from 27s to 3s. Still not great (3s for a single call on a beefy machine?), but fixes it by an order of magnitude and definitely makes it keepable as a test.

@ahejlsberg
Copy link
Member Author

I'm not sure I understand how #42485 helps. Before the fix in this PR we'd end up hitting the panic limit at 100 recursive invocations and output an Excessive stack depth comparing types... diagnostic, which prints the two types. This happed relatively quickly, but it is nonetheless wrong behavior.

With the PR we keep successfully relating types until we get to 50 levels of instantiations and then stop--but without printing any types, so #42485 wouldn't affect anything. It takes longer for this to occur but that isn't surprising given the very large number of types XMLHpptRequest touches if you recursively iterate over all of its properties.

@weswigham
Copy link
Member

This test (from 7bd6eaf):

let xhr: XMLHttpRequest;
const out2 = foo(xhr);
out2.responseXML
out2.responseXML.activeElement.className.length

you said you removed from this PR because after this PR, it takes an excessive time to typecheck. I can see that - on my machine it typechecks in 27s and issues a (bogus! The tree of possible reverse-mapped types is in fact finite!) error TS2589: Type instantiation is excessively deep and possibly infinite.. If you merge this PR and #42485 (which caches reverse mapped types much better than we do today via two means: 1. actually caching the lazily inferred property types (today we repeat inference on every property lookup!) and 2. identifying that repeated indexing on the template of a reverse mapped type is that same as the base and transforming the type as such as explained in this comment, allowing caching to be shared as inference descends into a tree of types), the erroneous error goes away and typecheck time gets reduced by an order of magnitude.

@andrewbranch andrewbranch dismissed their stale review April 5, 2021 17:41

Discussing perf of deleted test

@ahejlsberg
Copy link
Member Author

@weswigham I thought #42485 was just about fixing type printback, but great that it also improves performance. Let's get it merged before this PR and then we can keep the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Excessive stack depth comparing types 'FlatArray<Arr, ?>' and 'FlatArray<Arr, ?>'" false positive
4 participants