Skip to content

refactor(semantic): simplify checking if function is part of if statement#18290

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/01-19-refactor_semantic_simplify_checking_if_function_is_part_of_if_statement
Jan 21, 2026
Merged

refactor(semantic): simplify checking if function is part of if statement#18290
graphite-app[bot] merged 1 commit intomainfrom
om/01-19-refactor_semantic_simplify_checking_if_function_is_part_of_if_statement

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Jan 20, 2026

is_function_part_of_if_statement had some convoluted code to check if a Function is the consequent or alternate of an IfStatement.

Simplify it by checking if the Function is a function declaration, then just a check for whether the parent node is an IfStatement.

Rationale is:

  • If a Function is a declaration, it can only be the consequent or alternate of an IfStatement. It can't be the test, because that's an expression not a declaration. So if a function declaration's parent is an IfStatement, it's definitely either the consequent or alternate.
  • If a Function is an expression, it's parent can't be consequent or alternate of an IfStatement because the function would need to be wrapped in some other node e.g. ExpressionStatement (and then IfStatement wouldn't be the function's parent).

Also add a comment explaining why we do the check for strict/sloppy mode too.

@github-actions github-actions bot added A-semantic Area - Semantic C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Jan 20, 2026
Copy link
Member Author

overlookmotel commented Jan 20, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 20, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing om/01-19-refactor_semantic_simplify_checking_if_function_is_part_of_if_statement (3f602f0) with main (6803adf)1

Summary

✅ 42 untouched benchmarks
⏩ 3 skipped benchmarks2

Footnotes

  1. No successful run was found on om/01-20-test_semantic_add_test_cases_for_function_redeclaration_check (64ed030) during the generation of this report, so main (6803adf) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@overlookmotel overlookmotel marked this pull request as ready for review January 20, 2026 12:34
Copilot AI review requested due to automatic review settings January 20, 2026 12:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the is_function_part_of_if_statement function to use a simpler and more straightforward approach for checking if a function declaration is the consequent or alternate of an IfStatement. The refactoring removes pointer equality checks and leverages the fact that function declarations can only appear in specific positions within an IfStatement.

Changes:

  • Simplified logic by first checking if the function is a declaration, then checking parent node kind
  • Removed std::ptr import and pointer equality comparisons
  • Added clarifying comments explaining the logic and strict mode optimization

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@graphite-app
Copy link
Contributor

graphite-app bot commented Jan 20, 2026

Merge activity

@graphite-app graphite-app bot force-pushed the om/01-20-test_semantic_add_test_cases_for_function_redeclaration_check branch from 64ed030 to 22b4d39 Compare January 20, 2026 14:09
graphite-app bot pushed a commit that referenced this pull request Jan 20, 2026
…tement (#18290)

`is_function_part_of_if_statement` had some convoluted code to check if a `Function` is the `consequent` or `alternate` of an `IfStatement`.

Simplify it by checking if the `Function` is a function declaration, then just a check for whether the parent node is an `IfStatement`.

Rationale is:

* If a `Function` is a declaration, it can only be the `consequent` or `alternate` of an `IfStatement`. It can't be the `test`, because that's an expression not a declaration. So if a function declaration's parent is an `IfStatement`, it's definitely either the `consequent` or `alternate`.
* If a `Function` is an expression, it's parent can't be `consequent` or `alternate` of an `IfStatement` because the function would need to be wrapped in some other node e.g. `ExpressionStatement` (and then `IfStatement` wouldn't be the function's parent).

Also add a comment explaining why we do the check for strict/sloppy mode too.
@graphite-app graphite-app bot force-pushed the om/01-19-refactor_semantic_simplify_checking_if_function_is_part_of_if_statement branch from 3f602f0 to 90e93ab Compare January 20, 2026 14:09
Base automatically changed from om/01-20-test_semantic_add_test_cases_for_function_redeclaration_check to main January 20, 2026 14:15
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 20, 2026
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Jan 21, 2026
…tement (#18290)

`is_function_part_of_if_statement` had some convoluted code to check if a `Function` is the `consequent` or `alternate` of an `IfStatement`.

Simplify it by checking if the `Function` is a function declaration, then just a check for whether the parent node is an `IfStatement`.

Rationale is:

* If a `Function` is a declaration, it can only be the `consequent` or `alternate` of an `IfStatement`. It can't be the `test`, because that's an expression not a declaration. So if a function declaration's parent is an `IfStatement`, it's definitely either the `consequent` or `alternate`.
* If a `Function` is an expression, it's parent can't be `consequent` or `alternate` of an `IfStatement` because the function would need to be wrapped in some other node e.g. `ExpressionStatement` (and then `IfStatement` wouldn't be the function's parent).

Also add a comment explaining why we do the check for strict/sloppy mode too.
@graphite-app graphite-app bot force-pushed the om/01-19-refactor_semantic_simplify_checking_if_function_is_part_of_if_statement branch from 90e93ab to fde1dc7 Compare January 21, 2026 01:09
@graphite-app graphite-app bot merged commit fde1dc7 into main Jan 21, 2026
21 checks passed
@graphite-app graphite-app bot deleted the om/01-19-refactor_semantic_simplify_checking_if_function_is_part_of_if_statement branch January 21, 2026 01:15
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-semantic Area - Semantic C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants