Skip to content

Mark conditional extends as Unmeasurable and use a conditional-opaque wildcard for type erasure #43887

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

Conversation

weswigham
Copy link
Member

@weswigham weswigham commented Apr 29, 2021

This PR is essentially #41067 + #31277, with a change added on top so it also fixes #43867.

Fixes #43867 (we always now reliably issue the correct error (which is a new thing), rather than just for variance comparisons, as in master)
Fixes #23352 (we now use a wildcard marker for type erasure that is assignable to never, which allows overload resolution to process the overloads as we'd like)
Fixes #31251 (we now force a structural comparison when comparing type parameters which flow into conditional extends clauses (which require identical types))
Fixes #44945

@weswigham
Copy link
Member Author

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 29, 2021

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 29, 2021

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 29, 2021

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 29, 2021

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 29, 2021

Heya @weswigham, I've started to run the tarball bundle task on this PR at fda479e. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Apr 29, 2021

Hey @weswigham, 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/102062/artifacts?artifactName=tgz&fileId=E2E83215DAA92B08C87DEDC30F6EAC2DC20F7CB0CF699168EF9C60E6DB8FDE3302&fileName=/typescript-4.3.0-insiders.20210429.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/pr-build@4.3.0-pr-43887-6".;

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - master..43887

Metric master 43887 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 344,974k (± 0.02%) 344,963k (± 0.02%) -11k (- 0.00%) 344,845k 345,167k
Parse Time 1.92s (± 0.60%) 1.93s (± 0.79%) +0.00s (+ 0.16%) 1.90s 1.96s
Bind Time 0.84s (± 0.40%) 0.84s (± 1.34%) +0.00s (+ 0.12%) 0.82s 0.88s
Check Time 5.24s (± 0.64%) 5.25s (± 0.27%) +0.01s (+ 0.11%) 5.22s 5.28s
Emit Time 5.92s (± 0.65%) 5.91s (± 0.66%) -0.01s (- 0.12%) 5.85s 6.03s
Total Time 13.93s (± 0.42%) 13.93s (± 0.45%) 0.00s ( 0.00%) 13.84s 14.13s
Compiler-Unions - node (v10.16.3, x64)
Memory used 200,621k (± 0.15%) 200,871k (± 0.03%) +251k (+ 0.12%) 200,697k 200,989k
Parse Time 0.79s (± 0.63%) 0.79s (± 1.04%) +0.00s (+ 0.13%) 0.77s 0.81s
Bind Time 0.52s (± 1.18%) 0.52s (± 1.11%) +0.00s (+ 0.38%) 0.51s 0.53s
Check Time 7.57s (± 0.51%) 7.59s (± 0.73%) +0.02s (+ 0.25%) 7.49s 7.70s
Emit Time 2.49s (± 0.76%) 2.52s (± 0.86%) +0.03s (+ 1.20%) 2.48s 2.57s
Total Time 11.36s (± 0.48%) 11.42s (± 0.61%) +0.05s (+ 0.48%) 11.28s 11.56s
Monaco - node (v10.16.3, x64)
Memory used 341,655k (± 0.03%) 341,671k (± 0.01%) +16k (+ 0.00%) 341,611k 341,739k
Parse Time 1.56s (± 0.43%) 1.56s (± 0.67%) 0.00s ( 0.00%) 1.54s 1.58s
Bind Time 0.75s (± 0.78%) 0.75s (± 0.80%) -0.00s (- 0.13%) 0.73s 0.76s
Check Time 5.40s (± 0.43%) 5.39s (± 0.36%) -0.01s (- 0.28%) 5.35s 5.44s
Emit Time 3.03s (± 0.90%) 3.02s (± 0.73%) -0.01s (- 0.40%) 2.98s 3.08s
Total Time 10.74s (± 0.41%) 10.72s (± 0.28%) -0.02s (- 0.23%) 10.65s 10.79s
TFS - node (v10.16.3, x64)
Memory used 304,265k (± 0.02%) 304,235k (± 0.02%) -30k (- 0.01%) 304,118k 304,313k
Parse Time 1.21s (± 0.90%) 1.22s (± 0.37%) +0.01s (+ 0.50%) 1.21s 1.23s
Bind Time 0.71s (± 0.53%) 0.71s (± 1.08%) 0.00s ( 0.00%) 0.69s 0.73s
Check Time 4.79s (± 0.58%) 4.80s (± 0.63%) +0.01s (+ 0.19%) 4.75s 4.87s
Emit Time 3.19s (± 1.27%) 3.17s (± 0.91%) -0.02s (- 0.75%) 3.11s 3.25s
Total Time 9.90s (± 0.52%) 9.89s (± 0.43%) -0.01s (- 0.07%) 9.82s 10.00s
material-ui - node (v10.16.3, x64)
Memory used 474,609k (± 0.02%) 480,381k (± 0.02%) +5,772k (+ 1.22%) 480,100k 480,545k
Parse Time 1.93s (± 0.65%) 1.96s (± 0.54%) +0.02s (+ 1.14%) 1.92s 1.97s
Bind Time 0.65s (± 0.80%) 0.65s (± 1.08%) -0.00s (- 0.00%) 0.64s 0.67s
Check Time 14.70s (± 0.50%) 14.75s (± 0.38%) +0.05s (+ 0.34%) 14.57s 14.88s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 17.29s (± 0.44%) 17.36s (± 0.31%) +0.07s (+ 0.42%) 17.19s 17.48s
Angular - node (v12.1.0, x64)
Memory used 322,532k (± 0.01%) 322,573k (± 0.04%) +41k (+ 0.01%) 322,330k 322,814k
Parse Time 1.91s (± 0.75%) 1.91s (± 0.65%) +0.00s (+ 0.05%) 1.89s 1.94s
Bind Time 0.82s (± 0.54%) 0.83s (± 0.99%) +0.01s (+ 1.10%) 0.81s 0.84s
Check Time 5.15s (± 0.44%) 5.15s (± 0.35%) -0.01s (- 0.16%) 5.11s 5.18s
Emit Time 6.13s (± 0.35%) 6.16s (± 0.82%) +0.03s (+ 0.47%) 6.05s 6.26s
Total Time 14.02s (± 0.29%) 14.04s (± 0.53%) +0.02s (+ 0.17%) 13.90s 14.18s
Compiler-Unions - node (v12.1.0, x64)
Memory used 187,952k (± 0.13%) 188,101k (± 0.14%) +150k (+ 0.08%) 187,662k 188,567k
Parse Time 0.77s (± 0.80%) 0.77s (± 0.77%) +0.01s (+ 0.65%) 0.76s 0.78s
Bind Time 0.53s (± 2.16%) 0.53s (± 0.98%) +0.00s (+ 0.19%) 0.52s 0.54s
Check Time 7.02s (± 0.57%) 7.06s (± 0.59%) +0.04s (+ 0.63%) 6.99s 7.17s
Emit Time 2.48s (± 1.63%) 2.50s (± 1.09%) +0.02s (+ 0.89%) 2.44s 2.57s
Total Time 10.80s (± 0.45%) 10.87s (± 0.54%) +0.06s (+ 0.60%) 10.70s 11.00s
Monaco - node (v12.1.0, x64)
Memory used 324,061k (± 0.02%) 324,000k (± 0.02%) -61k (- 0.02%) 323,912k 324,164k
Parse Time 1.54s (± 1.11%) 1.54s (± 0.89%) -0.00s (- 0.13%) 1.51s 1.57s
Bind Time 0.72s (± 0.72%) 0.72s (± 0.62%) +0.00s (+ 0.42%) 0.71s 0.73s
Check Time 5.20s (± 0.65%) 5.20s (± 0.37%) +0.00s (+ 0.02%) 5.16s 5.24s
Emit Time 3.05s (± 0.41%) 3.07s (± 0.84%) +0.02s (+ 0.66%) 3.02s 3.13s
Total Time 10.51s (± 0.47%) 10.53s (± 0.38%) +0.02s (+ 0.18%) 10.45s 10.63s
TFS - node (v12.1.0, x64)
Memory used 288,656k (± 0.03%) 288,789k (± 0.03%) +134k (+ 0.05%) 288,673k 289,139k
Parse Time 1.21s (± 0.55%) 1.22s (± 0.77%) +0.01s (+ 0.83%) 1.21s 1.25s
Bind Time 0.69s (± 0.94%) 0.69s (± 0.48%) -0.00s (- 0.29%) 0.68s 0.70s
Check Time 4.71s (± 0.54%) 4.73s (± 0.55%) +0.02s (+ 0.32%) 4.67s 4.81s
Emit Time 3.19s (± 1.02%) 3.20s (± 1.32%) +0.02s (+ 0.47%) 3.10s 3.30s
Total Time 9.80s (± 0.56%) 9.83s (± 0.64%) +0.04s (+ 0.37%) 9.72s 9.99s
material-ui - node (v12.1.0, x64)
Memory used 452,227k (± 0.09%) 458,414k (± 0.01%) +6,187k (+ 1.37%) 458,290k 458,529k
Parse Time 1.94s (± 0.35%) 1.96s (± 0.28%) +0.01s (+ 0.72%) 1.95s 1.97s
Bind Time 0.64s (± 0.69%) 0.64s (± 0.87%) 0.00s ( 0.00%) 0.63s 0.65s
Check Time 13.31s (± 0.72%) 13.36s (± 0.54%) +0.05s (+ 0.37%) 13.16s 13.58s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.90s (± 0.63%) 15.96s (± 0.46%) +0.07s (+ 0.41%) 15.75s 16.18s
Angular - node (v14.15.1, x64)
Memory used 321,277k (± 0.01%) 321,265k (± 0.01%) -12k (- 0.00%) 321,222k 321,292k
Parse Time 1.91s (± 0.43%) 1.92s (± 0.51%) +0.01s (+ 0.63%) 1.90s 1.95s
Bind Time 0.86s (± 0.69%) 0.87s (± 0.94%) +0.01s (+ 0.69%) 0.85s 0.89s
Check Time 5.14s (± 0.49%) 5.16s (± 0.38%) +0.02s (+ 0.39%) 5.12s 5.20s
Emit Time 6.21s (± 0.71%) 6.25s (± 0.97%) +0.03s (+ 0.48%) 6.18s 6.43s
Total Time 14.13s (± 0.41%) 14.19s (± 0.51%) +0.07s (+ 0.47%) 14.09s 14.42s
Compiler-Unions - node (v14.15.1, x64)
Memory used 189,140k (± 0.57%) 189,255k (± 0.57%) +114k (+ 0.06%) 187,011k 190,241k
Parse Time 0.81s (± 0.74%) 0.81s (± 1.11%) 0.00s ( 0.00%) 0.79s 0.83s
Bind Time 0.56s (± 0.65%) 0.56s (± 0.67%) -0.00s (- 0.18%) 0.55s 0.56s
Check Time 7.16s (± 0.60%) 7.19s (± 0.65%) +0.03s (+ 0.47%) 7.10s 7.30s
Emit Time 2.49s (± 0.82%) 2.53s (± 1.21%) +0.03s (+ 1.24%) 2.45s 2.61s
Total Time 11.02s (± 0.37%) 11.08s (± 0.58%) +0.07s (+ 0.61%) 10.91s 11.21s
Monaco - node (v14.15.1, x64)
Memory used 323,125k (± 0.00%) 323,146k (± 0.01%) +20k (+ 0.01%) 323,113k 323,193k
Parse Time 1.57s (± 0.89%) 1.58s (± 0.43%) +0.01s (+ 0.45%) 1.56s 1.59s
Bind Time 0.75s (± 0.91%) 0.75s (± 0.89%) +0.00s (+ 0.54%) 0.74s 0.77s
Check Time 5.19s (± 0.67%) 5.20s (± 0.70%) +0.01s (+ 0.25%) 5.10s 5.26s
Emit Time 3.12s (± 0.50%) 3.13s (± 0.71%) +0.02s (+ 0.55%) 3.10s 3.20s
Total Time 10.62s (± 0.44%) 10.66s (± 0.46%) +0.04s (+ 0.39%) 10.51s 10.74s
TFS - node (v14.15.1, x64)
Memory used 287,642k (± 0.01%) 287,646k (± 0.01%) +4k (+ 0.00%) 287,593k 287,714k
Parse Time 1.27s (± 0.80%) 1.27s (± 1.94%) +0.00s (+ 0.24%) 1.25s 1.37s
Bind Time 0.71s (± 0.84%) 0.72s (± 0.56%) +0.00s (+ 0.56%) 0.71s 0.73s
Check Time 4.73s (± 0.66%) 4.73s (± 0.72%) -0.01s (- 0.15%) 4.65s 4.81s
Emit Time 3.28s (± 0.57%) 3.29s (± 0.55%) +0.00s (+ 0.15%) 3.24s 3.33s
Total Time 10.00s (± 0.42%) 10.00s (± 0.36%) +0.00s (+ 0.03%) 9.95s 10.12s
material-ui - node (v14.15.1, x64)
Memory used 450,544k (± 0.06%) 456,221k (± 0.06%) +5,677k (+ 1.26%) 455,097k 456,379k
Parse Time 1.98s (± 0.77%) 1.99s (± 0.76%) +0.01s (+ 0.40%) 1.96s 2.02s
Bind Time 0.70s (± 0.64%) 0.70s (± 0.71%) -0.00s (- 0.29%) 0.69s 0.71s
Check Time 13.53s (± 0.66%) 13.49s (± 0.85%) -0.04s (- 0.30%) 13.32s 13.87s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.22s (± 0.59%) 16.18s (± 0.68%) -0.04s (- 0.22%) 16.02s 16.54s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory8 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 43887 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.

@@ -13788,7 +13791,10 @@ namespace ts {
const includes = addTypesToUnion(typeSet, 0, types);
if (unionReduction !== UnionReduction.None) {
if (includes & TypeFlags.AnyOrUnknown) {
return includes & TypeFlags.Any ? includes & TypeFlags.IncludesWildcard ? wildcardType : anyType : unknownType;
// A wildcard has the _lowest_ type id, as it's first types created, and it's made in priority order
// - a normal `wildcardType` should take priority over an `opaqueWildcardType` if both somehoe end up
Copy link
Collaborator

Choose a reason for hiding this comment

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

somehow* end up

@@ -13629,7 +13632,7 @@ namespace ts {
if (!(flags & TypeFlags.Never)) {
includes |= flags & TypeFlags.IncludesMask;
if (flags & TypeFlags.StructuredOrInstantiable) includes |= TypeFlags.IncludesStructuredOrInstantiable;
if (type === wildcardType) includes |= TypeFlags.IncludesWildcard;
if (type === wildcardType || type === opaqueWildcardType) includes |= TypeFlags.IncludesWildcard;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this also set the IncludesOpaqueWildcard like the statements abit below?

Copy link
Member Author

Choose a reason for hiding this comment

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

It probably can. I was originally trying to avoid adding an extra includes flag, which, for unions, was possible by exploiting the sort order of the result set; however intersections are unsorted, so I had to add a flag to handle it there.

@jack-williams
Copy link
Collaborator

If I read the build correctly then DT has no issues?

Are the diff's for fp-ts in the user tests a result of this change? There are some new errors related to overload resolution which seems to be a touch point for this change. The previous output was a GC dump so I don't have a good sense about whether this change is going to cause any troubles.

From the POV of fixing #31251 I think this looks good. I don't understand the full implications of the change to overload resolution but the diff in subtypingWithConstructSignatures2.ts looks good, as an example.

@sandersn
Copy link
Member

sandersn commented Jun 1, 2022

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.

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
5 participants