Skip to content
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

Fast path for negative case when relating to unions of primtives #53192

Merged
merged 2 commits into from Mar 17, 2023

Conversation

ahejlsberg
Copy link
Member

This PR implements a fast path for the negative case of relating a literal type to a union of primtive types. This reduces the check time of the example in #53191 from ~45s to ~0.4s.

Fixes #53191.

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Mar 10, 2023
@ahejlsberg
Copy link
Member Author

@typescript-bot test this
@typescript-bot user test this inline
@typescript-bot run dt
@typescript-bot perf test faster
@typescript-bot test top100

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2023

Heya @ahejlsberg, I've started to run the abridged perf test suite on this PR at 922d47e. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2023

Heya @ahejlsberg, I've started to run the diff-based top-repos suite on this PR at 922d47e. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@jakebailey
Copy link
Member

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 10, 2023

Hey @jakebailey, 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/149010/artifacts?artifactName=tgz&fileId=95C542655335E9D7C485E8D08636527C9571596EBC161D59087FDF01D4A12DEB02&fileName=/typescript-5.1.0-insiders.20230310.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.1.0-pr-53192-9".;

@typescript-bot
Copy link
Collaborator

Hey @ahejlsberg, the results of running the DT tests are ready.
There were interesting changes:

Branch only errors:

Package: dom-mediacapture-transform
Error:

Error: Errors in typescript@local for external dependencies:
../dom-webcodecs/webcodecs.generated.d.ts(132,5): error TS2687: All declarations of 'config' must have identical modifiers.
../dom-webcodecs/webcodecs.generated.d.ts(132,5): error TS2717: Subsequent property declarations must have the same type.  Property 'config' must be of type 'VideoDecoderConfig | undefined', but here has type 'VideoDecoderConfig'.
../dom-webcodecs/webcodecs.generated.d.ts(133,5): error TS2687: All declarations of 'supported' must have identical modifiers.
../dom-webcodecs/webcodecs.generated.d.ts(133,5): error TS2717: Subsequent property declarations must have the same type.  Property 'supported' must be of type 'boolean | undefined', but here has type 'boolean'.
../dom-webcodecs/webcodecs.generated.d.ts(153,5): error TS2717: Subsequent property declarations must have the same type.  Property 'keyFrame' must be of type 'boolean | undefined', but here has type 'boolean | null | undefined'.
../dom-webcodecs/webcodecs.generated.d.ts(162,5): error TS2687: All declarations of 'config' must have identical modifiers.
../dom-webcodecs/webcodecs.generated.d.ts(162,5): error TS2717: Subsequent property declarations must have the same type.  Property 'config' must be of type 'VideoEncoderConfig | undefined', but here has type 'VideoEncoderConfig'.
../dom-webcodecs/webcodecs.generated.d.ts(163,5): error TS2687: All declarations of 'supported' must have identical modifiers.
../dom-webcodecs/webcodecs.generated.d.ts(163,5): error TS2717: Subsequent property declarations must have the same type.  Property 'supported' must be of type 'boolean | undefined', but here has type 'boolean'.
../dom-webcodecs/webcodecs.generated.d.ts(369,14): error TS2717: Subsequent property declarations must have the same type.  Property 'timestamp' must be of type 'number', but here has type 'number | null'.
../dom-webcodecs/webcodecs.generated.d.ts(404,6): error TS2300: Duplicate identifier 'BitrateMode'.
../dom-webcodecs/webcodecs.generated.d.ts(406,6): error TS2300: Duplicate identifier 'AlphaOption'.
../dom-webcodecs/webcodecs.generated.d.ts(408,6): error TS2300: Duplicate identifier 'AvcBitstreamFormat'.
../dom-webcodecs/webcodecs.generated.d.ts(409,6): error TS2300: Duplicate identifier 'CodecState'.
../dom-webcodecs/webcodecs.generated.d.ts(411,6): error TS2300: Duplicate identifier 'EncodedVideoChunkType'.
../dom-webcodecs/webcodecs.generated.d.ts(413,6): error TS2300: Duplicate identifier 'LatencyMode'.
../dom-webcodecs/webcodecs.generated.d.ts(416,6): error TS2300: Duplicate identifier 'VideoPixelFormat'.
../../../../../../built/local/lib.dom.d.ts(2010,5): error TS2687: All declarations of 'config' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(2011,5): error TS2687: All declarations of 'supported' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(2040,5): error TS2687: All declarations of 'config' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(2041,5): error TS2687: All declarations of 'supported' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(19284,6): error TS2300: Duplicate identifier 'AlphaOption'.
../../../../../../built/local/lib.dom.d.ts(19295,6): error TS2300: Duplicate identifier 'AvcBitstreamFormat'.
../../../../../../built/local/lib.dom.d.ts(19298,6): error TS2300: Duplicate identifier 'BitrateMode'.
../../../../../../built/local/lib.dom.d.ts(19315,6): error TS2300: Duplicate identifier 'CodecState'.
../../../../../../built/local/lib.dom.d.ts(19327,6): error TS2300: Duplicate identifier 'EncodedVideoChunkType'.
../../../../../../built/local/lib.dom.d.ts(19354,6): error TS2300: Duplicate identifier 'LatencyMode'.
../../../../../../built/local/lib.dom.d.ts(19448,6): error TS2300: Duplicate identifier 'VideoPixelFormat'.

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:151:9)

Package: dom-screen-wake-lock
Error:

Error: Errors in typescript@local for external dependencies:
../../../../../../built/local/lib.dom.d.ts(19450,6): error TS2300: Duplicate identifier 'WakeLockType'.

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:151:9)

Package: web-animations-js
Error:

Error: /home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/DefinitelyTyped/types/web-animations-js/index.d.ts:11:14
ERROR: 11:14  expect  TypeScript@local compile error: 
Subsequent property declarations must have the same type.  Property 'currentTime' must be of type 'CSSNumberish | null', but here has type 'number | null'.
ERROR: 12:14  expect  TypeScript@local compile error: 
Subsequent property declarations must have the same type.  Property 'timelineTime' must be of type 'CSSNumberish | null', but here has type 'number | null'.
ERROR: 23:5   expect  TypeScript@local compile error: 
Subsequent property declarations must have the same type.  Property 'currentTime' must be of type 'CSSNumberish | null | undefined', but here has type 'number | null | undefined'.
ERROR: 24:5   expect  TypeScript@local compile error: 
Subsequent property declarations must have the same type.  Property 'timelineTime' must be of type 'CSSNumberish | null | undefined', but here has type 'number | null | undefined'.
ERROR: 41:14  expect  TypeScript@local compile error: 
Subsequent property declarations must have the same type.  Property 'currentTime' must be of type 'CSSNumberish | null', but here has type 'number | null'.
ERROR: 73:5   expect  TypeScript@local compile error: 
Subsequent property declarations must have the same type.  Property 'currentTime' must be of type 'CSSNumberish | null', but here has type 'number | null'.
ERROR: 79:5   expect  TypeScript@local compile error: 
Subsequent property declarations must have the same type.  Property 'startTime' must be of type 'CSSNumberish | null', but here has type 'number | null'.

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:151:9)

Package: webappsec-credential-management
Error:

Error: /home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/DefinitelyTyped/types/webappsec-credential-management/index.d.ts:309:5
ERROR: 309:5  expect  TypeScript@local compile error: 
Subsequent property declarations must have the same type.  Property 'mediation' must be of type 'CredentialMediationRequirement | undefined', but here has type '"required" | "optional" | "silent" | undefined'.

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:151:9)

Package: dom-webcodecs
Error:

Error: Errors in typescript@local for external dependencies:
../../../../../../built/local/lib.dom.d.ts(2010,5): error TS2687: All declarations of 'config' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(2011,5): error TS2687: All declarations of 'supported' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(2040,5): error TS2687: All declarations of 'config' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(2041,5): error TS2687: All declarations of 'supported' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(19284,6): error TS2300: Duplicate identifier 'AlphaOption'.
../../../../../../built/local/lib.dom.d.ts(19295,6): error TS2300: Duplicate identifier 'AvcBitstreamFormat'.
../../../../../../built/local/lib.dom.d.ts(19298,6): error TS2300: Duplicate identifier 'BitrateMode'.
../../../../../../built/local/lib.dom.d.ts(19315,6): error TS2300: Duplicate identifier 'CodecState'.
../../../../../../built/local/lib.dom.d.ts(19327,6): error TS2300: Duplicate identifier 'EncodedVideoChunkType'.
../../../../../../built/local/lib.dom.d.ts(19354,6): error TS2300: Duplicate identifier 'LatencyMode'.
../../../../../../built/local/lib.dom.d.ts(19448,6): error TS2300: Duplicate identifier 'VideoPixelFormat'.

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:151:9)

Package: w3c-css-typed-object-model-level-1
Error:

Error: Errors in typescript@local for external dependencies:
../../../../../../built/local/lib.dom.d.ts(23,1): error TS6200: Definitions of the following identifiers conflict with those in another file: CSSStyleValue, CSSVariableReferenceValue, CSSUnparsedSegment, CSSUnparsedValue, CSSKeywordValue, CSSNumericValue, CSSUnitValue, CSSMathValue, CSSMathSum, CSSMathProduct, CSSMathNegate, CSSMathInvert, CSSMathMin, CSSMathMax, CSSNumericArray, CSSTransformValue, CSSTransformComponent, CSSTranslate, CSSRotate, CSSScale, CSSSkew, CSSSkewX, CSSSkewY, CSSPerspective, CSSMatrixComponent, CSSImageValue, StylePropertyMapReadOnly, StylePropertyMap
../../../../../../built/local/lib.dom.d.ts(177,5): error TS2687: All declarations of 'is2D' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(181,5): error TS2687: All declarations of 'angle' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(182,5): error TS2687: All declarations of 'flex' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(183,5): error TS2687: All declarations of 'frequency' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(184,5): error TS2687: All declarations of 'length' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(185,5): error TS2687: All declarations of 'percent' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(186,5): error TS2687: All declarations of 'percentHint' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(187,5): error TS2687: All declarations of 'resolution' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(188,5): error TS2687: All declarations of 'time' must have identical modifiers.
../../../../../../built/local/lib.dom.d.ts(19299,6): error TS2567: Enum declarations can only merge with namespace or other enum declarations.
../../../../../../built/local/lib.dom.d.ts(19300,6): error TS2567: Enum declarations can only merge with namespace or other enum declarations.

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:151:9)

Package: use-color-scheme
Error:

Error: /home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/DefinitelyTyped/types/use-color-scheme/use-color-scheme-tests.ts:8:1
ERROR: 8:1  expect  TypeScript@local expected type to be:
  "dark" | "light" | "no-preference"
got:
  "no-preference" | "dark" | "light"

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:151:9)

Package: dom-mediacapture-record
Error:

Error: Errors in typescript@local for external dependencies:
../../../../../../built/local/lib.dom.d.ts(19298,6): error TS2300: Duplicate identifier 'BitrateMode'.

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:151:9)

Package: ramda
Error:

Error: /home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/DefinitelyTyped/types/ramda/test/binary-tests.ts:29:5
ERROR: 29:5  expect  TypeScript@local expected type to be:
  (head: number, head: undefined) => number[]
got:
  (head: number, head_1: undefined) => number[]
ERROR: 30:5  expect  TypeScript@local expected type to be:
  (head: number, head: number) => number[]
got:
  (head: number, head_1: number) => number[]
ERROR: 31:5  expect  TypeScript@local expected type to be:
  (head: number, head: number) => number[]
got:
  (head: number, head_1: number) => number[]

/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/DefinitelyTyped/types/ramda/test/nAry-tests.ts:22:5
ERROR: 22:5  expect  TypeScript@local expected type to be:
  (head: number, head: undefined) => number[]
got:
  (head: number, head_1: undefined) => number[]

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint-runner/node_modules/@definitelytyped/dtslint/dist/index.js:151:9)

You can check the log here.

@jakebailey
Copy link
Member

RE: DT above, the results are still compared against nightly, so some of those are preexisting breaks caused elsewhere today and can be ignored. I think @gabritto is looking switching that to compare against main.

(In particular, DOM was updated which is most of the breaks, plus a dts emit change I need to go update in ramda.)

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the top-repos suite comparing main and refs/pull/53192/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..53192

Metric main 53192 Delta Best Worst p-value
Angular - node (v16.17.1, x64)
Memory used 362,834k (± 0.01%) 362,828k (± 0.01%) ~ 362,806k 362,852k p=0.689 n=6
Parse Time 3.52s (± 0.89%) 3.50s (± 1.13%) ~ 3.47s 3.57s p=0.466 n=6
Bind Time 1.18s (± 0.69%) 1.18s (± 0.44%) ~ 1.17s 1.18s p=0.114 n=6
Check Time 9.45s (± 0.48%) 9.43s (± 0.23%) ~ 9.39s 9.45s p=0.677 n=6
Emit Time 7.95s (± 0.46%) 7.93s (± 0.84%) ~ 7.88s 8.06s p=0.170 n=6
Total Time 22.10s (± 0.23%) 22.03s (± 0.39%) ~ 21.94s 22.16s p=0.148 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 192,725k (± 0.03%) 193,255k (± 0.66%) ~ 192,649k 195,848k p=0.689 n=6
Parse Time 1.59s (± 1.01%) 1.59s (± 1.24%) ~ 1.55s 1.60s p=1.000 n=6
Bind Time 0.82s (± 0.77%) 0.82s (± 0.77%) ~ 0.81s 0.83s p=1.000 n=6
Check Time 10.11s (± 0.36%) 10.11s (± 0.83%) ~ 10.03s 10.24s p=0.687 n=6
Emit Time 2.99s (± 0.84%) 3.00s (± 0.83%) ~ 2.97s 3.04s p=0.375 n=6
Total Time 15.51s (± 0.28%) 15.51s (± 0.63%) ~ 15.41s 15.68s p=0.873 n=6
Monaco - node (v16.17.1, x64)
Memory used 346,684k (± 0.00%) 346,692k (± 0.00%) ~ 346,672k 346,709k p=0.336 n=6
Parse Time 2.72s (± 0.36%) 2.73s (± 0.33%) ~ 2.72s 2.74s p=0.070 n=6
Bind Time 1.08s (± 0.50%) 1.09s (± 0.47%) ~ 1.08s 1.09s p=0.640 n=6
Check Time 7.74s (± 0.63%) 7.73s (± 0.50%) ~ 7.68s 7.80s p=1.000 n=6
Emit Time 4.45s (± 0.48%) 4.46s (± 0.91%) ~ 4.42s 4.53s p=1.000 n=6
Total Time 15.99s (± 0.45%) 16.01s (± 0.37%) ~ 15.94s 16.10s p=0.378 n=6
TFS - node (v16.17.1, x64)
Memory used 300,146k (± 0.01%) 300,134k (± 0.01%) ~ 300,096k 300,191k p=0.575 n=6
Parse Time 2.17s (± 0.65%) 2.18s (± 0.38%) ~ 2.16s 2.18s p=0.503 n=6
Bind Time 1.23s (± 1.22%) 1.23s (± 1.40%) ~ 1.21s 1.25s p=0.865 n=6
Check Time 7.15s (± 0.34%) 7.16s (± 0.51%) ~ 7.12s 7.22s p=0.808 n=6
Emit Time 4.32s (± 0.54%) 4.35s (± 0.91%) ~ 4.29s 4.40s p=0.168 n=6
Total Time 14.87s (± 0.33%) 14.92s (± 0.55%) ~ 14.84s 15.03s p=0.261 n=6
material-ui - node (v16.17.1, x64)
Memory used 477,749k (± 0.02%) 477,761k (± 0.00%) ~ 477,735k 477,778k p=0.471 n=6
Parse Time 3.22s (± 0.39%) 3.23s (± 0.54%) ~ 3.20s 3.25s p=0.463 n=6
Bind Time 0.96s (± 0.88%) 0.95s (± 0.86%) ~ 0.94s 0.96s p=1.000 n=6
Check Time 18.14s (± 0.60%) 18.01s (± 0.31%) ~ 17.93s 18.09s p=0.064 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 22.31s (± 0.49%) 22.19s (± 0.25%) ~ 22.10s 22.25s p=0.090 n=6
xstate - node (v16.17.1, x64)
Memory used 550,679k (± 0.02%) 550,699k (± 0.02%) ~ 550,629k 550,840k p=0.810 n=6
Parse Time 3.96s (± 0.29%) 3.94s (± 0.21%) -0.02s (- 0.42%) 3.94s 3.96s p=0.027 n=6
Bind Time 1.79s (± 0.61%) 1.79s (± 0.76%) ~ 1.78s 1.82s p=0.929 n=6
Check Time 3.00s (± 0.63%) 2.99s (± 0.28%) ~ 2.98s 3.00s p=0.667 n=6
Emit Time 0.09s (± 0.00%) 0.09s (± 0.00%) ~ 0.09s 0.09s p=1.000 n=6
Total Time 8.84s (± 0.31%) 8.83s (± 0.21%) ~ 8.81s 8.86s p=0.466 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-135-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
  • Angular - node (v16.17.1, x64)
  • Compiler-Unions - node (v16.17.1, x64)
  • Monaco - node (v16.17.1, x64)
  • TFS - node (v16.17.1, x64)
  • material-ui - node (v16.17.1, x64)
  • xstate - node (v16.17.1, x64)
Benchmark Name Iterations
Current 53192 6
Baseline main 6

Developer Information:

Download Benchmark

@Andarist
Copy link
Contributor

This likely supersedes #50640 and thus fixes #47511 and #47481

I tested the case from #47481 and the check time went from 12s to 0.5s on my machine

@DanielRosenwasser
Copy link
Member

Should we add the test cases from #47511, #47481, and #53191?

@ahejlsberg
Copy link
Member Author

Should we add the test cases from #47511, #47481, and #53191?

All that's interesting about those tests is their performance, and we don't measure that. So don't think so.

@jakebailey
Copy link
Member

jakebailey commented Mar 15, 2023

If they "fail", then they'll take long enough to time out the runner, or at least be suspiciously slow. Maybe that's enough, but I don't feel strongly.

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

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

IMO, we should add the test cases from the other issues, since, while we don't collect test perf metrics right now, we've talked about starting to collect them, once we have some more perf CI machine bandwidth, since the metrics are actually collected already. You can already require("./.parallelperf.json") to get an object with the timing data from your last run, so you can already anecdotally use the data today.

@@ -20837,6 +20833,21 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (containsType(targetTypes, source)) {
return Ternary.True;
}
if (getObjectFlags(target) & ObjectFlags.PrimitiveUnion && !(source.flags & TypeFlags.EnumLiteral) && (
source.flags & (TypeFlags.StringLiteral | TypeFlags.BooleanLiteral | TypeFlags.BigIntLiteral) ||
Copy link
Member

Choose a reason for hiding this comment

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

This can be expanded to cover unique symbol literals, too.

Copy link
Member Author

Choose a reason for hiding this comment

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

I considered that, but we'd then have to exclude them from the alternateForm check below because unique symbols don't have fresh forms. The extra complexity just doesn't seem worth it, I honestly can't imagine union types with multiple thousand unique symbols types anyways.

@ahejlsberg
Copy link
Member Author

I'm going to leave the tests out. Even with the optimization in this PR they still take a while to complete, and I don't want to add that overhead to every test run in perpituity when they don't actually check anything new. Once we have better performance infrastructure we should consider adding them there.

@ahejlsberg ahejlsberg merged commit a70c409 into main Mar 17, 2023
18 checks passed
@Andarist
Copy link
Contributor

The regression reported here can be traced back to this PR. The minimal~ repro case for it is this:

enum AutomationMode {
  NONE = "",
  TIME = "time",
  SYSTEM = "system",
  LOCATION = "location",
}

interface ThemePreset {
  id: string;
}

interface Automation {
  mode: AutomationMode;
}

interface UserSettings {
  presets: ThemePreset[];
  automation: Automation;
}

interface ExtensionData {
  settings: UserSettings;
}

export function getMockData(): ExtensionData {
  return {
    settings: {
      presets: [],
      automation: {
        mode: "",
      },
    } as UserSettings,
  }
}

TS playground

const containedUndefinedType = some(typeSet, containsMissingType) ? missingType : undefinedType;
removeFromEach(typeSet, TypeFlags.Undefined);
result = getUnionType([getIntersectionType(typeSet), containedUndefinedType], UnionReduction.Literal, aliasSymbol, aliasTypeArguments);
}
else if (eachIsUnionContaining(typeSet, TypeFlags.Null)) {
else if (every(typeSet, t => !!(t.flags & TypeFlags.Union && ((t as UnionType).types[0].flags & TypeFlags.Null || (t as UnionType).types[1].flags & TypeFlags.Null)))) {

Choose a reason for hiding this comment

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

(lines:-5+0)

Why does this only need to check?

  • types[0] for TypeFlags.Undefined
  • types[0] | types[1] for TypeFlags.Null

Is there some rule/convention that null is first in UnionType#types if it's part of the union, unless undefined is in the union (which is really always first if it is part of the union)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, union types are sorted like this internally - so if a union contains undefined it has to be the first element etc.

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
None yet
Development

Successfully merging this pull request may close these issues.

Relating large unions of literal types performs poorly
7 participants