Skip to content

🧹 Extract complex match arms in lower_stmts_with_env into helper functions - #313

Open
undivisible wants to merge 1 commit into
masterfrom
refactor-lower-stmts-with-env-8817524802857693550
Open

🧹 Extract complex match arms in lower_stmts_with_env into helper functions#313
undivisible wants to merge 1 commit into
masterfrom
refactor-lower-stmts-with-env-8817524802857693550

Conversation

@undivisible

@undivisible undivisible commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

🎯 What: The lower_stmts_with_env function in in-cli/src/lower_core.rs was overly long (257 lines) and contained deeply nested, complex control flow logic for several AST statement types within a single massive match block. This PR extracts the logic for Stmt::If, Stmt::Loop, Stmt::Match, and Stmt::Try into dedicated, smaller helper functions.

💡 Why: A massive, monolithic function handling all statement lowering is difficult to read, maintain, and reason about. Extracting these complex branches into separate helper functions significantly reduces the cognitive load, isolates the specific lowering logic for each construct, and dramatically improves the maintainability of the lower_core module without altering any functionality.

Verification: I successfully ran cargo fmt, cargo clippy, and the entire test suite (cargo test) locally to verify that no functionality was broken and no new warnings were introduced. I also verified the exact parameter passing and mutable borrows correctly mirror the original behavior.

Result: The lower_stmts_with_env function is now much shorter, more readable, and easier to maintain. The complex lowering logic for conditionals, loops, matching, and try/catch blocks is cleanly compartmentalized into isolated helper functions.


PR created automatically by Jules for task 8817524802857693550 started by @undivisible


Note

Low Risk
Pure refactor of compiler lowering with logic moved verbatim into helpers; risk is limited to accidental behavior drift, which the existing tests are meant to catch.

Overview
Refactors statement lowering in lower_core.rs by pulling if, loop, match, and try handling out of the large lower_stmts_with_env match into dedicated helpers: lower_if_stmt, lower_loop_stmt, lower_match_stmt, and lower_try_stmt.

The main dispatcher now delegates to those functions and passes the same env, SSA counter, finish_with_return, and output buffer (with lower_try_stmt still honoring force_stores). Emitted SIL and control-flow structure are unchanged—this is a structural cleanup only.

Reviewed by Cursor Bugbot for commit 8e9b20b. Configure here.

…tions

Extracted the bodies of Stmt::If, Stmt::Loop, Stmt::Match, and Stmt::Try
into separate lower_if_stmt, lower_loop_stmt, lower_match_stmt, and
lower_try_stmt helper functions. This drastically reduces the size and
complexity of the main lower_stmts_with_env function, improving
readability and maintainability while strictly preserving existing
behavior and scoping rules.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@cursor

cursor Bot commented Sep 10, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_828bb4f7-a0af-4202-89e4-c0c4994e6ff0)

@mergify

mergify Bot commented Sep 10, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant