Skip to content

Conversation

@vaivaswatha
Copy link
Contributor

@vaivaswatha vaivaswatha commented Jan 30, 2026

Cursor Bugbot found 1 potential issue for commit 101734d

@vaivaswatha vaivaswatha self-assigned this Jan 30, 2026
@vaivaswatha vaivaswatha marked this pull request as ready for review February 4, 2026 23:03
@vaivaswatha vaivaswatha requested a review from a team as a code owner February 4, 2026 23:03
@cursor
Copy link

cursor bot commented Feb 4, 2026

PR Summary

Medium Risk
Touches IR lowering logic and instruction ordering for aggregate initialization; incorrect zero detection or insertion position could cause miscompilations or missed lowering (as evidenced by updated failing snapshot).

Overview
Adds a new init_aggr lowering optimization: when an aggregate is mostly runtime-zeroed (>= ~30% by byte size), it now emits a mem_clear_val for the whole aggregate and then stores only the non-zero fields, including recursive handling of nested init_aggrs and careful insertion ordering.

Extends lowering plumbing with InitAggrInitializer::is_runtime_zeroed() and a skip_zeroes flag to avoid redundant zero stores (and disables the repeat-array fast path when zero-skipping would route through temporaries). Updates/adds IR generation tests and several e2e snapshots; also updates an auto contract ID, and the const_of_contract_call snapshot now captures a failing case where InstOp::InitAggr was not lowered.

Written by Cursor Bugbot for commit 101734d. This will update automatically on new commits. Configure here.

@vaivaswatha vaivaswatha enabled auto-merge (squash) February 4, 2026 23:03
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

for (insert_idx, initializer) in initializers.iter().enumerate() {
if initializer.is_runtime_zeroed(context) && skip_zeroes {
// This element is zero-initialized. We can skip initializing it again.
continue;
Copy link

Choose a reason for hiding this comment

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

Skipping zero initializers leaves nested init_aggr instructions unlowered

High Severity

When skip_zeroes is true and an initializer passes the is_runtime_zeroed check, the code uses continue to skip the call to lower_single_initializer_to_stores. However, if the initializer is a NestedInitAggr, this skips the critical cleanup code that removes the nested init_aggr instruction from the IR. Since nested init_aggrs are excluded from find_root_init_aggrs, they aren't removed at the end of the pass either. This leaves unlowered InitAggr instructions in the IR, causing the "InstOp::InitAggr was not lowered" compiler errors shown in the test failures for cases like [0], (0,), and S1 { a: 0 }.

Additional Locations (1)

Fix in Cursor Fix in Web

@ironcev
Copy link
Member

ironcev commented Feb 5, 2026

👍

@ironcev ironcev changed the title Optimize initialization of mostly zerod aggregates Optimize initialization of mostly zeroed aggregates Feb 5, 2026
@ironcev ironcev self-assigned this Feb 10, 2026
@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: ir IRgen and sway-ir including optimization passes labels Feb 10, 2026
@ironcev ironcev disabled auto-merge February 10, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler: ir IRgen and sway-ir including optimization passes compiler General compiler. Should eventually become more specific as the issue is triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants