Skip to content

Properly handle null and undefined in getCommonSupertype #50021

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

Merged
merged 3 commits into from
Jul 24, 2022
Merged

Conversation

ahejlsberg
Copy link
Member

This is an alternative fix for #49938 that supercedes #49981.

@jakebailey I found it easier to put up a new PR. I've copied the tests from #49981. This PR more uniformly lifts undefined and null from the inference candidates and then adds them back later, plus it's a bit better at avoiding duplicate work. For example, it handles this case that otherwise is an error:

let v = null!;

declare function foo<T>(x: T, y: T): T;

const x = foo(v as 'a' | undefined, v as 'b');

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jul 23, 2022
@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 pack this

@ahejlsberg
Copy link
Member Author

@typescript-bot test this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 23, 2022

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

@ahejlsberg
Copy link
Member Author

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 23, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 23, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 23, 2022

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

@ahejlsberg
Copy link
Member Author

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 23, 2022

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

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..50021

Metric main 50021 Delta Best Worst
Angular - node (v14.15.1, x64)
Memory used 335,938k (± 0.01%) 335,962k (± 0.01%) +24k (+ 0.01%) 335,871k 336,005k
Parse Time 2.06s (± 0.65%) 2.06s (± 0.46%) -0.01s (- 0.39%) 2.04s 2.08s
Bind Time 0.90s (± 1.30%) 0.90s (± 0.72%) -0.00s (- 0.11%) 0.89s 0.91s
Check Time 5.82s (± 0.41%) 5.83s (± 0.41%) +0.01s (+ 0.19%) 5.77s 5.89s
Emit Time 6.38s (± 0.63%) 6.38s (± 0.63%) -0.01s (- 0.08%) 6.27s 6.43s
Total Time 15.17s (± 0.37%) 15.16s (± 0.43%) -0.01s (- 0.05%) 14.98s 15.24s
Compiler-Unions - node (v14.15.1, x64)
Memory used 193,129k (± 0.01%) 193,453k (± 0.38%) +324k (+ 0.17%) 193,001k 196,437k
Parse Time 0.85s (± 0.68%) 0.84s (± 0.43%) -0.00s (- 0.35%) 0.84s 0.85s
Bind Time 0.57s (± 1.01%) 0.57s (± 1.13%) +0.00s (+ 0.35%) 0.56s 0.59s
Check Time 6.71s (± 0.80%) 6.73s (± 0.58%) +0.03s (+ 0.39%) 6.64s 6.83s
Emit Time 2.49s (± 0.87%) 2.49s (± 0.82%) +0.01s (+ 0.28%) 2.46s 2.55s
Total Time 10.61s (± 0.54%) 10.64s (± 0.38%) +0.03s (+ 0.29%) 10.54s 10.74s
Monaco - node (v14.15.1, x64)
Memory used 325,664k (± 0.01%) 325,647k (± 0.01%) -17k (- 0.01%) 325,601k 325,702k
Parse Time 1.58s (± 0.48%) 1.59s (± 0.70%) +0.01s (+ 0.63%) 1.56s 1.61s
Bind Time 0.78s (± 0.71%) 0.79s (± 1.06%) +0.00s (+ 0.38%) 0.77s 0.81s
Check Time 5.71s (± 0.46%) 5.67s (± 0.36%) -0.03s (- 0.56%) 5.64s 5.73s
Emit Time 3.36s (± 0.58%) 3.34s (± 0.75%) -0.02s (- 0.60%) 3.28s 3.40s
Total Time 11.42s (± 0.36%) 11.38s (± 0.34%) -0.04s (- 0.32%) 11.34s 11.51s
TFS - node (v14.15.1, x64)
Memory used 288,822k (± 0.01%) 288,845k (± 0.01%) +23k (+ 0.01%) 288,795k 288,931k
Parse Time 1.33s (± 1.04%) 1.33s (± 1.76%) +0.00s (+ 0.23%) 1.29s 1.39s
Bind Time 0.77s (± 4.36%) 0.77s (± 4.05%) -0.00s (- 0.00%) 0.73s 0.85s
Check Time 5.36s (± 0.26%) 5.33s (± 0.50%) -0.03s (- 0.54%) 5.27s 5.39s
Emit Time 3.54s (± 1.81%) 3.62s (± 1.92%) +0.08s (+ 2.18%) 3.46s 3.73s
Total Time 10.99s (± 0.57%) 11.04s (± 0.73%) +0.05s (+ 0.48%) 10.82s 11.17s
material-ui - node (v14.15.1, x64)
Memory used 446,711k (± 0.01%) 446,730k (± 0.01%) +19k (+ 0.00%) 446,661k 446,786k
Parse Time 1.88s (± 0.62%) 1.88s (± 0.64%) -0.00s (- 0.05%) 1.85s 1.91s
Bind Time 0.72s (± 1.23%) 0.72s (± 0.97%) -0.01s (- 0.83%) 0.71s 0.74s
Check Time 13.18s (± 0.51%) 13.24s (± 0.58%) +0.07s (+ 0.51%) 13.11s 13.44s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.78s (± 0.47%) 15.85s (± 0.52%) +0.06s (+ 0.39%) 15.70s 16.04s
xstate - node (v14.15.1, x64)
Memory used 541,295k (± 0.01%) 541,308k (± 0.00%) +13k (+ 0.00%) 541,260k 541,341k
Parse Time 2.60s (± 0.29%) 2.61s (± 0.32%) +0.01s (+ 0.35%) 2.58s 2.62s
Bind Time 1.15s (± 1.24%) 1.14s (± 1.57%) -0.01s (- 0.61%) 1.10s 1.20s
Check Time 1.56s (± 0.49%) 1.56s (± 0.72%) -0.00s (- 0.06%) 1.53s 1.58s
Emit Time 0.07s (± 4.66%) 0.07s (± 4.13%) -0.00s (- 1.37%) 0.07s 0.08s
Total Time 5.38s (± 0.36%) 5.38s (± 0.41%) +0.01s (+ 0.11%) 5.35s 5.46s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 50021 10
Baseline main 10

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

Heya @ahejlsberg, I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here.

@typescript-bot
Copy link
Collaborator

@ahejlsberg
Great news! no new errors were found between main..refs/pull/50021/merge

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jul 23, 2022

Hey @ahejlsberg, 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/130297/artifacts?artifactName=tgz&fileId=5B6A9298038EC2E4EEE17420D8BA1C609540E927E60F49CC71CBE61DF68A3F3902&fileName=/typescript-4.8.0-insiders.20220723.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/[email protected]".;

@ahejlsberg
Copy link
Member Author

Tests and performance all look good. No new errors, but one error went away in RWC because of better inference. I think this is a good fix.

@ahejlsberg
Copy link
Member Author

Latest commit adds more tests that now succeed but previously failed.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

Looks great. I should have known that literals needed the same treatment!

(filterType is another helper I need to commit to memory as existing.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants