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

Fixed a regression with reporting unused parameters in potential predicates #58514

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Andarist
Copy link
Contributor

fixes #58493

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label May 13, 2024
@jakebailey
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented May 13, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started ✅ Results
user test this ✅ Started ✅ Results
run dt ✅ Started ✅ Results
perf test this faster ✅ Started 👀 Results

@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.

@typescript-bot
Copy link
Collaborator

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

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 30 30 ~ ~ ~ p=1.000 n=6
Symbols 62,154 62,154 ~ ~ ~ p=1.000 n=6
Types 50,248 50,248 ~ ~ ~ p=1.000 n=6
Memory used 194,058k (± 1.03%) 193,425k (± 0.99%) ~ 192,164k 195,959k p=0.173 n=6
Parse Time 1.30s (± 0.69%) 1.30s (± 1.57%) ~ 1.27s 1.32s p=1.000 n=6
Bind Time 0.72s 0.72s ~ ~ ~ p=1.000 n=6
Check Time 9.55s (± 0.34%) 9.54s (± 0.38%) ~ 9.48s 9.58s p=0.627 n=6
Emit Time 2.65s (± 0.44%) 2.64s (± 1.01%) ~ 2.59s 2.66s p=0.236 n=6
Total Time 14.22s (± 0.22%) 14.19s (± 0.36%) ~ 14.13s 14.26s p=0.377 n=6
angular-1 - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 944,110 944,110 ~ ~ ~ p=1.000 n=6
Types 407,140 407,140 ~ ~ ~ p=1.000 n=6
Memory used 1,222,106k (± 0.00%) 1,222,086k (± 0.01%) ~ 1,222,021k 1,222,196k p=0.471 n=6
Parse Time 6.77s (± 0.59%) 6.78s (± 0.62%) ~ 6.73s 6.84s p=1.000 n=6
Bind Time 1.87s (± 0.44%) 1.88s (± 0.52%) ~ 1.87s 1.89s p=0.498 n=6
Check Time 31.15s (± 0.27%) 31.26s (± 0.21%) +0.11s (+ 0.34%) 31.14s 31.32s p=0.045 n=6
Emit Time 14.72s (± 0.53%) 14.80s (± 0.10%) ~ 14.78s 14.82s p=0.064 n=6
Total Time 54.51s (± 0.30%) 54.72s (± 0.13%) +0.20s (+ 0.38%) 54.59s 54.80s p=0.013 n=6
mui-docs - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 1,961,349 1,961,349 ~ ~ ~ p=1.000 n=6
Types 696,910 696,910 ~ ~ ~ p=1.000 n=6
Memory used 1,778,083k (± 0.00%) 1,778,093k (± 0.00%) ~ 1,778,052k 1,778,114k p=0.575 n=6
Parse Time 6.77s (± 0.18%) 6.78s (± 0.29%) ~ 6.76s 6.81s p=0.797 n=6
Bind Time 2.30s (± 0.65%) 2.30s (± 0.53%) ~ 2.29s 2.32s p=1.000 n=6
Check Time 56.95s (± 0.37%) 57.10s (± 0.31%) ~ 56.85s 57.34s p=0.261 n=6
Emit Time 0.14s 0.14s ~ ~ ~ p=1.000 n=6
Total Time 66.17s (± 0.32%) 66.32s (± 0.27%) ~ 66.07s 66.56s p=0.261 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,221,120 1,221,121 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 259,503 259,503 ~ ~ ~ p=1.000 n=6
Memory used 2,336,352k (± 0.03%) 2,337,014k (± 0.04%) ~ 2,336,098k 2,338,264k p=0.173 n=6
Parse Time 5.04s (± 1.54%) 5.05s (± 0.38%) ~ 5.03s 5.08s p=0.471 n=6
Bind Time 1.88s (± 0.64%) 1.87s (± 0.99%) ~ 1.85s 1.89s p=0.934 n=6
Check Time 33.78s (± 0.73%) 33.81s (± 0.21%) ~ 33.73s 33.91s p=0.748 n=6
Emit Time 2.68s (± 3.44%) 2.63s (± 1.61%) ~ 2.57s 2.69s p=0.128 n=6
Total Time 43.41s (± 0.41%) 43.38s (± 0.26%) ~ 43.25s 43.56s p=0.936 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,221,120 1,221,121 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 259,503 259,503 ~ ~ ~ p=1.000 n=6
Memory used 2,412,625k (± 0.02%) 2,413,238k (± 0.03%) ~ 2,412,040k 2,414,007k p=0.093 n=6
Parse Time 6.28s (± 1.24%) 6.20s (± 1.64%) ~ 6.01s 6.29s p=0.173 n=6
Bind Time 2.04s (± 0.67%) 2.06s (± 0.81%) +0.02s (+ 1.15%) 2.04s 2.08s p=0.043 n=6
Check Time 40.20s (± 0.29%) 40.31s (± 0.42%) ~ 40.08s 40.49s p=0.336 n=6
Emit Time 3.18s (± 2.27%) 3.11s (± 2.90%) ~ 3.00s 3.26s p=0.173 n=6
Total Time 51.71s (± 0.26%) 51.68s (± 0.45%) ~ 51.31s 51.91s p=0.936 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 256,716 256,717 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 104,580 104,580 ~ ~ ~ p=1.000 n=6
Memory used 425,973k (± 0.02%) 425,883k (± 0.01%) ~ 425,813k 425,966k p=0.093 n=6
Parse Time 4.17s (± 0.58%) 4.16s (± 0.42%) ~ 4.13s 4.18s p=0.168 n=6
Bind Time 1.62s (± 0.50%) 1.63s (± 0.85%) ~ 1.61s 1.65s p=0.270 n=6
Check Time 22.15s (± 0.49%) 22.11s (± 0.15%) ~ 22.06s 22.15s p=1.000 n=6
Emit Time 1.70s (± 1.05%) 1.73s (± 1.08%) ~ 1.71s 1.75s p=0.056 n=6
Total Time 29.64s (± 0.36%) 29.61s (± 0.17%) ~ 29.54s 29.67s p=0.936 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 35 35 ~ ~ ~ p=1.000 n=6
Symbols 224,575 224,575 ~ ~ ~ p=1.000 n=6
Types 93,785 93,785 ~ ~ ~ p=1.000 n=6
Memory used 369,887k (± 0.02%) 369,847k (± 0.04%) ~ 369,711k 370,106k p=0.230 n=6
Parse Time 2.85s (± 0.67%) 2.84s (± 0.82%) ~ 2.81s 2.88s p=0.624 n=6
Bind Time 1.58s (± 1.01%) 1.58s (± 0.80%) ~ 1.56s 1.59s p=0.869 n=6
Check Time 15.64s (± 0.44%) 15.64s (± 0.24%) ~ 15.60s 15.70s p=1.000 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.07s (± 0.41%) 20.06s (± 0.24%) ~ 19.99s 20.14s p=1.000 n=6
vscode - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,822,415 2,822,415 ~ ~ ~ p=1.000 n=6
Types 957,541 957,541 ~ ~ ~ p=1.000 n=6
Memory used 2,994,941k (± 0.00%) 2,995,024k (± 0.00%) ~ 2,994,981k 2,995,122k p=0.128 n=6
Parse Time 13.82s (± 0.19%) 13.82s (± 0.13%) ~ 13.79s 13.84s p=0.508 n=6
Bind Time 4.14s (± 0.33%) 4.14s (± 0.12%) ~ 4.14s 4.15s p=0.928 n=6
Check Time 73.44s (± 0.46%) 73.44s (± 0.43%) ~ 73.06s 74.02s p=0.936 n=6
Emit Time 23.61s (± 0.45%) 23.47s (± 0.48%) ~ 23.26s 23.57s p=0.078 n=6
Total Time 115.02s (± 0.35%) 114.88s (± 0.30%) ~ 114.53s 115.47s p=0.471 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 265,866 265,866 ~ ~ ~ p=1.000 n=6
Types 108,401 108,401 ~ ~ ~ p=1.000 n=6
Memory used 410,516k (± 0.01%) 410,514k (± 0.01%) ~ 410,452k 410,570k p=0.748 n=6
Parse Time 3.84s (± 1.39%) 3.83s (± 0.86%) ~ 3.79s 3.87s p=1.000 n=6
Bind Time 1.66s (± 0.59%) 1.66s (± 1.04%) ~ 1.64s 1.68s p=0.805 n=6
Check Time 16.98s (± 0.32%) 16.96s (± 0.32%) ~ 16.89s 17.02s p=0.810 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 22.49s (± 0.38%) 22.45s (± 0.36%) ~ 22.34s 22.56s p=0.748 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 524,639 524,639 ~ ~ ~ p=1.000 n=6
Types 178,906 178,906 ~ ~ ~ p=1.000 n=6
Memory used 462,675k (± 0.02%) 462,662k (± 0.01%) ~ 462,595k 462,744k p=0.689 n=6
Parse Time 3.89s (± 0.46%) 3.88s (± 0.36%) ~ 3.86s 3.90s p=0.370 n=6
Bind Time 1.44s (± 1.04%) 1.44s (± 1.57%) ~ 1.42s 1.48s p=0.285 n=6
Check Time 22.53s (± 0.33%) 22.57s (± 0.54%) ~ 22.36s 22.72s p=0.377 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 27.87s (± 0.26%) 27.89s (± 0.38%) ~ 27.74s 28.06s p=0.810 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the user tests comparing main and refs/pull/58514/merge:

Everything looks good!

@typescript-bot
Copy link
Collaborator

@jakebailey Here are the results of running the top 400 repos comparing main and refs/pull/58514/merge:

Everything looks good!

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

@danvk guessed that the source of the problem was a speculative getTypeOfSymbol. But this PR fixes resolution for all parameters. If it applies to all parameters, why wasn't this observed before Dan's change?

  1. Need tests of used/unused binding patterns. These probably exist already, but please double-check.
  2. If this implementation is correct, I think it would be easier to read in isSelfReferenceLocation, as long as that doesn't make performance worse (from adding a second parameter).

Edit: having looked at checkIfExpressionRefinesAnyParameter, Dan's specific guess doesn't make sense to me. My (fuzzier) guess is that we haven't tried to resolve a parameter name from itself before and never observed that it mistakenly caused the parameter to be marked as used. But I'm not sure what in the new code is causing that.

@@ -11360,18 +11360,23 @@ export function createNameResolver({
location = root.parent;
}
break;
case SyntaxKind.Parameter:
case SyntaxKind.Parameter: {
const param = location as ParameterDeclaration;
Copy link
Member

Choose a reason for hiding this comment

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

style question: is there a reason for all the casts in this code? Maybe it's better to drop this alias and use location as ParameterDeclaration) everywhere.

case SyntaxKind.Parameter: {
const param = location as ParameterDeclaration;
if (lastLocation === param.name) {
lastSelfReferenceLocation = param;
Copy link
Member

Choose a reason for hiding this comment

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

I'd almost prefer a new parameter and entry in isSelfReferenceLocation like

    function isSelfReferenceLocation(node: Node, lastLocation: Node): node is SelfReferenceLocation {
        switch (node.kind) {
            case SyntaxKind.Parameter: return lastLocation === (node as ParameterDeclaration).name
            // ...

case SyntaxKind.Parameter:
case SyntaxKind.Parameter: {
const param = location as ParameterDeclaration;
if (lastLocation === param.name) {
Copy link
Member

Choose a reason for hiding this comment

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

what does this do when param.name is a BindingPattern? Do we have tests to make sure that they still correctly get marked unused (and used when used)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

Regression in detecting unused parameters in 5.5.0-beta
4 participants