Repository navigation
MOD-20160 Retag emptied typed arrays before adding non-numeric items - #26
Merged
Merged
Conversation
TalBarYakar
reviewed
Nov 11, 2026
| Ok(()) | ||
| } | ||
|
|
||
| /// Retags or promotes the array so `item` can be stored in it, then reserves |
There was a problem hiding this comment.
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.
Author
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
TalBarYakar
approved these changes
Nov 12, 2026
Merged
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
IArraynow share a newprepare_for_itemhelper 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.