Skip to content

🧹 Replace unsafe unwrap with proper error handling in thumb_lower - #326

Open
undivisible wants to merge 1 commit into
masterfrom
jules-refactor-unwrap-thumb-lower-4335764489212883950
Open

🧹 Replace unsafe unwrap with proper error handling in thumb_lower#326
undivisible wants to merge 1 commit into
masterfrom
jules-refactor-unwrap-thumb-lower-4335764489212883950

Conversation

@undivisible

@undivisible undivisible commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

🎯 What:
Replaced the unwrap() call at in-cli/src/native_emit/thumb_lower.rs:115 with 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 the offsets map during lowering. Replacing this with an explicit error return gracefully propagates the failure back through the Result chain to the caller, preventing compiler crashes on malformed inputs (like empty extern functions) and improving the overall maintainability and safety of the pass.

Verification:

  • Linting & Formatting: Ran cargo fmt and cargo clippy --all-targets --features extended --locked -- -D warnings within the in-cli crate (no warnings).
  • Unit Testing: Ran cargo test -p inauguration native_emit and the full cargo test -p inauguration suite; all tests passed successfully.
  • Integration Testing: Executed the full conformance suite (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).
  • Code Review: Requested and passed automated code review with a "Correct" rating.

Result:
The lower_module function now correctly returns a detailed Err instead 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 Result error.

Overview
lower_module in 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 to offsets).

The final entry_offset lookup replaces unwrap() with ok_or_else + ?, returning a clear Err message instead of aborting the compiler. Valid entries with real bodies are unchanged.

Reviewed by Cursor Bugbot for commit 4bf73b3. Configure here.

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>
@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_1e3a68ad-c5bc-46d9-be24-2264c9897718)

@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