GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Increase type instantiation depth limit by ahejlsberg · Pull Request #45025 · microsoft/TypeScript

Conversation

@ahejlsberg

@ahejlsberg Anders Hejlsberg (ahejlsberg) commented Jul 14, 2021

Copy link
Copy Markdown
Member

This PR increases the type instantiation depth limit from 50 to 500. Resolution of recursive types (such as conditional types and indexed access types) can cause deeply nested invocations in the type instantiation logic of the compiler, which may ultimately cause stack overflows during compilation. For this reason we limit nested invocations of the instantiateType function, reporting a "Type instantiation is excessively deep and possibly infinite" error when the limit is reached. The current limit of 50 is generally reasonable, but in some scenarios involving tuple types and template literal types it is quickly reached. For example, the type

type GetChars<S> = S extends `${infer Char}${infer Rest}` ? Char | GetChars<Rest> : never;

extracts a union of the single characters in a literal string and reaches the instantiation depth limit after just 24 characters (each level of recursion involves two invocations of instantiateType). Likewise, utility types to manipulate tuple types often suffer from the same restrictions. It is sometimes possible to "batch process" multiple constituents at once, as in

type GetChars<S> =
    S extends `${infer C1}${infer C2}${infer C3}${infer C4}${infer Rest}` ? C1 | C2 | C3 | C4 | GetChars<Rest> :
    S extends `${infer C1}${infer Rest}` ? C1 | GetChars<Rest> : never;

but this is cumbersome and often too complex.

Since the instantiation depth limit is a reasonable approximation of call stack depth in the compiler, if we assume each recursive instantiateType call involves 5 stack frames and each stack frame consumes 100 bytes, then 500 levels of recursion roughly corresponds to 250K bytes, which is 25-50% of the default stack size in Node.js. That seems appropriate.

It's been suggested we make the depth limit configurable through a compiler option. I remain opposed to that as it is ultimately an implementation detail of the compiler that very well could change.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dan-dr, SancheZz, kiprasmel, jcalz, colinhacks, alii, ven, zyhou, rearchontis, callmeberzerker, and 5 more reacted with thumbs up emoji olivermrose, k-tten, karol-majewski, Merlin04, anthonyjoeseph, colinhacks, ven, and OliverJAsh reacted with laugh emoji g-plane, lideming, tjjfvi, AnyhowStep, olivermrose, brage-andreas, timvandam, k-tten, SancheZz, treybrisbane, and 11 more reacted with hooray emoji Jack-Works, septs, lideming, tjjfvi, AnyhowStep, brage-andreas, 0kku, k-tten, gogoyqj, tonivj5, and 17 more reacted with heart emoji AnyhowStep, k-tten, tonivj5, Beraliv, Igorbek, Merlin04, c69-addepar, anthonyjoeseph, KisaragiEffective, jcalz, and 5 more reacted with rocket emoji
All reactions
  • 👍 15 reactions
  • 😄 8 reactions
  • 🎉 21 reactions
  • ❤️ 27 reactions
  • 🚀 15 reactions
Anders Hejlsberg (ahejlsberg) added 2 commits July 14, 2021 07:24
@ahejlsberg
Bump instantiation depth limit to 500
16fea3e
@ahejlsberg
Accept new baselines
4f79295
@typescript-bot TypeScript Bot (typescript-bot) assigned Anders Hejlsberg (ahejlsberg) Jul 14, 2021
@typescript-bot TypeScript Bot (typescript-bot) added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jul 14, 2021
@ahejlsberg
Anders Hejlsberg (ahejlsberg) requested review from Daniel Rosenwasser (DanielRosenwasser), Ryan Cavanaugh (RyanCavanaugh) and Wesley Wigham (weswigham) July 14, 2021 14:56
DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) reviewed Jul 14, 2021
View reviewed changes
Comment thread tests/baselines/reference/recursiveConditionalTypes.errors.txt Outdated
@@ -85,8 +84,6 @@ tests/cases/compiler/recursiveConditionalTypes.ts(116,9): error TS2345: Argument
type TT2 = TupleOf<number, number>;
type TT3 = TupleOf<number, any>;
type TT4 = TupleOf<number, 100>; // Depth error

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Jul 14, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The comment in tests/cases/compiler/recursiveConditionalTypes.ts will need to be amended.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Jul 14, 2021

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) pack this
TypeScript Bot (@typescript-bot) test this
TypeScript Bot (@typescript-bot) user test this
TypeScript Bot (@typescript-bot) run dt
TypeScript Bot (@typescript-bot) perf test this

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the extended test suite on this PR at 4f79295. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the perf test suite on this PR at 4f79295. You can monitor the build here.

Update: The results are in!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the tarball bundle task on this PR at 4f79295. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the parallelized community code test suite on this PR at 4f79295. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the parallelized Definitely Typed test suite on this PR at 4f79295. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AnyhowStep

AnyhowStep commented Jul 14, 2021

Copy link
Copy Markdown
Contributor

I love you

colinhacks, alii, ven, thelinuxlich, and strblr reacted with thumbs up emoji DanielRosenwasser, 0kku, dsherret, tonivj5, Merlin04, yozohu, colinhacks, 3jins, and lidaze reacted with laugh emoji vuaaaaaaaaaaax, 0kku, Merlin04, and colinhacks reacted with hooray emoji yozohu, Beraliv, colinhacks, alii, mdkmridul, klesun, and jan-wilhelm reacted with heart emoji
All reactions
  • 👍 5 reactions
  • 😄 9 reactions
  • 🎉 4 reactions
  • ❤️ 7 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 14, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Hey Daniel Rosenwasser (@DanielRosenwasser), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/106764/artifacts?artifactName=tgz&fileId=5C079C6A6740444AA1A534C55FECB56270903505B9A9A29E546161CE9AEA0C6402&fileName=/typescript-4.4.0-insiders.20210714.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot TypeScript Bot (typescript-bot) mentioned this pull request Jul 14, 2021
🤖 User test baselines have changed for increaseInstantiationDepth typescript-bot/TypeScript#192
Open
@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 14, 2021

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jul 14, 2021

Copy link
Copy Markdown
Contributor

Daniel Rosenwasser (@DanielRosenwasser)
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..45025

Metric main 45025 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 343,509k (± 0.03%) 343,514k (± 0.02%) +5k (+ 0.00%) 343,366k 343,714k
Parse Time 1.79s (± 0.45%) 1.80s (± 0.50%) +0.01s (+ 0.39%) 1.78s 1.82s
Bind Time 0.85s (± 1.11%) 0.84s (± 0.66%) -0.01s (- 0.59%) 0.83s 0.86s
Check Time 5.34s (± 0.49%) 5.33s (± 0.56%) -0.01s (- 0.13%) 5.27s 5.39s
Emit Time 5.85s (± 0.53%) 5.81s (± 0.49%) -0.04s (- 0.70%) 5.74s 5.87s
Total Time 13.83s (± 0.36%) 13.78s (± 0.37%) -0.05s (- 0.34%) 13.64s 13.87s
Compiler-Unions - node (v10.16.3, x64)
Memory used 201,233k (± 0.02%) 201,207k (± 0.04%) -26k (- 0.01%) 201,035k 201,388k
Parse Time 0.78s (± 0.90%) 0.78s (± 0.60%) -0.00s (- 0.13%) 0.77s 0.79s
Bind Time 0.52s (± 1.30%) 0.53s (± 1.14%) +0.00s (+ 0.19%) 0.51s 0.54s
Check Time 7.81s (± 0.61%) 7.81s (± 0.65%) +0.00s (+ 0.05%) 7.70s 7.93s
Emit Time 2.45s (± 0.90%) 2.44s (± 0.56%) -0.01s (- 0.49%) 2.41s 2.47s
Total Time 11.57s (± 0.56%) 11.56s (± 0.49%) -0.01s (- 0.09%) 11.41s 11.68s
Monaco - node (v10.16.3, x64)
Memory used 340,460k (± 0.02%) 340,446k (± 0.02%) -14k (- 0.00%) 340,273k 340,624k
Parse Time 1.45s (± 0.60%) 1.46s (± 0.68%) +0.01s (+ 0.41%) 1.43s 1.48s
Bind Time 0.75s (± 0.91%) 0.75s (± 0.53%) +0.00s (+ 0.67%) 0.74s 0.76s
Check Time 5.38s (± 0.57%) 5.35s (± 0.52%) -0.03s (- 0.52%) 5.28s 5.42s
Emit Time 3.15s (± 1.03%) 3.16s (± 1.34%) +0.01s (+ 0.29%) 3.10s 3.27s
Total Time 10.73s (± 0.49%) 10.72s (± 0.54%) -0.01s (- 0.07%) 10.64s 10.86s
TFS - node (v10.16.3, x64)
Memory used 303,771k (± 0.02%) 303,819k (± 0.02%) +48k (+ 0.02%) 303,671k 303,973k
Parse Time 1.18s (± 0.40%) 1.18s (± 0.47%) +0.00s (+ 0.17%) 1.17s 1.20s
Bind Time 0.71s (± 0.69%) 0.71s (± 0.48%) -0.01s (- 0.98%) 0.70s 0.71s
Check Time 4.89s (± 0.33%) 4.88s (± 0.56%) -0.01s (- 0.10%) 4.82s 4.94s
Emit Time 3.33s (± 1.00%) 3.33s (± 1.22%) +0.00s (+ 0.12%) 3.23s 3.40s
Total Time 10.11s (± 0.41%) 10.10s (± 0.61%) -0.01s (- 0.10%) 9.98s 10.21s
material-ui - node (v10.16.3, x64)
Memory used 469,650k (± 0.01%) 469,619k (± 0.02%) -31k (- 0.01%) 469,498k 469,861k
Parse Time 1.73s (± 0.74%) 1.73s (± 0.54%) 0.00s ( 0.00%) 1.70s 1.74s
Bind Time 0.67s (± 0.89%) 0.67s (± 1.29%) +0.01s (+ 0.90%) 0.66s 0.69s
Check Time 14.17s (± 0.49%) 14.16s (± 0.43%) -0.01s (- 0.04%) 14.05s 14.34s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.57s (± 0.46%) 16.56s (± 0.42%) -0.00s (- 0.02%) 16.43s 16.77s
Angular - node (v12.1.0, x64)
Memory used 321,697k (± 0.03%) 321,646k (± 0.02%) -51k (- 0.02%) 321,489k 321,826k
Parse Time 1.78s (± 0.62%) 1.78s (± 0.60%) +0.00s (+ 0.06%) 1.77s 1.81s
Bind Time 0.83s (± 1.02%) 0.82s (± 0.75%) -0.01s (- 0.97%) 0.81s 0.83s
Check Time 5.18s (± 0.49%) 5.18s (± 0.54%) -0.00s (- 0.10%) 5.12s 5.23s
Emit Time 6.03s (± 0.43%) 6.02s (± 0.67%) -0.01s (- 0.20%) 5.95s 6.12s
Total Time 13.83s (± 0.39%) 13.80s (± 0.44%) -0.02s (- 0.15%) 13.68s 13.98s
Compiler-Unions - node (v12.1.0, x64)
Memory used 188,688k (± 0.02%) 188,676k (± 0.09%) -12k (- 0.01%) 188,057k 188,977k
Parse Time 0.78s (± 0.63%) 0.77s (± 0.68%) -0.01s (- 0.90%) 0.76s 0.78s
Bind Time 0.53s (± 0.92%) 0.54s (± 0.92%) +0.00s (+ 0.37%) 0.53s 0.55s
Check Time 7.34s (± 0.79%) 7.32s (± 0.79%) -0.02s (- 0.22%) 7.22s 7.45s
Emit Time 2.42s (± 0.97%) 2.44s (± 0.76%) +0.02s (+ 0.70%) 2.41s 2.49s
Total Time 11.07s (± 0.66%) 11.07s (± 0.60%) -0.00s (- 0.02%) 10.94s 11.18s
Monaco - node (v12.1.0, x64)
Memory used 323,640k (± 0.01%) 323,611k (± 0.02%) -29k (- 0.01%) 323,494k 323,713k
Parse Time 1.42s (± 0.78%) 1.42s (± 0.48%) -0.01s (- 0.49%) 1.40s 1.43s
Bind Time 0.73s (± 0.65%) 0.72s (± 0.80%) -0.01s (- 0.96%) 0.71s 0.74s
Check Time 5.24s (± 0.62%) 5.21s (± 0.26%) -0.03s (- 0.53%) 5.18s 5.25s
Emit Time 3.16s (± 0.61%) 3.17s (± 0.96%) +0.00s (+ 0.16%) 3.13s 3.27s
Total Time 10.55s (± 0.48%) 10.52s (± 0.29%) -0.03s (- 0.31%) 10.47s 10.63s
TFS - node (v12.1.0, x64)
Memory used 288,573k (± 0.02%) 288,541k (± 0.02%) -32k (- 0.01%) 288,395k 288,687k
Parse Time 1.19s (± 0.80%) 1.19s (± 0.63%) -0.01s (- 0.59%) 1.18s 1.21s
Bind Time 0.69s (± 1.09%) 0.70s (± 0.71%) +0.00s (+ 0.14%) 0.69s 0.71s
Check Time 4.81s (± 0.39%) 4.81s (± 0.41%) -0.00s (- 0.02%) 4.76s 4.86s
Emit Time 3.33s (± 0.55%) 3.36s (± 0.53%) +0.03s (+ 0.87%) 3.32s 3.40s
Total Time 10.03s (± 0.29%) 10.05s (± 0.31%) +0.02s (+ 0.20%) 9.97s 10.11s
material-ui - node (v12.1.0, x64)
Memory used 448,306k (± 0.07%) 448,383k (± 0.01%) +78k (+ 0.02%) 448,249k 448,451k
Parse Time 1.72s (± 0.43%) 1.72s (± 0.59%) -0.00s (- 0.06%) 1.70s 1.74s
Bind Time 0.65s (± 0.69%) 0.65s (± 0.72%) +0.00s (+ 0.31%) 0.64s 0.66s
Check Time 12.77s (± 0.95%) 12.75s (± 0.56%) -0.02s (- 0.15%) 12.59s 12.89s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.13s (± 0.79%) 15.12s (± 0.54%) -0.01s (- 0.09%) 14.94s 15.27s
Angular - node (v14.15.1, x64)
Memory used 320,219k (± 0.01%) 320,222k (± 0.01%) +3k (+ 0.00%) 320,166k 320,256k
Parse Time 1.81s (± 0.99%) 1.80s (± 0.74%) -0.01s (- 0.39%) 1.78s 1.83s
Bind Time 0.88s (± 0.57%) 0.87s (± 0.68%) -0.00s (- 0.11%) 0.86s 0.89s
Check Time 5.20s (± 0.57%) 5.19s (± 0.16%) -0.01s (- 0.12%) 5.18s 5.22s
Emit Time 6.16s (± 0.64%) 6.11s (± 0.60%) -0.05s (- 0.80%) 5.98s 6.16s
Total Time 14.04s (± 0.48%) 13.98s (± 0.36%) -0.07s (- 0.47%) 13.82s 14.09s
Compiler-Unions - node (v14.15.1, x64)
Memory used 189,578k (± 0.58%) 188,420k (± 0.69%) -1,158k (- 0.61%) 186,344k 190,583k
Parse Time 0.80s (± 0.61%) 0.80s (± 1.18%) +0.00s (+ 0.00%) 0.79s 0.84s
Bind Time 0.56s (± 0.65%) 0.56s (± 1.10%) -0.00s (- 0.53%) 0.55s 0.58s
Check Time 7.46s (± 0.57%) 7.53s (± 0.48%) +0.07s (+ 0.88%) 7.45s 7.59s
Emit Time 2.42s (± 0.55%) 2.46s (± 1.29%) +0.04s (+ 1.74%) 2.40s 2.53s
Total Time 11.24s (± 0.47%) 11.35s (± 0.36%) +0.11s (+ 0.94%) 11.26s 11.49s
Monaco - node (v14.15.1, x64)
Memory used 322,367k (± 0.01%) 322,364k (± 0.00%) -3k (- 0.00%) 322,342k 322,383k
Parse Time 1.49s (± 0.89%) 1.48s (± 0.71%) -0.01s (- 0.67%) 1.46s 1.51s
Bind Time 0.75s (± 0.69%) 0.75s (± 1.00%) +0.00s (+ 0.40%) 0.74s 0.77s
Check Time 5.20s (± 0.57%) 5.20s (± 0.50%) -0.01s (- 0.15%) 5.15s 5.26s
Emit Time 3.20s (± 0.59%) 3.21s (± 0.70%) +0.01s (+ 0.31%) 3.16s 3.28s
Total Time 10.64s (± 0.32%) 10.64s (± 0.48%) 0.00s ( 0.00%) 10.53s 10.77s
TFS - node (v14.15.1, x64)
Memory used 287,540k (± 0.01%) 287,547k (± 0.01%) +7k (+ 0.00%) 287,499k 287,605k
Parse Time 1.26s (± 1.56%) 1.25s (± 0.75%) -0.01s (- 0.56%) 1.23s 1.27s
Bind Time 0.72s (± 0.80%) 0.72s (± 0.51%) -0.00s (- 0.56%) 0.71s 0.72s
Check Time 4.83s (± 0.51%) 4.86s (± 0.46%) +0.03s (+ 0.54%) 4.82s 4.92s
Emit Time 3.41s (± 0.76%) 3.46s (± 0.90%) +0.05s (+ 1.41%) 3.40s 3.54s
Total Time 10.22s (± 0.48%) 10.29s (± 0.46%) +0.06s (+ 0.62%) 10.21s 10.43s
material-ui - node (v14.15.1, x64)
Memory used 446,768k (± 0.00%) 446,769k (± 0.01%) +1k (+ 0.00%) 446,665k 446,796k
Parse Time 1.76s (± 0.64%) 1.76s (± 0.56%) +0.00s (+ 0.17%) 1.74s 1.78s
Bind Time 0.69s (± 0.65%) 0.69s (± 0.81%) -0.00s (- 0.00%) 0.68s 0.70s
Check Time 12.95s (± 0.70%) 12.90s (± 0.33%) -0.05s (- 0.42%) 12.80s 13.00s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.40s (± 0.56%) 15.35s (± 0.29%) -0.05s (- 0.32%) 15.25s 15.45s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory1 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 45025 10
Baseline main 10

Developer Information:

Download Benchmark

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Jul 14, 2021

Copy link
Copy Markdown
Member Author

Tests and performance are unaffected, as expected. The only possible causes for concern with this change are (1) stack overflows could occur if each recursive invocation of instantiateType consumes more stack space than we have estimated, and (2) because we permit 10x more recursive invocations, it takes longer to report "Type instantiation is excessively deep..." errors, which may make language services less responsive.

AnyhowStep reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Anders Hejlsberg (ahejlsberg) added 2 commits July 14, 2021 13:30
@ahejlsberg
Update tests
62efc71
@ahejlsberg
Accept new baselines
d89a9bc
weswigham
Wesley Wigham (weswigham) approved these changes Jul 14, 2021
View reviewed changes

@weswigham Wesley Wigham (weswigham) left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It's harder to make this number smaller rather than larger, so we really should be sure that we won't stack overflow with 500 in any cases, since adjusting it down if we are is going to be way breakier.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AnyhowStep and MartinJohns reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@jjangga0214

jjangga0214 commented Jul 15, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Thanks for the attention to the issue :)

Wesley Wigham (@weswigham)

It's harder to make this number smaller rather than larger,

I believe this is one of the strengths of configurable depth limit/count. Maintainers would be able to modify the default values progressively, in more freedom without too much worry.

Anders Hejlsberg (@ahejlsberg)

It's been suggested we make the depth limit configurable through a compiler option. I remain opposed to that as it is ultimately an implementation detail of the compiler that very well could change.

I understand that change of implementation detail might require breaking change of configuration.
What about taking some time to think and fix the newly exposed configuration?
I believe, with thorough care, it can be stabilized someday.

So I suggest introducing experimental configuration and stabilizing it later.

500 levels of recursion roughly corresponds to 250K bytes, which is 25-50% of the default stack size in Node.js. That seems appropriate.

This is where configurations resolve uncertainty. When people don't use the default stack size(larger/smaller), they would also naturally want to configure tsc's recursive limit, by their own free decision.

klesun reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jjangga0214

jjangga0214 commented Jul 15, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

MEMO: relation with #34933 and #44997

This issue(#45025) is related to #34933, but does not resolve it. This is because there can be (theoretically) already published (including famous libraries) codes which even the increased limit(500 depth) cannot cover (e.g. needs 505 depth, 570 depth).
To fully resolve this broken ecosystem, the limitations should be configurable(#44997), I believe.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request Jul 19, 2021
Design Meeting Notes, 7/14/2021 #45104
Closed
@orouz orouz mentioned this pull request Aug 11, 2021
Mapped Type + Recursive Type = Type instantiation is excessively deep and possibly infinite (2589) #45411
Closed
@jjangga0214 jjangga0214 mentioned this pull request Aug 14, 2021
feat(compilerOption): add instantiationDepthLimit and instantiationCountLimit #44997
Closed
@sandersn

Nathan Shively-Sanders (sandersn) commented Aug 16, 2021

Copy link
Copy Markdown
Member

Wesley Wigham (@weswigham) Anders Hejlsberg (@ahejlsberg) Now that 4.5 development has started, is this ready to merge, or does the number need more experimentation?

(I'm leaning toward merging given our design meeting discussion.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ahejlsberg
Anders Hejlsberg (ahejlsberg) merged commit 79474fd into main Aug 17, 2021
@ahejlsberg
Anders Hejlsberg (ahejlsberg) deleted the increaseInstantiationDepth branch August 17, 2021 14:00
@colinhacks

Colin McDonnell (colinhacks) commented Aug 18, 2021

Copy link
Copy Markdown
Contributor

AnyhowStep Time to throw the party you've been planning since 2019 😝

alii, Beraliv, and tonivj5 reacted with thumbs up emoji alii and tonivj5 reacted with laugh emoji
All reactions
  • 👍 3 reactions
  • 😄 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@markusylisiurunen Markus Ylisiurunen (markusylisiurunen) mentioned this pull request Aug 20, 2021
TypeScript throwing a "Type instantiation is excessively deep and possibly infinite" error runtypes/runtypes#212
Closed
@adam-thomas-privitar Adam Thomas (adam-thomas-privitar) mentioned this pull request Aug 24, 2021
Chakra does not compile with latest Typescript 4.3.x: Type instantiation is excessively deep chakra-ui/chakra-ui#4226
Closed
@ahejlsberg Anders Hejlsberg (ahejlsberg) mentioned this pull request Sep 3, 2021
Tail recursive evaluation of conditional types #45711
Merged
@sandersn Nathan Shively-Sanders (sandersn) mentioned this pull request Oct 7, 2021
flag to customize type instantiation depth limit #46180
Closed
5 tasks done
@letmaik Maik Riechert (letmaik) mentioned this pull request Oct 19, 2021
Upgrading to 1.6.x causes "Type instantiation is excessively deep and possibly infinite" errors ThomasAribart/json-schema-to-ts#43
Closed
Cassandra Choi (BobobUnicorn) pushed a commit to BobobUnicorn/TypeScript that referenced this pull request Oct 24, 2021
@ahejlsberg @BobobUnicorn
Increase type instantiation depth limit (microsoft#45025)
5f99e87
* Bump instantiation depth limit to 500

* Accept new baselines

* Update tests

* Accept new baselines
@thelinuxlich

Alisson Cavalcante Agiani (thelinuxlich) commented Dec 8, 2022

Copy link
Copy Markdown

What happened to this fix?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thelinuxlich Alisson Cavalcante Agiani (thelinuxlich) mentioned this pull request Dec 8, 2022
With a schema definition of 93 routes, I got "Type instantiation is excessively deep and possibly infinite" ecyrbe/zodios#256
Closed
@Dragon-Hatcher

Dragon-Hatcher commented Jun 24, 2023

Copy link
Copy Markdown

What happened to this fix?

It was reverted in #45711 and was replaced with a tail recursion strategy.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) DanielRosenwasser left review comments
@weswigham Wesley Wigham (weswigham) weswigham approved these changes
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) Awaiting requested review from RyanCavanaugh

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@ahejlsberg Anders Hejlsberg (ahejlsberg)

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

PR Backlog
Archived in project

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@ahejlsberg @DanielRosenwasser @typescript-bot @AnyhowStep @jjangga0214 @sandersn @colinhacks @thelinuxlich @Dragon-Hatcher @weswigham
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.