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

No contextual typing from return types for boolean literals #48380

Merged
merged 3 commits into from
Mar 30, 2022
Merged

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Mar 23, 2022

This PR makes a small change to contextual typing of boolean literals: When a boolean literal in a function argument expression is contextually typed by a type variable, and type boolean was inferred for that type variable through function return type inference, we remove boolean from the instantiated contextual type, thus causing the boolean literal to widen to type boolean (as it would had it not been contextually typed).

Fixes #48363.

Also fixes issue mentioned here.

@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
Copy link
Collaborator

typescript-bot commented Mar 23, 2022

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 23, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 23, 2022

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Mar 23, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..48380

Metric main 48380 Delta Best Worst
Angular - node (v14.15.1, x64)
Memory used 332,464k (± 0.01%) 332,480k (± 0.01%) +16k (+ 0.00%) 332,420k 332,541k
Parse Time 2.03s (± 0.64%) 2.03s (± 0.59%) +0.00s (+ 0.00%) 2.00s 2.05s
Bind Time 0.87s (± 0.64%) 0.87s (± 0.75%) -0.00s (- 0.46%) 0.86s 0.89s
Check Time 5.60s (± 0.56%) 5.61s (± 0.60%) +0.01s (+ 0.20%) 5.53s 5.68s
Emit Time 6.32s (± 0.87%) 6.30s (± 0.73%) -0.02s (- 0.27%) 6.18s 6.40s
Total Time 14.82s (± 0.54%) 14.81s (± 0.41%) -0.01s (- 0.06%) 14.65s 14.92s
Compiler-Unions - node (v14.15.1, x64)
Memory used 194,150k (± 0.62%) 193,616k (± 0.62%) -534k (- 0.28%) 191,933k 195,284k
Parse Time 0.85s (± 0.43%) 0.86s (± 0.98%) +0.01s (+ 0.70%) 0.85s 0.89s
Bind Time 0.56s (± 0.61%) 0.56s (± 0.84%) +0.00s (+ 0.54%) 0.55s 0.57s
Check Time 7.43s (± 0.55%) 7.49s (± 1.01%) +0.06s (+ 0.81%) 7.36s 7.72s
Emit Time 2.48s (± 0.82%) 2.50s (± 0.88%) +0.01s (+ 0.56%) 2.43s 2.55s
Total Time 11.33s (± 0.48%) 11.41s (± 0.77%) +0.08s (+ 0.71%) 11.26s 11.67s
Monaco - node (v14.15.1, x64)
Memory used 325,419k (± 0.01%) 325,439k (± 0.01%) +20k (+ 0.01%) 325,400k 325,505k
Parse Time 1.58s (± 0.55%) 1.58s (± 0.92%) +0.00s (+ 0.32%) 1.55s 1.62s
Bind Time 0.78s (± 0.95%) 0.78s (± 0.64%) -0.01s (- 0.64%) 0.77s 0.79s
Check Time 5.46s (± 0.30%) 5.48s (± 0.48%) +0.02s (+ 0.42%) 5.43s 5.55s
Emit Time 3.33s (± 1.81%) 3.35s (± 0.73%) +0.02s (+ 0.72%) 3.30s 3.40s
Total Time 11.15s (± 0.55%) 11.19s (± 0.34%) +0.04s (+ 0.39%) 11.10s 11.25s
TFS - node (v14.15.1, x64)
Memory used 288,910k (± 0.01%) 288,885k (± 0.01%) -24k (- 0.01%) 288,848k 288,937k
Parse Time 1.33s (± 0.87%) 1.32s (± 1.22%) -0.01s (- 1.12%) 1.29s 1.37s
Bind Time 0.73s (± 0.45%) 0.74s (± 1.01%) +0.01s (+ 0.96%) 0.72s 0.75s
Check Time 5.11s (± 0.44%) 5.14s (± 0.71%) +0.03s (+ 0.61%) 5.06s 5.24s
Emit Time 3.51s (± 1.87%) 3.53s (± 1.69%) +0.02s (+ 0.66%) 3.42s 3.66s
Total Time 10.68s (± 0.74%) 10.72s (± 0.84%) +0.04s (+ 0.41%) 10.58s 11.02s
material-ui - node (v14.15.1, x64)
Memory used 453,530k (± 0.06%) 453,552k (± 0.07%) +22k (+ 0.00%) 452,278k 453,728k
Parse Time 1.86s (± 0.44%) 1.86s (± 0.42%) -0.00s (- 0.27%) 1.85s 1.88s
Bind Time 0.70s (± 1.17%) 0.70s (± 0.85%) +0.00s (+ 0.14%) 0.69s 0.72s
Check Time 20.49s (± 1.00%) 20.41s (± 1.27%) -0.09s (- 0.42%) 19.63s 20.95s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 23.06s (± 0.87%) 22.97s (± 1.15%) -0.09s (- 0.40%) 22.18s 23.51s
xstate - node (v14.15.1, x64)
Memory used 535,379k (± 0.01%) 535,376k (± 0.01%) -3k (- 0.00%) 535,313k 535,435k
Parse Time 2.57s (± 0.55%) 2.56s (± 0.41%) -0.01s (- 0.31%) 2.55s 2.59s
Bind Time 1.14s (± 0.71%) 1.14s (± 0.81%) -0.00s (- 0.09%) 1.12s 1.17s
Check Time 1.51s (± 0.68%) 1.51s (± 0.74%) -0.00s (- 0.33%) 1.49s 1.53s
Emit Time 0.07s (± 3.14%) 0.07s (± 0.00%) -0.00s (- 1.41%) 0.07s 0.07s
Total Time 5.30s (± 0.35%) 5.29s (± 0.22%) -0.01s (- 0.25%) 5.25s 5.31s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory4 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 48380 10
Baseline main 10

Developer Information:

Download Benchmark

@ahejlsberg
Copy link
Member Author

ahejlsberg commented Mar 23, 2022

All tests are clean and performance is unaffected. I think this one is good to merge.

EDIT: Actually, a few changes in the extended test suite, but all to be expected. Three of the changes are errors that go away in immutable.js (foldLeft with a boolean literal seed).

@typescript-bot typescript-bot added For Milestone Bug PRs that fix a bug with a specific milestone and removed For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Mar 23, 2022
@ahejlsberg ahejlsberg merged commit 3f483d8 into main Mar 30, 2022
@ahejlsberg ahejlsberg deleted the fix48363-2 branch March 30, 2022 23:32
sidharthv96 added a commit to sidharthv96/TypeScript that referenced this pull request Apr 1, 2022
* upstream/main: (473 commits)
  Correct node used for isDefinition calculation (microsoft#48499)
  fix(48405): emit dummy members from a mapped type (microsoft#48481)
  CFA for dependent parameters typed by generic constraints (microsoft#48411)
  No contextual typing from return types for boolean literals (microsoft#48380)
  fix(47733): omit JSDoc comment template suggestion on node with existing JSDoc (microsoft#47748)
  Ensure that we copy empty NodeArrays during transform (microsoft#48490)
  Add a new compiler option `moduleSuffixes` to expand the node module resolver's search algorithm (microsoft#48189)
  feat(27615): Add missing member fix should work for type literals (microsoft#47212)
  Add label details to completion entry (microsoft#48429)
  Enable method signature completion for object literals (microsoft#48168)
  Fix string literal completions when a partially-typed string fixes inference to a type parameter (microsoft#48410)
  fix(48445): show errors on type-only import/export specifiers in JavaScript files (microsoft#48449)
  Fix newline inserted in empty block at end of formatting range (microsoft#48463)
  Prevent looking up symbol for as const from triggering an error (microsoft#48464)
  Revise accessor resolution logic and error reporting (microsoft#48459)
  fix(48166): skip checking module.exports in a truthiness call expression (microsoft#48337)
  LEGO: Merge pull request 48450
  LEGO: Merge pull request 48436
  fix(48031): show circularity error for self referential get accessor annotations (microsoft#48050)
  Revert "Fix contextual discrimination for omitted members (microsoft#43937)" (microsoft#48426)
  ...
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.

Inconsistent boolean literal types
3 participants