Skip to content

CFA for dependent parameters typed by generic constraints - #48411

Merged
Anders Hejlsberg (ahejlsberg) merged 3 commits into
mainfrom
fix48345
Mar 30, 2022
Merged

CFA for dependent parameters typed by generic constraints#48411
Anders Hejlsberg (ahejlsberg) merged 3 commits into
mainfrom
fix48345

Conversation

@ahejlsberg

Copy link
Copy Markdown
Member

Fixes#48345.

@ahejlsberg

Copy link
Copy Markdown
MemberAuthor

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 24, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the diff-based community code test suite on this PR at 44e8d72. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 24, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized Definitely Typed test suite on this PR at 44e8d72. You can monitor the build here.

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 24, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the abridged perf test suite on this PR at 44e8d72. You can monitor the build here.

Update: The results are in!

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 24, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the extended test suite on this PR at 44e8d72. You can monitor the build here.

@typescript-bot

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg)
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..48411

Metricmain48411DeltaBestWorst
Angular - node (v14.15.1, x64)
Memory used332,462k (± 0.01%)332,480k (± 0.01%)+18k (+ 0.01%)332,434k332,546k
Parse Time2.02s (± 0.45%)2.02s (± 0.24%)-0.00s (- 0.10%)2.01s2.03s
Bind Time0.87s (± 0.60%)0.87s (± 0.92%)-0.00s (- 0.12%)0.85s0.89s
Check Time5.61s (± 0.42%)5.61s (± 0.44%)+0.00s (+ 0.02%)5.55s5.66s
Emit Time6.25s (± 0.44%)6.29s (± 0.58%)+0.04s (+ 0.61%)6.20s6.37s
Total Time14.75s (± 0.30%)14.79s (± 0.38%)+0.04s (+ 0.25%)14.64s14.89s
Compiler-Unions - node (v14.15.1, x64)
Memory used194,944k (± 0.38%)194,520k (± 0.56%)-424k (- 0.22%)191,255k195,285k
Parse Time0.86s (± 0.75%)0.86s (± 0.61%)+0.00s (+ 0.12%)0.85s0.87s
Bind Time0.56s (± 0.80%)0.56s (± 0.80%)0.00s ( 0.00%)0.55s0.57s
Check Time7.51s (± 0.64%)7.54s (± 0.65%)+0.03s (+ 0.36%)7.46s7.67s
Emit Time2.50s (± 0.86%)2.49s (± 0.79%)-0.01s (- 0.28%)2.45s2.54s
Total Time11.42s (± 0.46%)11.45s (± 0.42%)+0.02s (+ 0.18%)11.38s11.57s
Monaco - node (v14.15.1, x64)
Memory used325,416k (± 0.01%)325,425k (± 0.01%)+9k (+ 0.00%)325,391k325,474k
Parse Time1.58s (± 0.60%)1.57s (± 0.25%)-0.01s (- 0.44%)1.56s1.58s
Bind Time0.77s (± 0.38%)0.77s (± 0.64%)+0.00s (+ 0.26%)0.77s0.79s
Check Time5.51s (± 0.28%)5.49s (± 0.53%)-0.02s (- 0.38%)5.40s5.54s
Emit Time3.31s (± 0.51%)3.29s (± 0.61%)-0.02s (- 0.64%)3.24s3.32s
Total Time11.17s (± 0.20%)11.12s (± 0.31%)-0.05s (- 0.43%)11.00s11.18s
TFS - node (v14.15.1, x64)
Memory used288,905k (± 0.01%)288,894k (± 0.00%)-11k (- 0.00%)288,853k288,911k
Parse Time1.32s (± 1.17%)1.32s (± 1.58%)+0.00s (+ 0.23%)1.29s1.38s
Bind Time0.73s (± 0.92%)0.73s (± 0.64%)+0.00s (+ 0.41%)0.72s0.74s
Check Time5.15s (± 0.38%)5.16s (± 0.49%)+0.00s (+ 0.10%)5.08s5.21s
Emit Time3.45s (± 1.71%)3.50s (± 2.32%)+0.05s (+ 1.42%)3.36s3.66s
Total Time10.65s (± 0.62%)10.71s (± 1.08%)+0.06s (+ 0.56%)10.48s10.95s
material-ui - node (v14.15.1, x64)
Memory used453,635k (± 0.01%)453,586k (± 0.04%)-48k (- 0.01%)452,939k453,713k
Parse Time1.86s (± 0.26%)1.85s (± 0.41%)-0.00s (- 0.11%)1.84s1.88s
Bind Time0.71s (± 0.91%)0.70s (± 1.08%)-0.00s (- 0.56%)0.69s0.72s
Check Time20.38s (± 0.70%)20.51s (± 0.64%)+0.13s (+ 0.62%)20.33s20.88s
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)0.00s ( NaN%)0.00s0.00s
Total Time22.95s (± 0.62%)23.07s (± 0.60%)+0.12s (+ 0.51%)22.89s23.48s
xstate - node (v14.15.1, x64)
Memory used534,101k (± 0.00%)534,087k (± 0.00%)-14k (- 0.00%)534,043k534,118k
Parse Time2.56s (± 0.38%)2.57s (± 0.48%)+0.00s (+ 0.20%)2.54s2.60s
Bind Time1.15s (± 0.66%)1.15s (± 0.72%)+0.00s (+ 0.09%)1.13s1.17s
Check Time1.51s (± 0.40%)1.52s (± 0.49%)+0.01s (+ 0.33%)1.51s1.54s
Emit Time0.07s (± 0.00%)0.07s (± 0.00%)0.00s ( 0.00%)0.07s0.07s
Total Time5.29s (± 0.17%)5.31s (± 0.35%)+0.01s (+ 0.26%)5.27s5.36s
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)
BenchmarkNameIterations
Current4841110
Baselinemain10

Developer Information:

Download Benchmark

@typescript-bot

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg)
Great news! no new errors were found between main..refs/pull/48411/merge

const contextualSignature = getContextualSignature(func);
if (contextualSignature && contextualSignature.parameters.length === 1 && signatureHasRestParameter(contextualSignature)) {
const restType = getTypeOfSymbol(contextualSignature.parameters[0]);
const restType = getReducedApparentType(getTypeOfSymbol(contextualSignature.parameters[0]));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A very easy fix indeed 😅

@ahejlsberg

Copy link
Copy Markdown
MemberAuthor

@awerlogus

Copy link
Copy Markdown

For test suite:

functiona<Textends'a'|'b'>(arg: T){if(arg==='a'){// Expected: 'a'// Got: T extends "a" | "b"arg}}

Sidharth Vinod (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)
...
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 22, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: TeamFor Milestone BugPRs that fix a bug with a specific milestone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Control Flow Analysis for Dependent Parameters doesn't work when the parameters are generic

5 participants

@ahejlsberg@typescript-bot@awerlogus@RyanCavanaugh@Andarist