🧹 Extract complex match arms in lower_stmts_with_env into helper functions - #313
🧹 Extract complex match arms in lower_stmts_with_env into helper functions#313undivisible wants to merge 1 commit into
lower_stmts_with_env into helper functions#313Conversation
…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>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Bugbot couldn't run - usage limit reachedBugbot 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) |
|
Tick the box to add this pull request to the merge queue (same as
|
🎯 What: The
lower_stmts_with_envfunction inin-cli/src/lower_core.rswas overly long (257 lines) and contained deeply nested, complex control flow logic for several AST statement types within a single massivematchblock. This PR extracts the logic forStmt::If,Stmt::Loop,Stmt::Match, andStmt::Tryinto 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_coremodule 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_envfunction 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.rsby pullingif,loop,match, andtryhandling out of the largelower_stmts_with_envmatch into dedicated helpers:lower_if_stmt,lower_loop_stmt,lower_match_stmt, andlower_try_stmt.The main dispatcher now delegates to those functions and passes the same
env, SSA counter,finish_with_return, and output buffer (withlower_try_stmtstill honoringforce_stores). Emitted SIL and control-flow structure are unchanged—this is a structural cleanup only.Reviewed by Cursor Bugbot for commit 8e9b20b. Configure here.