Skip to content

MOD-20160 Retag emptied typed arrays before adding non-numeric items - #26

Merged
AvivDavid23 merged 2 commits into
masterfrom
MOD-20160
Nov 12, 2026
Merged

AvivDavid23 merged 2 commits into
masterfrom
MOD-20160

Conversation

@AvivDavid23

@AvivDavid23 AvivDavid23 commented Nov 11, 2026 •

Copy link
Copy Markdown

Note

Medium Risk
Changes core array mutation and in-place retagging of empty typed allocations; behavior is exercised by new tests but mistakes could corrupt tags or storage layout.

Overview
Push and insert on IArray now share a new prepare_for_item helper instead of duplicating type-tag and capacity logic.

When the array is empty, the next item drives the tag: non-numeric values move the buffer to Heterogeneous (even if it was still typed after pop/remove/clear), and numeric values can narrow the tag (e.g. heterogeneous → I8). Non-empty arrays keep the existing promote-or-heterogenize behavior.

New tests cover emptied typed and heterogeneous arrays across all primitive tags, emptying via remove/pop/clear, and mixed push sequences.

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

Comment thread src/array.rs
Ok(())
}

/// Retags or promotes the array so `item` can be stored in it, then reserves

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe add a comment explaining the type transitions for an empty array:

  • Numeric → numeric: choose the numeric type that fits the new value, possibly narrowing it (e.g. i64 → i8).
  • Numeric → non-numeric: switch to Heterogeneous.
  • Heterogeneous → numeric: switch to the appropriate numeric type.
  • Heterogeneous → non-numeric: remain Heterogeneous.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Narrow? we never narrow.
And I think such comment is not needed + will also confuse since we never Heterogeneous → numeric(unless the array is empty, and therefore the code speaks for itself

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I was referring only to empty arrays, where the type is selected again from the incoming value—for example, an emptied i64 array becomes i8 when inserting 7, as covered by the new test. I didn’t mean that we narrow non-empty arrays.

@AvivDavid23
AvivDavid23 merged commit 379dadf into master Nov 12, 2026
7 checks passed
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.

2 participants