🧹 Replace unsafe unwrap with proper error handling in thumb_lower - #326
🧹 Replace unsafe unwrap with proper error handling in thumb_lower#326undivisible wants to merge 1 commit into
Conversation
Replaces unwrap() with proper error handling using ok_or_else() and the ? operator to return a structured error message when an entry offset is not found during lowering, improving the safety and robustness of the compiler pass. 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_1e3a68ad-c5bc-46d9-be24-2264c9897718) |
|
Tick the box to add this pull request to the merge queue (same as
|
🎯 What:
Replaced the
unwrap()call atin-cli/src/native_emit/thumb_lower.rs:115with proper error handling using.ok_or_else()and the?operator.💡 Why:
The previous code would unconditionally panic (
unwrap) if the target entry offset was not found in theoffsetsmap during lowering. Replacing this with an explicit error return gracefully propagates the failure back through theResultchain to the caller, preventing compiler crashes on malformed inputs (like empty extern functions) and improving the overall maintainability and safety of the pass.✅ Verification:
cargo fmtandcargo clippy --all-targets --features extended --locked -- -D warningswithin thein-clicrate (no warnings).cargo test -p inauguration native_emitand the fullcargo test -p inaugurationsuite; all tests passed successfully.IN_TEST_SKIP_SWIFT=1 ./install.sh && ~/.local/bin/in test), which completed successfully (accounting for known pre-existing baseline failures that were not regressions).✨ Result:
The
lower_modulefunction now correctly returns a detailedErrinstead of panicking when an entry offset is missing, making the Thumb-2 backend more robust without changing any valid lowering behavior.PR created automatically by Jules for task 4335764489212883950 started by @undivisible
Note
Low Risk
Single-site error-handling change in the Thumb lowerer; no behavior change for successfully lowered modules, only replaces a panic with a propagated
Resulterror.Overview
lower_modulein the Thumb-2 backend no longer panics when the chosen entry symbol has no emitted code offset (e.g. an extern with an empty body, which is skipped during emission and never added tooffsets).The final
entry_offsetlookup replacesunwrap()withok_or_else+?, returning a clearErrmessage instead of aborting the compiler. Valid entries with real bodies are unchanged.Reviewed by Cursor Bugbot for commit 4bf73b3. Configure here.