Skip to content

Conversation

weswigham
Copy link
Member

Fixes #17023 - binding patterns correctly have their initial type bound to the narrowed type of the narrowed property indicated by the binding pattern. Previously, we were not getting their flow type when looking for their initial type (and the flow logic wasn't setup to look for references equivalent to a nested binding element).

function getBindingElementNameText(element: BindingElement): string | undefined {
if (element.parent.kind === SyntaxKind.ObjectBindingPattern) {
const name = element.propertyName || element.name;
if (isComputedNonLiteralName(name as PropertyName)) return undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Consider moving this down to the analogous case clause to make it clearer that it's safe to assert name.expression as LiteralExpression

@sandersn
Copy link
Member

Can you make sure that performance doesn't get worse with this change? This would only apply for code bases that use binding patterns, of course, so I guess our own compiler would be a good test case. Maybe?

if (node.kind === SyntaxKind.BindingElement) {
const key = node.parent.parent.kind === SyntaxKind.BindingElement ? getFlowCacheKey(node.parent.parent) : isApparentTypePosition(node.parent.parent) ? "@<initializer>" : "<initializer>";
const text = getBindingElementNameText(node as BindingElement);
return key && text && key + "." + text;
Copy link
Member

Choose a reason for hiding this comment

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

it sounds like from our discussion at lunch that you came up with a better way to make a key.

@weswigham
Copy link
Member Author

@sandersn I've done my work to find a better cache key (now it follows the same trail isMatchingReference does). As far as perf goes, on my machine - the specified perf benchmark on this PR:

Scenarios: Compiler
Hosts: node (v8.1.2, x64)
  [1/1] Measuring scenario 'Compiler - node (v8.1.2, x64)'...
    [1/5] Compiled scenario 'Compiler - node (v8.1.2, x64)' in 4.27s.
    [2/5] Compiled scenario 'Compiler - node (v8.1.2, x64)' in 4.34s.
    [3/5] Compiled scenario 'Compiler - node (v8.1.2, x64)' in 4.29s.
    [4/5] Compiled scenario 'Compiler - node (v8.1.2, x64)' in 4.26s.
    [5/5] Compiled scenario 'Compiler - node (v8.1.2, x64)' in 4.36s.
┌─────────────┬─────────────────────┬──────────┬──────────┐
│ Project     │             Average │     Best │    Worst │
╞═════════════╧═════════════════════╧══════════╧══════════╡
│ Compiler - node (v8.1.2, x64)                           │
├─────────────┬─────────────────────┬──────────┬──────────┤
│ Memory used │ 169,395k (±  0.03%) │ 169,325k │ 169,424k │
│ Parse Time  │    0.76s (±  4.41%) │    0.74s │    0.81s │
│ Bind Time   │    0.36s (±  1.73%) │    0.36s │    0.37s │
│ Check Time  │    1.98s (±  1.76%) │    1.96s │    2.03s │
│ Emit Time   │    1.20s (±  1.28%) │    1.19s │    1.22s │
├─────────────┼─────────────────────┼──────────┼──────────┤
│ Total Time  │    4.30s (±  1.17%) │    4.26s │    4.36s │
└─────────────┴─────────────────────┴──────────┴──────────┘

Master, de9a67f:

Scenarios: Compiler
Hosts: node (v8.1.2, x64)
  [1/1] Measuring scenario 'Compiler - node (v8.1.2, x64)'...
    [1/5] Compiled scenario 'Compiler - node (v8.1.2, x64)' in 4.26s.
    [2/5] Compiled scenario 'Compiler - node (v8.1.2, x64)' in 4.31s.
    [3/5] Compiled scenario 'Compiler - node (v8.1.2, x64)' in 4.34s.
    [4/5] Compiled scenario 'Compiler - node (v8.1.2, x64)' in 4.28s.
    [5/5] Compiled scenario 'Compiler - node (v8.1.2, x64)' in 4.33s.
┌─────────────┬─────────────────────┬──────────┬──────────┐
│ Project     │             Average │     Best │    Worst │
╞═════════════╧═════════════════════╧══════════╧══════════╡
│ Compiler - node (v8.1.2, x64)                           │
├─────────────┬─────────────────────┬──────────┬──────────┤
│ Memory used │ 169,356k (±  0.02%) │ 169,322k │ 169,398k │
│ Parse Time  │    0.75s (±  3.31%) │    0.72s │    0.77s │
│ Bind Time   │    0.37s (±  2.81%) │    0.36s │    0.38s │
│ Check Time  │    1.98s (±  1.13%) │    1.95s │    1.99s │
│ Emit Time   │    1.21s (±  4.10%) │    1.16s │    1.26s │
├─────────────┼─────────────────────┼──────────┼──────────┤
│ Total Time  │    4.30s (±  0.90%) │    4.26s │    4.34s │
└─────────────┴─────────────────────┴──────────┴──────────┘

Together:

┌─────────────┬─────────────────────┬─────────────────────┬───────────────────┬──────────┬──────────┐
│ Project     │            Baseline │             Current │             Delta │     Best │    Worst │
╞═════════════╧═════════════════════╧═════════════════════╧═══════════════════╧══════════╧══════════╡
│ Compiler - node (v8.1.2, x64)                                                                     │
├─────────────┬─────────────────────┬─────────────────────┬───────────────────┬──────────┬──────────┤
│ Memory used │ 169,356k (±  0.02%) │ 169,395k (±  0.03%) │   +39k (+  0.02%) │ 169,325k │ 169,424k │
│ Parse Time  │    0.75s (±  3.31%) │    0.76s (±  4.41%) │ +0.01s (+  1.06%) │    0.74s │    0.81s │
│ Bind Time   │    0.37s (±  2.81%) │    0.36s (±  1.73%) │ -0.00s (-  0.55%) │    0.36s │    0.37s │
│ Check Time  │    1.98s (±  1.13%) │    1.98s (±  1.76%) │ +0.00s (+  0.10%) │    1.96s │    2.03s │
│ Emit Time   │    1.21s (±  4.10%) │    1.20s (±  1.28%) │ -0.01s (-  0.66%) │    1.19s │    1.22s │
├─────────────┼─────────────────────┼─────────────────────┼───────────────────┼──────────┼──────────┤
│ Total Time  │    4.30s (±  0.90%) │    4.30s (±  1.17%) │ -0.00s (-  0.00%) │    4.26s │    4.36s │
└─────────────┴─────────────────────┴─────────────────────┴───────────────────┴──────────┴──────────┘

So... no difference.

@weswigham weswigham merged commit 6955142 into microsoft:master Jul 18, 2017
@weswigham weswigham deleted the fix-17023 branch August 17, 2017 23:47
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants