Skip to content

Support custom 'Symbol.hasInstance' methods when narrowing 'instanceof' #55052

New issue

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

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

Already on GitHub? # to your account

Merged
merged 15 commits into from
Sep 29, 2023

Conversation

rbuckton
Copy link
Member

@rbuckton rbuckton commented Jul 17, 2023

This makes our instanceof narrowing more closely align to Steps 2-3 of the InstanceofOperator algorithm in the ECMA-262 specification by allowing any object type in the right-hand side of instanceof as long as it has a valid [Symbol.hasInstance] method. If such a method exists and returns a type predicate, that predicate can then be used when narrowing instanceof.

interface Point { x: number, y: number };

const Point = {
  create(x: number, y: number): Point {
    return { x, y };
  },
  [Symbol.hasInstance](value: unknown): value is Point {
    return typeof value === "object" && value !== null &&
      "x" in value && typeof (value as Point).x === "number" &&
      "y" in value && typeof (value as Point).y === "number";
  }
};

interface Line { ... }

declare const p: Point | Line;
if (p instanceof Point) {
  p; // Point
} else {
  p; // Line
}

For a [Symbol.hasInstance] method to be considered during instanceof narrowing, it must have a type predicate as its return type.

In addition, when the left-hand side of instanceof is considered as an argument to [Symbol.hasInstance], it must be assignable to the first parameter. This does not, however, weaken our current requirement that the left-hand side be an object type (or a union containing an object type), despite the fact this is not currently a requirement of ECMAScript.

This is intended to address rather complicated workarounds employed by, for example, engine262 which uses [Symbol.hasInstance] as a runtime type guard, but needed to introduce a non-creatable abstract class so that TypeScript would understand the type guard: https://github.com/engine262/engine262/blob/435e533f8bb2f66961e3c16fe67150a0bba745bb/src/completion.mts#L70

Fixes #17360
Fixes #39064
Related #32080
Related #52670

NOTE: This will need to wait for 5.3 at the earliest.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jul 17, 2023
@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

@rbuckton rbuckton marked this pull request as ready for review July 17, 2023 22:12
@rbuckton rbuckton changed the title [WIP] Support custom 'Symbol.hasInstance' methods when narrowing 'instanceof' Support custom 'Symbol.hasInstance' methods when narrowing 'instanceof' Jul 17, 2023
@gabritto
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

Hey @gabritto, 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/155911/artifacts?artifactName=tgz&fileId=97BAAB5AACB42F8DDA14CB27D0D6B4CD5415D110CC5CD3B416AD60372D09BDEC02&fileName=/typescript-5.2.0-insiders.20230718.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@5.2.0-pr-55052-3".;

@rbuckton
Copy link
Member Author

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

Heya @rbuckton, I've started to run the diff-based user code test suite on this PR at 6a4f838. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 18, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@rbuckton Here are the results of running the user test suite comparing main and refs/pull/55052/merge:

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Unknown failure"
  • 1 instance of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

rxjs-src

/mnt/ts_downloads/rxjs-src/build.sh

  • [NEW] error TS2428: All declarations of 'WeakMap' must have identical type parameters.
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-55052/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
  • [MISSING] error TS2428: All declarations of 'WeakMap' must have identical type parameters.
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)

@typescript-bot
Copy link
Collaborator

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

Here they are:

Compiler

Comparison Report - main..55052
Metric main 55052 Delta Best Worst p-value
Angular - node (v18.10.0, x64)
Memory used 366,844k (± 0.01%) 366,878k (± 0.01%) ~ 366,829k 366,937k p=0.093 n=6
Parse Time 3.38s (± 0.46%) 3.40s (± 1.11%) ~ 3.35s 3.46s p=0.294 n=6
Bind Time 1.12s (± 0.56%) 1.12s (± 0.67%) ~ 1.11s 1.13s p=0.718 n=6
Check Time 8.91s (± 0.42%) 8.90s (± 0.66%) ~ 8.82s 8.99s p=0.748 n=6
Emit Time 7.52s (± 1.00%) 7.54s (± 0.74%) ~ 7.48s 7.61s p=0.423 n=6
Total Time 20.94s (± 0.46%) 20.96s (± 0.54%) ~ 20.79s 21.08s p=0.688 n=6
Compiler-Unions - node (v18.10.0, x64)
Memory used 192,067k (± 1.18%) 191,106k (± 0.04%) ~ 191,030k 191,204k p=0.378 n=6
Parse Time 1.50s (± 0.54%) 1.52s (± 0.68%) +0.01s (+ 0.89%) 1.50s 1.53s p=0.047 n=6
Bind Time 0.77s (± 0.53%) 0.77s (± 0.53%) ~ 0.77s 0.78s p=1.000 n=6
Check Time 9.52s (± 0.93%) 9.51s (± 0.41%) ~ 9.46s 9.57s p=0.227 n=6
Emit Time 2.74s (± 1.02%) 2.77s (± 1.77%) ~ 2.70s 2.84s p=0.332 n=6
Total Time 14.54s (± 0.69%) 14.56s (± 0.48%) ~ 14.48s 14.66s p=1.000 n=6
Monaco - node (v18.10.0, x64)
Memory used 346,870k (± 0.01%) 346,895k (± 0.01%) ~ 346,864k 346,932k p=0.148 n=6
Parse Time 2.62s (± 0.61%) 2.64s (± 0.89%) ~ 2.60s 2.67s p=0.315 n=6
Bind Time 1.01s (± 0.40%) 1.01s (± 1.19%) ~ 1.00s 1.03s p=0.863 n=6
Check Time 7.29s (± 0.42%) 7.32s (± 0.22%) ~ 7.29s 7.34s p=0.106 n=6
Emit Time 4.28s (± 0.43%) 4.25s (± 0.61%) ~ 4.22s 4.29s p=0.064 n=6
Total Time 15.21s (± 0.16%) 15.22s (± 0.31%) ~ 15.17s 15.30s p=1.000 n=6
TFS - node (v18.10.0, x64)
Memory used 300,910k (± 0.00%) 300,938k (± 0.01%) +28k (+ 0.01%) 300,917k 300,956k p=0.020 n=6
Parse Time 2.09s (± 1.02%) 2.08s (± 0.72%) ~ 2.07s 2.11s p=0.465 n=6
Bind Time 1.13s (± 0.46%) 1.13s (± 0.56%) ~ 1.12s 1.14s p=0.386 n=6
Check Time 6.66s (± 0.57%) 6.69s (± 0.44%) ~ 6.65s 6.74s p=0.106 n=6
Emit Time 3.88s (± 0.51%) 3.88s (± 0.93%) ~ 3.83s 3.94s p=0.624 n=6
Total Time 13.74s (± 0.28%) 13.79s (± 0.50%) ~ 13.68s 13.88s p=0.227 n=6
material-ui - node (v18.10.0, x64)
Memory used 482,367k (± 0.01%) 482,395k (± 0.01%) ~ 482,341k 482,452k p=0.471 n=6
Parse Time 3.02s (± 2.11%) 3.10s (± 2.15%) ~ 2.97s 3.14s p=0.065 n=6
Bind Time 0.97s (± 5.46%) 0.94s (± 3.89%) ~ 0.91s 1.01s p=0.293 n=6
Check Time 17.38s (± 0.78%) 17.32s (± 0.50%) ~ 17.23s 17.45s p=0.378 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 21.37s (± 0.68%) 21.35s (± 0.46%) ~ 21.27s 21.51s p=0.687 n=6
xstate - node (v18.10.0, x64)
Memory used 563,592k (± 0.01%) 563,667k (± 0.03%) ~ 563,503k 563,862k p=0.810 n=6
Parse Time 3.84s (± 0.69%) 3.86s (± 0.45%) ~ 3.83s 3.87s p=0.224 n=6
Bind Time 1.66s (± 0.25%) 1.66s (± 1.12%) ~ 1.63s 1.68s p=0.245 n=6
Check Time 2.81s (± 0.49%) 2.80s (± 0.65%) ~ 2.78s 2.83s p=0.681 n=6
Emit Time 0.08s (± 0.00%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=1.000 n=6
Total Time 8.39s (± 0.34%) 8.40s (± 0.30%) ~ 8.36s 8.43s p=0.466 n=6
Angular - node (v16.17.1, x64)
Memory used 366,223k (± 0.01%) 366,269k (± 0.01%) +46k (+ 0.01%) 366,228k 366,289k p=0.020 n=6
Parse Time 3.56s (± 0.65%) 3.57s (± 0.79%) ~ 3.54s 3.61s p=0.686 n=6
Bind Time 1.19s (± 0.63%) 1.19s (± 0.34%) ~ 1.19s 1.20s p=0.389 n=6
Check Time 9.71s (± 0.46%) 9.66s (± 0.32%) ~ 9.60s 9.68s p=0.123 n=6
Emit Time 8.09s (± 0.46%) 7.99s (± 0.42%) -0.09s (- 1.15%) 7.95s 8.05s p=0.008 n=6
Total Time 22.54s (± 0.28%) 22.41s (± 0.33%) -0.13s (- 0.57%) 22.33s 22.53s p=0.020 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 193,442k (± 0.68%) 192,872k (± 0.02%) ~ 192,822k 192,950k p=0.149 n=6
Parse Time 1.59s (± 0.51%) 1.60s (± 0.51%) ~ 1.59s 1.61s p=0.666 n=6
Bind Time 0.83s (± 0.66%) 0.83s (± 0.99%) ~ 0.82s 0.84s p=0.859 n=6
Check Time 10.15s (± 0.76%) 10.14s (± 0.27%) ~ 10.11s 10.18s p=0.936 n=6
Emit Time 3.00s (± 0.53%) 3.02s (± 0.90%) ~ 2.98s 3.05s p=0.195 n=6
Total Time 15.56s (± 0.54%) 15.59s (± 0.33%) ~ 15.52s 15.65s p=0.517 n=6
Monaco - node (v16.17.1, x64)
Memory used 346,183k (± 0.01%) 346,203k (± 0.01%) ~ 346,164k 346,232k p=0.173 n=6
Parse Time 2.77s (± 0.49%) 2.77s (± 0.53%) ~ 2.75s 2.79s p=0.934 n=6
Bind Time 1.07s (± 0.38%) 1.08s (± 0.48%) +0.01s (+ 0.78%) 1.07s 1.08s p=0.022 n=6
Check Time 8.01s (± 0.67%) 8.03s (± 0.29%) ~ 7.99s 8.06s p=0.872 n=6
Emit Time 4.49s (± 0.60%) 4.48s (± 0.86%) ~ 4.41s 4.52s p=0.627 n=6
Total Time 16.34s (± 0.50%) 16.35s (± 0.38%) ~ 16.28s 16.45s p=1.000 n=6
TFS - node (v16.17.1, x64)
Memory used 300,246k (± 0.00%) 300,268k (± 0.01%) ~ 300,240k 300,291k p=0.065 n=6
Parse Time 2.21s (± 0.62%) 2.20s (± 0.89%) ~ 2.19s 2.24s p=0.739 n=6
Bind Time 1.20s (± 1.33%) 1.22s (± 0.96%) ~ 1.21s 1.24s p=0.118 n=6
Check Time 7.33s (± 0.45%) 7.33s (± 0.54%) ~ 7.27s 7.37s p=1.000 n=6
Emit Time 4.35s (± 0.52%) 4.33s (± 0.81%) ~ 4.28s 4.37s p=0.324 n=6
Total Time 15.09s (± 0.33%) 15.09s (± 0.57%) ~ 14.96s 15.19s p=1.000 n=6
material-ui - node (v16.17.1, x64)
Memory used 481,657k (± 0.01%) 481,664k (± 0.01%) ~ 481,607k 481,762k p=0.936 n=6
Parse Time 3.25s (± 0.41%) 3.25s (± 0.37%) ~ 3.23s 3.26s p=0.490 n=6
Bind Time 0.96s (± 0.78%) 0.96s (± 0.54%) ~ 0.95s 0.96s p=0.241 n=6
Check Time 18.45s (± 0.60%) 18.29s (± 0.31%) -0.16s (- 0.89%) 18.22s 18.34s p=0.024 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 22.67s (± 0.46%) 22.49s (± 0.26%) -0.18s (- 0.78%) 22.41s 22.56s p=0.020 n=6
xstate - node (v16.17.1, x64)
Memory used 561,367k (± 0.03%) 561,288k (± 0.03%) ~ 561,125k 561,606k p=0.378 n=6
Parse Time 4.00s (± 0.34%) 4.01s (± 0.41%) ~ 3.99s 4.03s p=0.935 n=6
Bind Time 1.78s (± 1.05%) 1.76s (± 1.33%) ~ 1.73s 1.79s p=0.513 n=6
Check Time 3.07s (± 0.39%) 3.06s (± 0.49%) ~ 3.04s 3.08s p=0.742 n=6
Emit Time 0.10s (± 5.76%) 0.09s (± 5.53%) ~ 0.09s 0.10s p=0.640 n=6
Total Time 8.94s (± 0.39%) 8.92s (± 0.35%) ~ 8.89s 8.97s p=0.687 n=6
Angular - node (v14.21.3, x64)
Memory used 360,186k (± 0.01%) 360,212k (± 0.01%) ~ 360,179k 360,272k p=0.149 n=6
Parse Time 3.71s (± 0.15%) 3.73s (± 0.36%) +0.02s (+ 0.45%) 3.71s 3.75s p=0.032 n=6
Bind Time 1.22s (± 0.62%) 1.23s (± 0.66%) ~ 1.22s 1.24s p=0.120 n=6
Check Time 10.07s (± 0.38%) 10.14s (± 0.35%) +0.07s (+ 0.66%) 10.09s 10.18s p=0.029 n=6
Emit Time 8.34s (± 0.74%) 8.36s (± 0.39%) ~ 8.30s 8.39s p=0.520 n=6
Total Time 23.35s (± 0.36%) 23.45s (± 0.24%) ~ 23.38s 23.52s p=0.054 n=6
Compiler-Unions - node (v14.21.3, x64)
Memory used 188,193k (± 0.01%) 188,197k (± 0.01%) ~ 188,159k 188,239k p=0.630 n=6
Parse Time 1.61s (± 0.61%) 1.62s (± 1.03%) ~ 1.60s 1.64s p=0.209 n=6
Bind Time 0.85s (± 0.48%) 0.85s (± 1.37%) ~ 0.84s 0.87s p=0.858 n=6
Check Time 10.30s (± 0.80%) 10.33s (± 0.62%) ~ 10.24s 10.43s p=0.520 n=6
Emit Time 3.13s (± 0.92%) 3.13s (± 1.29%) ~ 3.10s 3.21s p=0.802 n=6
Total Time 15.90s (± 0.51%) 15.94s (± 0.53%) ~ 15.85s 16.03s p=0.294 n=6
Monaco - node (v14.21.3, x64)
Memory used 341,176k (± 0.01%) 341,205k (± 0.01%) ~ 341,170k 341,249k p=0.149 n=6
Parse Time 2.81s (± 0.49%) 2.81s (± 0.55%) ~ 2.79s 2.83s p=0.805 n=6
Bind Time 1.09s (± 0.47%) 1.10s (± 0.57%) ~ 1.09s 1.11s p=0.091 n=6
Check Time 8.27s (± 0.55%) 8.31s (± 0.39%) ~ 8.27s 8.35s p=0.198 n=6
Emit Time 4.69s (± 0.65%) 4.66s (± 0.43%) ~ 4.63s 4.69s p=0.107 n=6
Total Time 16.86s (± 0.40%) 16.88s (± 0.28%) ~ 16.82s 16.93s p=0.572 n=6
TFS - node (v14.21.3, x64)
Memory used 295,329k (± 0.00%) 295,342k (± 0.00%) +14k (+ 0.00%) 295,336k 295,347k p=0.020 n=6
Parse Time 2.42s (± 1.25%) 2.43s (± 0.60%) ~ 2.41s 2.45s p=0.145 n=6
Bind Time 1.08s (± 0.70%) 1.08s (± 0.91%) ~ 1.07s 1.09s p=0.554 n=6
Check Time 7.65s (± 0.58%) 7.66s (± 0.45%) ~ 7.63s 7.72s p=0.805 n=6
Emit Time 4.29s (± 0.67%) 4.30s (± 0.77%) ~ 4.26s 4.34s p=0.687 n=6
Total Time 15.45s (± 0.41%) 15.48s (± 0.28%) ~ 15.42s 15.53s p=0.574 n=6
material-ui - node (v14.21.3, x64)
Memory used 477,159k (± 0.00%) 477,170k (± 0.00%) ~ 477,156k 477,191k p=0.199 n=6
Parse Time 3.31s (± 0.63%) 3.30s (± 0.56%) ~ 3.29s 3.34s p=0.677 n=6
Bind Time 0.99s (± 0.41%) 0.99s (± 0.52%) ~ 0.99s 1.00s p=0.114 n=6
Check Time 19.21s (± 0.59%) 19.16s (± 0.41%) ~ 19.09s 19.31s p=0.336 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 23.51s (± 0.48%) 23.46s (± 0.37%) ~ 23.38s 23.61s p=0.423 n=6
xstate - node (v14.21.3, x64)
Memory used 550,104k (± 0.00%) 550,124k (± 0.01%) ~ 550,077k 550,187k p=0.689 n=6
Parse Time 4.21s (± 0.34%) 4.22s (± 0.44%) ~ 4.20s 4.24s p=0.627 n=6
Bind Time 1.67s (± 2.16%) 1.69s (± 0.58%) ~ 1.68s 1.70s p=0.625 n=6
Check Time 3.14s (± 0.44%) 3.13s (± 0.49%) -0.01s (- 0.48%) 3.11s 3.14s p=0.034 n=6
Emit Time 0.09s (± 0.00%) 0.09s (± 0.00%) ~ 0.09s 0.09s p=1.000 n=6
Total Time 9.12s (± 0.37%) 9.13s (± 0.24%) ~ 9.10s 9.16s p=0.747 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-148-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.21.3, x64)
Scenarios
  • Angular - node (v18.10.0, x64)
  • Angular - node (v16.17.1, x64)
  • Angular - node (v14.21.3, x64)
  • Compiler-Unions - node (v18.10.0, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Compiler-Unions - node (v14.21.3, x64)
  • Monaco - node (v18.10.0, x64)
  • Monaco - node (v16.17.1, x64)
  • Monaco - node (v14.21.3, x64)
  • TFS - node (v18.10.0, x64)
  • TFS - node (v16.17.1, x64)
  • TFS - node (v14.21.3, x64)
  • material-ui - node (v18.10.0, x64)
  • material-ui - node (v16.17.1, x64)
  • material-ui - node (v14.21.3, x64)
  • xstate - node (v18.10.0, x64)
  • xstate - node (v16.17.1, x64)
  • xstate - node (v14.21.3, x64)
Benchmark Name Iterations
Current 55052 6
Baseline main 6

TSServer

Comparison Report - main..55052
Metric main 55052 Delta Best Worst p-value
Compiler-UnionsTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 2,530ms (± 0.79%) 2,564ms (± 0.61%) +34ms (+ 1.34%) 2,543ms 2,589ms p=0.013 n=6
Req 2 - geterr 5,382ms (± 0.69%) 5,386ms (± 0.48%) ~ 5,340ms 5,418ms p=0.748 n=6
Req 3 - references 340ms (± 0.44%) 342ms (± 0.30%) +2ms (+ 0.59%) 340ms 343ms p=0.040 n=6
Req 4 - navto 287ms (± 0.44%) 288ms (± 0.28%) ~ 287ms 289ms p=0.082 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 91ms (± 2.20%) 91ms (± 2.58%) ~ 86ms 92ms p=0.652 n=6
CompilerTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 2,622ms (± 0.94%) 2,616ms (± 0.49%) ~ 2,599ms 2,638ms p=0.810 n=6
Req 2 - geterr 4,115ms (± 0.55%) 4,109ms (± 0.67%) ~ 4,072ms 4,140ms p=0.689 n=6
Req 3 - references 347ms (± 1.17%) 348ms (± 1.07%) ~ 341ms 351ms p=0.807 n=6
Req 4 - navto 289ms (± 1.11%) 289ms (± 0.79%) ~ 287ms 293ms p=1.000 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 73ms (± 3.62%) 76ms (± 2.35%) ~ 74ms 79ms p=0.167 n=6
xstateTSServer - node (v18.10.0, x64)
Req 1 - updateOpen 3,073ms (± 0.50%) 3,101ms (± 0.91%) ~ 3,060ms 3,139ms p=0.108 n=6
Req 2 - geterr 1,599ms (± 0.86%) 1,593ms (± 0.48%) ~ 1,582ms 1,602ms p=0.574 n=6
Req 3 - references 115ms (± 1.42%) 118ms (± 5.79%) ~ 113ms 132ms p=0.222 n=6
Req 4 - navto 370ms (± 1.06%) 371ms (± 0.98%) ~ 368ms 377ms p=0.370 n=6
Req 5 - completionInfo count 2,872 (± 0.00%) 2,872 (± 0.00%) ~ 2,872 2,872 p=1.000 n=6
Req 5 - completionInfo 379ms (± 2.24%) 386ms (± 0.73%) ~ 383ms 391ms p=0.172 n=6
Compiler-UnionsTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,638ms (± 0.94%) 2,640ms (± 0.54%) ~ 2,618ms 2,653ms p=0.873 n=6
Req 2 - geterr 6,026ms (± 0.40%) 6,048ms (± 0.42%) ~ 6,019ms 6,089ms p=0.149 n=6
Req 3 - references 351ms (± 0.87%) 355ms (± 0.62%) +4ms (+ 1.09%) 352ms 358ms p=0.044 n=6
Req 4 - navto 290ms (± 1.32%) 288ms (± 1.10%) ~ 283ms 293ms p=0.212 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 96ms (± 5.86%) 99ms (± 0.99%) ~ 98ms 100ms p=0.402 n=6
CompilerTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 2,799ms (± 0.33%) 2,812ms (± 0.44%) ~ 2,788ms 2,822ms p=0.109 n=6
Req 2 - geterr 4,659ms (± 0.44%) 4,660ms (± 0.52%) ~ 4,627ms 4,695ms p=1.000 n=6
Req 3 - references 364ms (± 0.69%) 365ms (± 0.32%) ~ 363ms 366ms p=0.124 n=6
Req 4 - navto 283ms (± 0.66%) 285ms (± 1.01%) ~ 281ms 290ms p=0.060 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 76ms (± 1.36%) 76ms (± 0.99%) ~ 75ms 77ms p=0.437 n=6
xstateTSServer - node (v16.17.1, x64)
Req 1 - updateOpen 3,221ms (± 0.20%) 3,247ms (± 0.70%) ~ 3,210ms 3,266ms p=0.065 n=6
Req 2 - geterr 1,747ms (± 1.17%) 1,748ms (± 0.62%) ~ 1,727ms 1,757ms p=0.748 n=6
Req 3 - references 123ms (± 1.40%) 127ms (± 6.09%) ~ 123ms 143ms p=0.120 n=6
Req 4 - navto 355ms (± 0.58%) 354ms (± 0.88%) ~ 349ms 357ms p=1.000 n=6
Req 5 - completionInfo count 2,872 (± 0.00%) 2,872 (± 0.00%) ~ 2,872 2,872 p=1.000 n=6
Req 5 - completionInfo 413ms (± 2.29%) 416ms (± 1.72%) ~ 408ms 426ms p=0.521 n=6
Compiler-UnionsTSServer - node (v14.21.3, x64)
Req 1 - updateOpen 2,760ms (± 0.73%) 2,767ms (± 0.41%) ~ 2,749ms 2,779ms p=0.521 n=6
Req 2 - geterr 6,205ms (± 1.40%) 6,175ms (± 0.73%) ~ 6,132ms 6,258ms p=0.575 n=6
Req 3 - references 360ms (± 0.72%) 365ms (± 1.37%) ~ 359ms 372ms p=0.109 n=6
Req 4 - navto 292ms (± 1.24%) 294ms (± 1.59%) ~ 290ms 302ms p=0.244 n=6
Req 5 - completionInfo count 1,356 (± 0.00%) 1,356 (± 0.00%) ~ 1,356 1,356 p=1.000 n=6
Req 5 - completionInfo 109ms (± 3.38%) 108ms (± 7.03%) ~ 93ms 113ms p=0.744 n=6
CompilerTSServer - node (v14.21.3, x64)
Req 1 - updateOpen 2,931ms (± 0.83%) 2,944ms (± 0.59%) ~ 2,922ms 2,967ms p=0.471 n=6
Req 2 - geterr 4,559ms (± 0.73%) 4,560ms (± 0.65%) ~ 4,529ms 4,612ms p=0.810 n=6
Req 3 - references 381ms (± 0.75%) 381ms (± 1.05%) ~ 378ms 387ms p=0.936 n=6
Req 4 - navto 296ms (± 0.72%) 298ms (± 0.35%) +3ms (+ 0.85%) 297ms 300ms p=0.049 n=6
Req 5 - completionInfo count 1,518 (± 0.00%) 1,518 (± 0.00%) ~ 1,518 1,518 p=1.000 n=6
Req 5 - completionInfo 82ms (± 1.47%) 85ms (± 2.67%) +2ms (+ 2.63%) 83ms 89ms p=0.046 n=6
xstateTSServer - node (v14.21.3, x64)
Req 1 - updateOpen 3,519ms (± 0.59%) 3,530ms (± 0.50%) ~ 3,510ms 3,558ms p=0.261 n=6
Req 2 - geterr 1,871ms (± 0.69%) 1,861ms (± 0.56%) ~ 1,847ms 1,876ms p=0.199 n=6
Req 3 - references 139ms (± 7.06%) 146ms (± 7.02%) ~ 132ms 153ms p=0.463 n=6
Req 4 - navto 389ms (± 1.37%) 391ms (± 1.22%) ~ 385ms 397ms p=0.419 n=6
Req 5 - completionInfo count 2,872 (± 0.00%) 2,872 (± 0.00%) ~ 2,872 2,872 p=1.000 n=6
Req 5 - completionInfo 421ms (± 1.48%) 421ms (± 0.77%) ~ 418ms 427ms p=0.936 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-148-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v18.10.0, x64)
  • node (v16.17.1, x64)
  • node (v14.21.3, x64)
Scenarios
  • Compiler-UnionsTSServer - node (v18.10.0, x64)
  • Compiler-UnionsTSServer - node (v16.17.1, x64)
  • Compiler-UnionsTSServer - node (v14.21.3, x64)
  • CompilerTSServer - node (v18.10.0, x64)
  • CompilerTSServer - node (v16.17.1, x64)
  • CompilerTSServer - node (v14.21.3, x64)
  • xstateTSServer - node (v18.10.0, x64)
  • xstateTSServer - node (v16.17.1, x64)
  • xstateTSServer - node (v14.21.3, x64)
Benchmark Name Iterations
Current 55052 6
Baseline main 6

Startup

Comparison Report - main..55052
Metric main 55052 Delta Best Worst p-value
tsc-startup - node (v16.17.1, x64)
Execution time 142.45ms (± 0.21%) 143.05ms (± 0.21%) +0.59ms (+ 0.42%) 142.18ms 145.81ms p=0.000 n=600
tsserver-startup - node (v16.17.1, x64)
Execution time 222.13ms (± 0.23%) 222.90ms (± 0.18%) +0.77ms (+ 0.35%) 221.77ms 226.59ms p=0.000 n=600
tsserverlibrary-startup - node (v16.17.1, x64)
Execution time 224.33ms (± 0.28%) 223.86ms (± 0.16%) -0.47ms (- 0.21%) 222.89ms 228.96ms p=0.000 n=600
typescript-startup - node (v16.17.1, x64)
Execution time 205.80ms (± 0.23%) 205.83ms (± 0.15%) +0.03ms (+ 0.01%) 205.03ms 210.81ms p=0.000 n=600
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-148-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v16.17.1, x64)
Scenarios
  • tsc-startup - node (v16.17.1, x64)
  • tsserver-startup - node (v16.17.1, x64)
  • tsserverlibrary-startup - node (v16.17.1, x64)
  • typescript-startup - node (v16.17.1, x64)
Benchmark Name Iterations
Current 55052 6
Baseline main 6

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

Hey @rbuckton, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

@rbuckton
Copy link
Member Author

rbuckton commented Aug 9, 2023

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 9, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Aug 9, 2023

Hey @rbuckton, 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/156423/artifacts?artifactName=tgz&fileId=BBBB1882B63D1727843C1849163FCC29DE37D3F84D961910EDF835ACC1AB34AC02&fileName=/typescript-5.3.0-insiders.20230809.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@5.3.0-pr-55052-14".;

@jakebailey
Copy link
Member

jakebailey commented Aug 9, 2023

Leaving a random comment to test the new perf infra on this PR.

Update: The results are in!

@rbuckton rbuckton requested a review from ahejlsberg September 20, 2023 20:34
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.

This seems a lot more complex than I had expected. I'm not quite understanding why we need synthetic method calls and potentially overload resolution to figure this out.

@rbuckton
Copy link
Member Author

The most recent commits address feedback from an offline discussion with @ahejlsberg. @ahejlsberg, can you take another look?

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.

Suggest simplifying the error reporting per comments, otherwise looks good.

@rbuckton rbuckton merged commit 9cf44dc into main Sep 29, 2023
@rbuckton rbuckton deleted the instanceof-Symbol.hasInstance branch September 29, 2023 17:37
@rbuckton
Copy link
Member Author

@typescript-bot cherry-pick this to release-5.3

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 29, 2023

Heya @rbuckton, I've started to run the task to cherry-pick this into release-5.3 on this PR at 0554f56. You can monitor the build here.

@rbuckton rbuckton restored the instanceof-Symbol.hasInstance branch September 29, 2023 17:39
@rbuckton rbuckton deleted the instanceof-Symbol.hasInstance branch September 29, 2023 17:43
@typescript-bot
Copy link
Collaborator

Hey @rbuckton, I couldn't open a PR with the cherry-pick. (You can check the log here). You may need to squash and pick this PR into release-5.3 manually.

typescript-bot pushed a commit to typescript-bot/TypeScript that referenced this pull request Sep 29, 2023
Component commits:
69f59da [WIP] Support custom 'Symbol.hasInstance' methods when checking/narrowing 'instanceof'

161d1f1 Add tests for instanceof and narrowing

6a4f838 Accept baseline, fix lint

af6bb55 Check derived types when using type predicates with instanceof/hasInstance

6a83254 Small tweaks, lint fixes, and baseline updates

511c955 Add go-to-definition support on 'instanceof' keyword

9e3adb4 Merge branch 'main' into instanceof-Symbol.hasInstance

4b0eafc Fix format

befa293 Address PR feedback

559047e Comment cleanup

8af777e Switch synthetic call to use use 'resolveSignature' flow

f3e94f0 Merge branch 'main' into instanceof-Symbol.hasInstance

1d90af1 Run formatting

b65f9bc Merge branch 'main' into instanceof-Symbol.hasInstance

0554f56 Remove branch for 'instanceof' error message reporting
@jakebailey
Copy link
Member

I have no idea why the pick failed; I was going to say that it failed a the push stage but it got pushed above: typescript-bot@97bf30b

Probably some weird GH outage :|

(I am working on replacing this pick task anyway.)

@rbuckton
Copy link
Member Author

rbuckton commented Sep 29, 2023

It doesn't matter too much in this case. Daniel said he'd just update from main anyways.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Archived in project
6 participants