Skip to content

Erase type parameters to a type which behaves as never in a union and unknown in an intersection or any otherwise #39217

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

Closed
wants to merge 2 commits into from

Conversation

weswigham
Copy link
Member

This has the effect of omitting the parameters from inference calculations, without subsuming that data provided by the other members of the union/intersection.

Fixes #39080

@weswigham
Copy link
Member Author

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 23, 2020

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 23, 2020

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 23, 2020

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 23, 2020

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

@@ -1,3 +1,6 @@
tests/cases/compiler/immutable.ts(189,20): error TS2430: Interface 'Stack<T>' incorrectly extends interface 'Indexed<T>'.
The types returned by 'concat(...).map(...).filter(...)' are incompatible between these types.
Type 'Set<any>' is not assignable to type 'Indexed<any>'.
Copy link
Member Author

Choose a reason for hiding this comment

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

This is just a new follow-on error to the existing errors below, I believe, as the incorrect extensions below make Set and Indexed incompatible with one another, which is now properly reported here (as we now no longer fully erase all the data in the signature and can keep comparing until we get to that point).

@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

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

Here they are:

Comparison Report - master..39217

Metric master 39217 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 340,586k (± 0.02%) 340,020k (± 0.03%) -566k (- 0.17%) 339,799k 340,270k
Parse Time 1.99s (± 0.62%) 1.99s (± 0.50%) +0.00s (+ 0.10%) 1.97s 2.02s
Bind Time 0.80s (± 0.62%) 0.80s (± 0.88%) +0.00s (+ 0.38%) 0.78s 0.81s
Check Time 4.73s (± 0.39%) 4.73s (± 0.78%) -0.00s (- 0.06%) 4.64s 4.85s
Emit Time 5.17s (± 0.55%) 5.18s (± 0.58%) +0.01s (+ 0.19%) 5.12s 5.26s
Total Time 12.69s (± 0.35%) 12.69s (± 0.47%) +0.01s (+ 0.04%) 12.61s 12.90s
Monaco - node (v10.16.3, x64)
Memory used 338,970k (± 0.02%) 338,967k (± 0.02%) -3k (- 0.00%) 338,871k 339,151k
Parse Time 1.59s (± 0.58%) 1.58s (± 0.81%) -0.01s (- 0.63%) 1.55s 1.61s
Bind Time 0.70s (± 0.71%) 0.69s (± 0.52%) -0.00s (- 0.29%) 0.69s 0.70s
Check Time 4.84s (± 0.18%) 4.87s (± 0.52%) +0.04s (+ 0.72%) 4.81s 4.93s
Emit Time 2.74s (± 0.59%) 2.74s (± 0.50%) +0.01s (+ 0.29%) 2.72s 2.79s
Total Time 9.86s (± 0.30%) 9.89s (± 0.35%) +0.03s (+ 0.33%) 9.80s 9.95s
TFS - node (v10.16.3, x64)
Memory used 301,941k (± 0.01%) 301,947k (± 0.03%) +5k (+ 0.00%) 301,697k 302,096k
Parse Time 1.21s (± 0.67%) 1.21s (± 0.84%) -0.00s (- 0.16%) 1.19s 1.23s
Bind Time 0.65s (± 1.02%) 0.66s (± 0.52%) +0.01s (+ 1.08%) 0.65s 0.66s
Check Time 4.35s (± 0.52%) 4.36s (± 0.40%) +0.01s (+ 0.21%) 4.33s 4.42s
Emit Time 2.89s (± 0.65%) 2.90s (± 1.05%) +0.01s (+ 0.52%) 2.82s 2.98s
Total Time 9.10s (± 0.29%) 9.13s (± 0.39%) +0.03s (+ 0.34%) 9.04s 9.23s
material-ui - node (v10.16.3, x64)
Memory used 459,747k (± 0.02%) 459,586k (± 0.01%) -161k (- 0.03%) 459,492k 459,670k
Parse Time 2.05s (± 0.63%) 2.04s (± 0.73%) -0.01s (- 0.39%) 2.02s 2.08s
Bind Time 0.66s (± 0.91%) 0.66s (± 1.02%) +0.00s (+ 0.15%) 0.64s 0.67s
Check Time 12.79s (± 0.40%) 12.88s (± 0.81%) +0.09s (+ 0.70%) 12.72s 13.09s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.49s (± 0.37%) 15.58s (± 0.69%) +0.09s (+ 0.57%) 15.44s 15.82s
Angular - node (v12.1.0, x64)
Memory used 317,986k (± 0.03%) 317,523k (± 0.02%) -463k (- 0.15%) 317,393k 317,688k
Parse Time 1.97s (± 0.61%) 1.97s (± 0.84%) +0.00s (+ 0.10%) 1.94s 2.02s
Bind Time 0.78s (± 0.64%) 0.79s (± 0.63%) +0.01s (+ 1.29%) 0.78s 0.80s
Check Time 4.61s (± 0.56%) 4.63s (± 0.67%) +0.02s (+ 0.41%) 4.57s 4.71s
Emit Time 5.34s (± 0.41%) 5.40s (± 0.84%) +0.06s (+ 1.11%) 5.28s 5.48s
Total Time 12.69s (± 0.32%) 12.78s (± 0.49%) +0.09s (+ 0.68%) 12.62s 12.92s
Monaco - node (v12.1.0, x64)
Memory used 321,539k (± 0.02%) 321,507k (± 0.02%) -32k (- 0.01%) 321,404k 321,648k
Parse Time 1.54s (± 0.73%) 1.55s (± 0.94%) +0.01s (+ 0.45%) 1.51s 1.57s
Bind Time 0.68s (± 1.20%) 0.68s (± 0.73%) -0.01s (- 1.02%) 0.67s 0.69s
Check Time 4.67s (± 0.56%) 4.67s (± 0.65%) +0.00s (+ 0.09%) 4.62s 4.72s
Emit Time 2.80s (± 0.56%) 2.82s (± 0.60%) +0.01s (+ 0.50%) 2.78s 2.86s
Total Time 9.69s (± 0.34%) 9.71s (± 0.41%) +0.02s (+ 0.23%) 9.63s 9.78s
TFS - node (v12.1.0, x64)
Memory used 286,405k (± 0.02%) 286,429k (± 0.02%) +24k (+ 0.01%) 286,297k 286,537k
Parse Time 1.23s (± 0.94%) 1.24s (± 0.86%) +0.00s (+ 0.16%) 1.22s 1.26s
Bind Time 0.62s (± 1.09%) 0.63s (± 1.09%) +0.00s (+ 0.32%) 0.61s 0.64s
Check Time 4.27s (± 0.46%) 4.28s (± 0.69%) +0.01s (+ 0.35%) 4.20s 4.33s
Emit Time 2.92s (± 0.70%) 2.91s (± 0.76%) -0.00s (- 0.17%) 2.85s 2.97s
Total Time 9.04s (± 0.36%) 9.05s (± 0.51%) +0.02s (+ 0.18%) 8.95s 9.18s
material-ui - node (v12.1.0, x64)
Memory used 437,916k (± 0.07%) 438,056k (± 0.01%) +140k (+ 0.03%) 437,935k 438,224k
Parse Time 2.03s (± 0.57%) 2.04s (± 0.51%) +0.00s (+ 0.20%) 2.02s 2.06s
Bind Time 0.63s (± 0.78%) 0.64s (± 0.93%) +0.00s (+ 0.32%) 0.62s 0.65s
Check Time 11.66s (± 1.04%) 11.61s (± 1.08%) -0.05s (- 0.43%) 11.38s 11.91s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 14.33s (± 0.86%) 14.29s (± 0.91%) -0.04s (- 0.30%) 14.05s 14.59s
Angular - node (v8.9.0, x64)
Memory used 337,048k (± 0.02%) 336,648k (± 0.02%) -401k (- 0.12%) 336,531k 336,814k
Parse Time 2.51s (± 0.33%) 2.50s (± 0.49%) -0.00s (- 0.20%) 2.48s 2.53s
Bind Time 0.83s (± 0.90%) 0.83s (± 0.67%) -0.00s (- 0.12%) 0.82s 0.84s
Check Time 5.33s (± 0.38%) 5.38s (± 0.60%) +0.05s (+ 0.90%) 5.29s 5.44s
Emit Time 5.92s (± 0.97%) 5.92s (± 1.44%) +0.00s (+ 0.07%) 5.64s 6.11s
Total Time 14.59s (± 0.40%) 14.63s (± 0.61%) +0.04s (+ 0.29%) 14.38s 14.83s
Monaco - node (v8.9.0, x64)
Memory used 340,387k (± 0.01%) 340,404k (± 0.01%) +16k (+ 0.00%) 340,327k 340,485k
Parse Time 1.87s (± 0.35%) 1.86s (± 0.59%) -0.01s (- 0.32%) 1.84s 1.88s
Bind Time 0.87s (± 0.71%) 0.87s (± 0.60%) 0.00s ( 0.00%) 0.86s 0.88s
Check Time 5.36s (± 0.45%) 5.37s (± 0.32%) +0.02s (+ 0.32%) 5.33s 5.41s
Emit Time 3.20s (± 0.59%) 3.21s (± 0.48%) +0.01s (+ 0.28%) 3.18s 3.25s
Total Time 11.29s (± 0.28%) 11.32s (± 0.32%) +0.02s (+ 0.19%) 11.22s 11.41s
TFS - node (v8.9.0, x64)
Memory used 303,713k (± 0.01%) 303,705k (± 0.01%) -8k (- 0.00%) 303,643k 303,769k
Parse Time 1.53s (± 0.36%) 1.53s (± 0.39%) +0.00s (+ 0.20%) 1.52s 1.55s
Bind Time 0.65s (± 1.08%) 0.66s (± 0.91%) +0.01s (+ 0.77%) 0.64s 0.67s
Check Time 5.00s (± 1.60%) 5.07s (± 1.55%) +0.07s (+ 1.40%) 4.86s 5.22s
Emit Time 3.07s (± 3.17%) 2.98s (± 2.69%) -0.09s (- 2.99%) 2.89s 3.15s
Total Time 10.26s (± 0.37%) 10.24s (± 0.57%) -0.01s (- 0.15%) 10.13s 10.40s
material-ui - node (v8.9.0, x64)
Memory used 463,976k (± 0.01%) 463,763k (± 0.01%) -213k (- 0.05%) 463,630k 463,846k
Parse Time 2.40s (± 0.40%) 2.39s (± 0.53%) -0.00s (- 0.17%) 2.36s 2.42s
Bind Time 0.78s (± 0.95%) 0.77s (± 1.37%) -0.01s (- 1.67%) 0.75s 0.80s
Check Time 17.15s (± 0.70%) 17.09s (± 0.83%) -0.07s (- 0.40%) 16.72s 17.41s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 20.33s (± 0.59%) 20.25s (± 0.73%) -0.08s (- 0.41%) 19.86s 20.60s
Angular - node (v8.9.0, x86)
Memory used 193,530k (± 0.02%) 193,336k (± 0.03%) -194k (- 0.10%) 193,226k 193,503k
Parse Time 2.42s (± 0.70%) 2.43s (± 0.74%) +0.00s (+ 0.08%) 2.39s 2.46s
Bind Time 0.97s (± 1.41%) 0.97s (± 0.51%) -0.00s (- 0.21%) 0.96s 0.98s
Check Time 4.80s (± 0.54%) 4.80s (± 0.57%) +0.00s (+ 0.06%) 4.76s 4.87s
Emit Time 5.92s (± 1.33%) 5.95s (± 0.95%) +0.04s (+ 0.59%) 5.86s 6.16s
Total Time 14.11s (± 0.58%) 14.15s (± 0.39%) +0.04s (+ 0.26%) 14.08s 14.32s
Monaco - node (v8.9.0, x86)
Memory used 193,380k (± 0.02%) 193,434k (± 0.02%) +53k (+ 0.03%) 193,309k 193,525k
Parse Time 1.90s (± 0.54%) 1.91s (± 0.85%) +0.01s (+ 0.47%) 1.88s 1.96s
Bind Time 0.69s (± 0.72%) 0.69s (± 0.58%) +0.00s (+ 0.44%) 0.68s 0.70s
Check Time 5.45s (± 0.49%) 5.50s (± 0.60%) +0.05s (+ 0.88%) 5.41s 5.55s
Emit Time 2.67s (± 0.70%) 2.66s (± 0.47%) -0.01s (- 0.26%) 2.64s 2.70s
Total Time 10.71s (± 0.37%) 10.76s (± 0.45%) +0.06s (+ 0.54%) 10.62s 10.87s
TFS - node (v8.9.0, x86)
Memory used 173,669k (± 0.02%) 173,695k (± 0.03%) +26k (+ 0.01%) 173,566k 173,845k
Parse Time 1.58s (± 0.76%) 1.59s (± 2.50%) +0.01s (+ 0.63%) 1.55s 1.74s
Bind Time 0.63s (± 0.80%) 0.62s (± 1.04%) -0.00s (- 0.48%) 0.61s 0.64s
Check Time 4.67s (± 0.92%) 4.66s (± 0.57%) -0.01s (- 0.28%) 4.60s 4.70s
Emit Time 2.79s (± 1.06%) 2.79s (± 1.11%) +0.00s (+ 0.14%) 2.73s 2.85s
Total Time 9.66s (± 0.73%) 9.66s (± 0.82%) -0.00s (- 0.02%) 9.53s 9.89s
material-ui - node (v8.9.0, x86)
Memory used 262,717k (± 0.03%) 262,610k (± 0.02%) -108k (- 0.04%) 262,540k 262,691k
Parse Time 2.44s (± 0.52%) 2.45s (± 0.75%) +0.01s (+ 0.29%) 2.41s 2.50s
Bind Time 0.66s (± 0.87%) 0.66s (± 1.43%) +0.00s (+ 0.61%) 0.65s 0.69s
Check Time 15.61s (± 0.54%) 15.64s (± 0.60%) +0.03s (+ 0.20%) 15.49s 15.93s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 18.71s (± 0.42%) 18.75s (± 0.52%) +0.04s (+ 0.22%) 18.61s 19.04s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-166-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 (v8.9.0, x64)
  • node (v8.9.0, x86)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v8.9.0, x64)
  • Angular - node (v8.9.0, x86)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v8.9.0, x64)
  • Monaco - node (v8.9.0, x86)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v8.9.0, x64)
  • TFS - node (v8.9.0, x86)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v8.9.0, x64)
  • material-ui - node (v8.9.0, x86)
Benchmark Name Iterations
Current 39217 10
Baseline master 10

@weswigham
Copy link
Member Author

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 24, 2020

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 24, 2020

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 24, 2020

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

Copy link
Member

@ahejlsberg ahejlsberg left a comment

Choose a reason for hiding this comment

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

Would we need this PR if we merge #31029?

@@ -700,6 +700,7 @@ namespace ts {
const anyType = createIntrinsicType(TypeFlags.Any, "any");
const autoType = createIntrinsicType(TypeFlags.Any, "any");
const wildcardType = createIntrinsicType(TypeFlags.Any, "any");
const erasedType = createIntrinsicType(TypeFlags.Any | TypeFlags.Never | TypeFlags.Unknown, "any");
Copy link
Member

Choose a reason for hiding this comment

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

Wow, a schizophrenic type. We have an implicit assumption everywhere that only one of these flags will be set--with a few exceptions such as TypeFlags.EnumLiteral. Are you confident there are no places we'll get confused by all three being set in this type? Tests for these now become order dependent.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I'm literally abusing the order dependence of handling each of these to avoid special-casing the handling of this type in most type construction places (partially because we're essentially out of normal type flags). Generally speaking we handle Any, then Never, then Unknown (if we handle both), so it's OK, since this marker is mostly any-like (except in unions/intersections, where we handle unknown or never, and then any, which is what causes the desirable vaporization in both structures). At the start, I also wanted to add ObjectFlags.NonInferrableType to it, but that has the side effect of cases like <T extends T[]>() => T where we currently infer any[] becoming unknown. I don't think any[] is great (it injects any into the program without the user ever explicitly writing it, and it's not an noImplicitAny error!), but unknown isn't really much better. I think the ideal would be unknown[] - but that relies on knowing that T[] is covariant on T... I guess since we use getVariances in inference already, that should be safe. So In theory I could get what I want by mapping this erased type to unknown in covariant positions and never in contravariant positions, when it persists into the constructed type (rather than just vaporizing in a union or intersection and letting it persist beyond that as a psuedo-any). I could also make this a special type parameter, and handle all this with a special instantiator that tracks some context of the instantiation - in fact, to do the variance bit, I probably need to.

@weswigham
Copy link
Member Author

Would we need this PR if we merge #31029?

I think #31029 would fixup some of the issues I have with marking the erasedType as it currently stands as ObjectFlags.NonInferrableType (as getBaseSignature would no longer erase to any in constraints as often), but wouldn't solve the root issue here, since that issue is that getErasedSignature is

  1. Used for instantiating a signature in the context of another via inferFromSignatures, and
  2. Erases to any, which deletes information which could still be useful to inference.

@sandersn sandersn assigned ahejlsberg and unassigned weswigham Sep 4, 2020
@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Sep 4, 2020
@sandersn
Copy link
Member

sandersn commented Sep 4, 2020

@ahejlsberg is @weswigham's explanation of erasedType convincing enough to take this PR?

@sandersn
Copy link
Member

Unfortunately, we never finished reviewing this PR. It is pretty old now, so I'm going to close it to reduce the number of open PRs.

@sandersn sandersn closed this May 24, 2022
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
Archived in project
Development

Successfully merging this pull request may close these issues.

Generic argument inference no longer working for specific case
4 participants