Skip to content

Improve uncalled function check related to parenthesized and binary expressions #50756

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 9 commits into from
Jan 17, 2023

Conversation

Andarist
Copy link
Contributor

fixes #37598

@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Sep 13, 2022
Comment on lines 34161 to 34166
let parent = node.parent;
while (parent.kind === SyntaxKind.ParenthesizedExpression
|| isBinaryExpression(parent) && (parent.operatorToken.kind === SyntaxKind.AmpersandAmpersandToken || parent.operatorToken.kind === SyntaxKind.BarBarToken)) {
parent = parent.parent;
}
if (operator === SyntaxKind.AmpersandAmpersandToken || isIfStatement(parent)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've thought that perhaps with some of my recent changes this could be reverted but it seems that it can't. Without this change the error here goes away:

~~~~~~~~~
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

It's quite interesting because a similar error here doesn't go away:

~~~~~~~~~
!!! error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

So it seems that the logic is very sensitive when it comes to handling left/right side of a binary expression. Should I strive to revert this change here and find another solution? Or is this acceptable?

helper(condExpr, body);
while (isBinaryExpression(condExpr) && condExpr.operatorToken.kind === SyntaxKind.BarBarToken) {
condExpr = condExpr.left;
function bothHelper(condExpr: Expression, body: Expression | Statement | undefined) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

todo: this could use a better name, the helper itself probably could use a better name too. I can try to figure out something better later on

@jakebailey
Copy link
Member

@typescript-bot test this
@typescript-bot user test this inline
@typescript-bot perf test this faster
@typescript-bot test top100

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 26, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 26, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 26, 2022

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

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 26, 2022

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

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

Here they are:

Comparison Report - main..50756

Metric main 50756 Delta Best Worst
Angular - node (v14.15.1, x64)
Memory used 337,918k (± 0.08%) 338,065k (± 0.01%) +146k (+ 0.04%) 338,016k 338,170k
Parse Time 2.06s (± 0.48%) 2.06s (± 0.47%) +0.00s (+ 0.05%) 2.04s 2.08s
Bind Time 0.79s (± 0.94%) 0.79s (± 0.75%) +0.00s (+ 0.13%) 0.78s 0.81s
Check Time 5.87s (± 0.89%) 5.88s (± 0.50%) +0.01s (+ 0.14%) 5.83s 5.97s
Emit Time 6.24s (± 0.82%) 6.26s (± 0.38%) +0.02s (+ 0.29%) 6.22s 6.33s
Total Time 14.96s (± 0.65%) 14.99s (± 0.30%) +0.02s (+ 0.16%) 14.91s 15.11s
Compiler-Unions - node (v14.15.1, x64)
Memory used 190,791k (± 0.67%) 190,778k (± 0.68%) -13k (- 0.01%) 190,133k 196,029k
Parse Time 0.86s (± 0.61%) 0.85s (± 0.72%) -0.01s (- 0.93%) 0.84s 0.87s
Bind Time 0.49s (± 1.06%) 0.49s (± 0.75%) -0.00s (- 0.61%) 0.48s 0.49s
Check Time 6.76s (± 0.62%) 6.70s (± 0.52%) -0.06s (- 0.84%) 6.65s 6.80s
Emit Time 2.40s (± 1.18%) 2.41s (± 0.74%) +0.01s (+ 0.33%) 2.38s 2.44s
Total Time 10.50s (± 0.53%) 10.45s (± 0.37%) -0.05s (- 0.52%) 10.39s 10.58s
Monaco - node (v14.15.1, x64)
Memory used 326,572k (± 0.01%) 326,560k (± 0.01%) -12k (- 0.00%) 326,472k 326,616k
Parse Time 1.58s (± 0.67%) 1.59s (± 0.69%) +0.01s (+ 0.32%) 1.57s 1.61s
Bind Time 0.72s (± 0.80%) 0.72s (± 0.83%) +0.00s (+ 0.28%) 0.71s 0.74s
Check Time 5.70s (± 0.49%) 5.70s (± 0.43%) +0.01s (+ 0.12%) 5.62s 5.75s
Emit Time 3.36s (± 0.38%) 3.37s (± 0.62%) +0.01s (+ 0.27%) 3.33s 3.42s
Total Time 11.37s (± 0.27%) 11.39s (± 0.22%) +0.02s (+ 0.18%) 11.34s 11.46s
TFS - node (v14.15.1, x64)
Memory used 289,687k (± 0.01%) 289,678k (± 0.01%) -10k (- 0.00%) 289,619k 289,709k
Parse Time 1.30s (± 0.43%) 1.31s (± 1.10%) +0.01s (+ 0.77%) 1.28s 1.35s
Bind Time 0.80s (± 0.75%) 0.80s (± 0.86%) -0.00s (- 0.13%) 0.79s 0.82s
Check Time 5.37s (± 0.20%) 5.37s (± 0.42%) +0.00s (+ 0.06%) 5.32s 5.44s
Emit Time 3.60s (± 0.53%) 3.59s (± 0.64%) -0.01s (- 0.39%) 3.55s 3.64s
Total Time 11.06s (± 0.24%) 11.05s (± 0.40%) -0.00s (- 0.05%) 10.97s 11.20s
material-ui - node (v14.15.1, x64)
Memory used 435,593k (± 0.00%) 435,488k (± 0.06%) -105k (- 0.02%) 434,440k 435,664k
Parse Time 1.86s (± 0.71%) 1.87s (± 0.62%) +0.01s (+ 0.54%) 1.85s 1.90s
Bind Time 0.58s (± 0.58%) 0.58s (± 0.77%) -0.00s (- 0.17%) 0.57s 0.59s
Check Time 12.89s (± 0.33%) 12.86s (± 0.70%) -0.03s (- 0.20%) 12.71s 13.09s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.34s (± 0.35%) 15.32s (± 0.65%) -0.02s (- 0.12%) 15.13s 15.56s
xstate - node (v14.15.1, x64)
Memory used 544,017k (± 0.00%) 544,041k (± 0.00%) +24k (+ 0.00%) 544,007k 544,087k
Parse Time 2.61s (± 0.34%) 2.61s (± 0.60%) +0.00s (+ 0.04%) 2.57s 2.64s
Bind Time 0.99s (± 1.39%) 0.98s (± 0.86%) -0.01s (- 0.61%) 0.97s 1.00s
Check Time 1.52s (± 0.50%) 1.52s (± 0.51%) +0.00s (+ 0.20%) 1.51s 1.54s
Emit Time 0.07s (± 0.00%) 0.07s (± 0.00%) 0.00s ( 0.00%) 0.07s 0.07s
Total Time 5.19s (± 0.35%) 5.18s (± 0.28%) -0.01s (- 0.15%) 5.14s 5.20s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 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 50756 10
Baseline main 10

Developer Information:

Download Benchmark

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

…tion-check

# Conflicts:
#	src/compiler/checker.ts
#	src/compiler/factory/utilities.ts
@Andarist
Copy link
Contributor Author

Andarist commented Dec 9, 2022

@jakebailey you requested perf results for this some time ago. Any chance that you'd have some time to review this now when they are already here? :)

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

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

The code LGTM and the perf does appear to be fine. I think from the issue that this is a behavior we want, so, SGTM.

@jakebailey jakebailey requested a review from weswigham December 15, 2022 21:06
@Andarist
Copy link
Contributor Author

@jakebailey I was wondering if there is a chance to land this before entering the 5.0 beta period (3 days left 😅 )

@jakebailey
Copy link
Member

I was hoping for someone else to weigh in (I don't entirely trust myself to merge large-ish checker PRs), but it still seems fine to me given it's an "experience enhancement" aka "obviously an improvement" and top100 passed (so, probably low-risk).

@jakebailey jakebailey merged commit 16c695c into microsoft:main Jan 17, 2023
@Andarist Andarist deleted the improve-uncalled-function-check branch January 17, 2023 23:11
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.

Function truthy check doesn't apply if the function is in a boolean expression
4 participants