Skip to content

refactor(lowering): Made function not return Maybe and possibly hide diags.#9916

Merged
orizi merged 1 commit into
mainfrom
orizi/05-07-refactor_lowering_made_function_not_return_maybe_and_possibly_hide_diags
May 10, 2026
Merged

refactor(lowering): Made function not return Maybe and possibly hide diags.#9916
orizi merged 1 commit into
mainfrom
orizi/05-07-refactor_lowering_made_function_not_return_maybe_and_possibly_hide_diags

Conversation

@orizi
Copy link
Copy Markdown
Collaborator

@orizi orizi commented May 10, 2026

Summary

function_with_body_lowering_diagnostics now returns Diagnostics directly instead of Maybe<Diagnostics>. The in_cycle error case is handled inline using matches!(..., Ok(true)) rather than propagating via ?, allowing the function to be infallible. All call sites are updated to remove .unwrap_or_default() and ? unwrapping accordingly.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

function_with_body_lowering_diagnostics was returning Maybe<Diagnostics> despite having no meaningful failure path — the only ? usage was on db.in_cycle(...), which on error would silently swallow all diagnostics collected up to that point. This meant a query failure could cause legitimate diagnostics to be lost rather than reported.


What was the behavior or documentation before?

If db.in_cycle(function_id, DependencyType::Cost) returned an Err, the function would early-return Err, discarding any diagnostics already accumulated in the builder. Call sites used .unwrap_or_default() to recover, silently dropping those diagnostics.


What is the behavior or documentation after?

The function is now infallible and always returns a Diagnostics value. The in_cycle result is checked with matches!(..., Ok(true)), so errors are treated as "not in cycle" without aborting diagnostic collection. All diagnostics gathered before the cycle check are preserved and returned regardless of whether in_cycle succeeds.


Related issue or discussion (if any)


Additional context

The test helper in block_generator_test.rs is also updated to remove the now-unnecessary .unwrap() call.

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Collaborator Author

orizi commented May 10, 2026

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

@cursor
Copy link
Copy Markdown

cursor Bot commented May 10, 2026

PR Summary

Medium Risk
Changes the type/signature and error-handling behavior of function_with_body_lowering_diagnostics, which affects compilation/lowering control flow and could subtly change when errors are surfaced or suppressed.

Overview
function_with_body_lowering_diagnostics now returns Diagnostics directly (no Maybe), ensuring diagnostics collected during lowering/borrow-checking aren’t dropped due to an in_cycle query error.

Call sites are updated to stop propagating/unwrap’ing this query (lowered_body no longer uses ?, semantic aggregation no longer uses unwrap_or_default, and the Sierra generator test removes an unwrap()), and the cycle check treats in_cycle failures as “not in cycle” via matches!(..., Ok(true)).

Reviewed by Cursor Bugbot for commit c2d068e. Bugbot is set up for automated code reviews on this repo. Configure here.

@orizi orizi force-pushed the orizi/05-07-refactor_lowering_made_function_not_return_maybe_and_possibly_hide_diags branch from dd3b75b to bb24961 Compare May 10, 2026 10:30
@orizi orizi force-pushed the orizi/05-06-bug_fix_fix_ice_on_nested_const_fn_in_const_fn_9889_ branch from 74c9f4a to e1b9767 Compare May 10, 2026 10:30
@orizi orizi force-pushed the orizi/05-07-refactor_lowering_made_function_not_return_maybe_and_possibly_hide_diags branch from bb24961 to e340c25 Compare May 10, 2026 10:31
Copy link
Copy Markdown
Collaborator

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

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

:lgtm:

@TomerStarkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on orizi).

@orizi orizi force-pushed the orizi/05-06-bug_fix_fix_ice_on_nested_const_fn_in_const_fn_9889_ branch from e1b9767 to 8ce771c Compare May 10, 2026 10:31
@orizi orizi changed the base branch from orizi/05-06-bug_fix_fix_ice_on_nested_const_fn_in_const_fn_9889_ to graphite-base/9916 May 10, 2026 10:36
@orizi orizi force-pushed the orizi/05-07-refactor_lowering_made_function_not_return_maybe_and_possibly_hide_diags branch from e340c25 to c2d068e Compare May 10, 2026 10:36
@orizi orizi force-pushed the graphite-base/9916 branch from 8ce771c to ac2d27e Compare May 10, 2026 10:36
@orizi orizi changed the base branch from graphite-base/9916 to main May 10, 2026 10:36
@orizi orizi enabled auto-merge May 10, 2026 10:38
@orizi orizi added this pull request to the merge queue May 10, 2026
Merged via the queue into main with commit 7c0efa3 May 10, 2026
105 checks passed
@orizi orizi deleted the orizi/05-07-refactor_lowering_made_function_not_return_maybe_and_possibly_hide_diags branch May 10, 2026 11:00
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.

3 participants