Skip to content

Grab the left type when narrowing by in operator lazily #54795

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 2 commits into from
Jul 19, 2023

Conversation

Andarist
Copy link
Contributor

fixes #54790

@jakebailey
Copy link
Member

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 27, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 27, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 27, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 27, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 27, 2023

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 27, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 27, 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/155690/artifacts?artifactName=tgz&fileId=D086F55C68FDC5199867199BCBEBF0E7F2FB7693264284A6771255784B22A77B02&fileName=/typescript-5.2.0-insiders.20230627.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]".;

@typescript-bot
Copy link
Collaborator

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

There were infrastructure failures potentially unrelated to your change:

  • 1 instance of "Unknown failure"
  • 1 instance of "Package install failed"

Otherwise...

Something interesting changed - please have a look.

Details

rxjs-src

/mnt/ts_downloads/rxjs-src/build.sh

  • [NEW] error TS2428: All declarations of 'WeakMap' must have identical type parameters.
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-54795/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
  • [MISSING] error TS2428: All declarations of 'WeakMap' must have identical type parameters.
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.collection.d.ts(63,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.iterable.d.ts(162,11)
    • /home/vsts/work/1/s/typescript-main/lib/lib.es2015.symbol.wellknown.d.ts(140,11)

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, it looks like the DT test run failed. Please check the log for more details.
You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..54795

Metric main 54795 Delta Best Worst p-value
Angular - node (v16.17.1, x64)
Memory used 366,137k (± 0.01%) 366,115k (± 0.01%) ~ 366,072k 366,195k p=0.229 n=6
Parse Time 3.58s (± 0.37%) 3.60s (± 0.79%) ~ 3.57s 3.65s p=0.319 n=6
Bind Time 1.18s (± 0.35%) 1.18s (± 0.76%) ~ 1.17s 1.19s p=0.787 n=6
Check Time 9.68s (± 0.57%) 9.64s (± 0.41%) ~ 9.59s 9.69s p=0.170 n=6
Emit Time 8.00s (± 0.83%) 7.99s (± 0.42%) ~ 7.95s 8.03s p=0.808 n=6
Total Time 22.43s (± 0.51%) 22.41s (± 0.37%) ~ 22.31s 22.53s p=0.809 n=6
Compiler-Unions - node (v16.17.1, x64)
Memory used 192,799k (± 0.02%) 192,764k (± 0.03%) ~ 192,699k 192,860k p=0.378 n=6
Parse Time 1.59s (± 0.76%) 1.58s (± 1.48%) ~ 1.55s 1.61s p=1.000 n=6
Bind Time 0.82s (± 0.63%) 0.82s (± 0.50%) ~ 0.81s 0.82s p=0.595 n=6
Check Time 10.06s (± 0.64%) 10.10s (± 0.44%) ~ 10.01s 10.14s p=0.228 n=6
Emit Time 3.02s (± 1.59%) 3.00s (± 0.56%) ~ 2.98s 3.02s p=0.411 n=6
Total Time 15.48s (± 0.45%) 15.50s (± 0.27%) ~ 15.43s 15.54s p=0.574 n=6
Monaco - node (v16.17.1, x64)
Memory used 346,075k (± 0.00%) 346,060k (± 0.01%) ~ 346,034k 346,087k p=0.199 n=6
Parse Time 2.73s (± 0.31%) 2.74s (± 0.30%) ~ 2.73s 2.75s p=0.718 n=6
Bind Time 1.09s (± 0.47%) 1.09s (± 0.90%) ~ 1.07s 1.10s p=0.504 n=6
Check Time 7.87s (± 0.48%) 7.87s (± 0.36%) ~ 7.84s 7.92s p=0.936 n=6
Emit Time 4.48s (± 0.62%) 4.46s (± 0.46%) ~ 4.44s 4.50s p=0.219 n=6
Total Time 16.18s (± 0.35%) 16.16s (± 0.16%) ~ 16.12s 16.19s p=0.171 n=6
TFS - node (v16.17.1, x64)
Memory used 300,200k (± 0.01%) 300,229k (± 0.00%) ~ 300,217k 300,243k p=0.054 n=6
Parse Time 2.16s (± 0.35%) 2.17s (± 0.24%) +0.02s (+ 0.69%) 2.17s 2.18s p=0.009 n=6
Bind Time 1.23s (± 0.61%) 1.25s (± 0.51%) +0.02s (+ 1.49%) 1.24s 1.26s p=0.006 n=6
Check Time 7.30s (± 0.57%) 7.32s (± 0.41%) ~ 7.26s 7.34s p=0.376 n=6
Emit Time 4.34s (± 0.77%) 4.35s (± 0.64%) ~ 4.30s 4.38s p=0.685 n=6
Total Time 15.03s (± 0.29%) 15.09s (± 0.20%) +0.06s (+ 0.38%) 15.06s 15.13s p=0.029 n=6
material-ui - node (v16.17.1, x64)
Memory used 481,685k (± 0.01%) 481,593k (± 0.01%) -92k (- 0.02%) 481,487k 481,678k p=0.020 n=6
Parse Time 3.25s (± 0.41%) 3.26s (± 0.30%) ~ 3.25s 3.27s p=0.168 n=6
Bind Time 0.96s (± 0.57%) 0.95s (± 0.79%) ~ 0.94s 0.96s p=0.476 n=6
Check Time 18.26s (± 0.32%) 17.96s (± 0.43%) -0.30s (- 1.62%) 17.88s 18.09s p=0.005 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 22.47s (± 0.24%) 22.18s (± 0.38%) -0.29s (- 1.28%) 22.07s 22.30s p=0.005 n=6
xstate - node (v16.17.1, x64)
Memory used 561,208k (± 0.02%) 561,149k (± 0.01%) ~ 561,048k 561,275k p=0.423 n=6
Parse Time 4.01s (± 0.58%) 3.99s (± 0.31%) ~ 3.98s 4.01s p=0.466 n=6
Bind Time 1.74s (± 0.67%) 1.74s (± 0.59%) ~ 1.72s 1.75s p=0.801 n=6
Check Time 3.05s (± 0.41%) 3.04s (± 0.61%) ~ 3.03s 3.08s p=0.232 n=6
Emit Time 0.09s (± 0.00%) 0.09s (± 5.53%) ~ 0.09s 0.10s p=0.174 n=6
Total Time 8.89s (± 0.38%) 8.86s (± 0.25%) ~ 8.84s 8.90s p=0.197 n=6
System
Machine Namets-ci-ubuntu
Platformlinux 5.4.0-148-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 54795 6
Baseline main 6

Developer Information:

Download Benchmark

@jakebailey
Copy link
Member

@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Jun 28, 2023

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

Hey @jakebailey, the results of running the DT tests are ready.
Everything looks the same!
You can check the log here.

Comment on lines 27171 to 27174
if (containsMissingType(type) && isAccessExpression(reference) && isMatchingReference(reference.expression, target) && (leftType = getTypeOfExpression(expr.left)).flags & TypeFlags.StringOrNumberLiteralOrUnique &&
getAccessedPropertyName(reference) === getPropertyNameFromType(leftType as StringLiteralType | NumberLiteralType | UniqueESSymbolType)) {
return getTypeWithFacts(type, assumeTrue ? TypeFacts.NEUndefined : TypeFacts.EQUndefined);
}
Copy link
Contributor

@rbuckton rbuckton Jul 18, 2023

Choose a reason for hiding this comment

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

Since there is no else you can just have two nested if statements to avoid an assignment deep in a condition, and you can use isTypeUsableAsPropertyName to avoid the cast:

Suggested change
if (containsMissingType(type) && isAccessExpression(reference) && isMatchingReference(reference.expression, target) && (leftType = getTypeOfExpression(expr.left)).flags & TypeFlags.StringOrNumberLiteralOrUnique &&
getAccessedPropertyName(reference) === getPropertyNameFromType(leftType as StringLiteralType | NumberLiteralType | UniqueESSymbolType)) {
return getTypeWithFacts(type, assumeTrue ? TypeFacts.NEUndefined : TypeFacts.EQUndefined);
}
if (containsMissingType(type) && isAccessExpression(reference) && isMatchingReference(reference.expression, target)) {
const leftType = getTypeOfExpression(expr.left);
if (isTypeUsableAsPropertyName(leftType) && getAccessedPropertyName(reference) === getPropertyNameFromType(leftType)) {
return getTypeWithFacts(type, assumeTrue ? TypeFacts.NEUndefined : TypeFacts.EQUndefined);
}
}

You can do the same for the other if below this as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

adjusted the code as requested, I'm not sure why I've written it this way - it was bizarre 😅

@Andarist Andarist requested a review from rbuckton July 19, 2023 08:30
@rbuckton rbuckton merged commit adf5e84 into microsoft:main Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Backlog Bug PRs that fix a backlog bug
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

implicitly 'any' type error despite no circularity in assignment and being assigned a template literal
5 participants