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 — Use couldContainTypeVariables to short-circuit instantiateType by amcasey · Pull Request #36951 · microsoft/TypeScript

Conversation

@amcasey

@amcasey Andrew Casey (amcasey) commented Feb 21, 2020

Copy link
Copy Markdown
Member

This is particularly impactful for large unions of string literals.

Sorry, something went wrong.

Uh oh!

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

All reactions
@amcasey
Use couldContainTypeVariables to short-circuit instantiateType
a13b9c5
This is particularly impactful for large unions of string literals.
@amcasey
Andrew Casey (amcasey) requested review from Daniel Rosenwasser (DanielRosenwasser), Anders Hejlsberg (ahejlsberg) and Wesley Wigham (weswigham) February 21, 2020 23:15
@amcasey

Andrew Casey (amcasey) commented Feb 21, 2020

Copy link
Copy Markdown
Member Author

The check could be lifted out to instantiateType to short-circuit the whole call to instantiateTypeWorker, but that was about 1% slower when I ran the material-ui benchmark. Of course, 1% might be worth it for clearer code. Thoughts?

All reactions

Sorry, something went wrong.

Uh oh!

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

@amcasey

Andrew Casey (amcasey) commented Feb 21, 2020

Copy link
Copy Markdown
Member Author

Not running the perf test since only unions and intersections are affected.

All reactions

Sorry, something went wrong.

Uh oh!

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

@amcasey

Andrew Casey (amcasey) commented Feb 21, 2020

Copy link
Copy Markdown
Member Author

I intentionally made this a very narrow change. If we wanted to go broader, we could have instantiateType and couldContainTypeVariable share their tree walks (probably by having instantiateType also return whether it encountered a type variable). If we wanted to go really nuts, it could also indicate whether the instantiated type contains type variables. Thoughts?

All reactions

Sorry, something went wrong.

Uh oh!

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

weswigham
Wesley Wigham (weswigham) approved these changes Feb 22, 2020
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.

Considering we already have the same check in the flags & Object + objectFlags & ObjectFlags.Anonymous case, adding this check seems fine. We can at least start with this and iterate if we need to.

Sorry, something went wrong.

Uh oh!

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

All reactions
@amcasey

Andrew Casey (amcasey) commented Feb 22, 2020

Copy link
Copy Markdown
Member Author

Wesley Wigham (@weswigham) I was surprised that the value didn't seem to be cached in that case. I think it will be as of #36947.

All reactions

Sorry, something went wrong.

Uh oh!

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

@amcasey
Andrew Casey (amcasey) merged commit 865c120 into microsoft:master Feb 25, 2020
@amcasey
Andrew Casey (amcasey) deleted the InstantiateCouldContain branch February 25, 2020 01:50
@weswigham Wesley Wigham (weswigham) mentioned this pull request Apr 7, 2020
"Type instantiation is excessively deep and possibly infinite." for big keyof types #35493
Closed
@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

@weswigham Wesley Wigham (weswigham) weswigham approved these changes
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Awaiting requested review from DanielRosenwasser
@ahejlsberg Anders Hejlsberg (ahejlsberg) Awaiting requested review from ahejlsberg

Uh oh!

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

Assignees

No one assigned

Labels

None yet

Projects

None yet

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.

2 participants

@amcasey @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.