Skip to content

Constant arrays and tuples are named from their content, not from attribute addresses - #819

Merged
ASDAlexander77 merged 1 commit into
mainfrom
constant-array-names
Nov 12, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
constant-array-names

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Constant arrays (a_…) and constant tuples (tp_…) are now named from their content, not from where their MLIR attributes happen to sit in memory.

The bug

calc_hash_value combined hash_value of the type and of each element attribute. MLIR hashes an attribute or a type by its address, with a weak mix. So:

  • Names changed from run to run. The same program compiled twice got different global names.
  • Different arrays got near-identical names. In one module, [1, 2] and [3, 4] were about 1,200 apart (a_211972185937195 vs a_211972185936021).
  • The size and hash could run together. The size was printed with no separator before the hash, so "a_2" + "11…" and "a_21" + "1…" spell the same name.

A global with a given name is shared by every constant that gets that name. So a collision gives one constant array another's data, and how often that happens depends on the addresses of a run. This is the likely cause of the one unexplained failure in #818's testing: 00owned_iteration.ts (wasm32, rc, debug) failed an assertion, the same way in all 5 runs of that build, and a rebuild passed.

The fix

  • The name is now an xxh3_64bits hash of the type and the elements as MLIR prints them, so identical constants still share a global.
  • The size is kept apart from the hash (a_<size>_<hash>).

Checks

  • Stable names: compiled twice, 00owned_iteration.ts gives the same a_/tp_ names. Its [1, 2], [2, 3] and [3, 4] now get unrelated hashes.
  • Sharing still works: [1, 2] in two functions shares one global, with the same name it gets in another file.
  • Element kinds: string, float and nested arrays, and [2, 1] against [1, 2], all get distinct names, and the program prints the right values.
  • Native ctest: 6976/6976.
  • wasm suites, release and debug, wasm32 and wasm64: 0 failures. tester 652 (none, rc) and 486 (own); default library none 206, rc 207, own 206.

Not changed

Other names still come from hash_value of a type: the type descriptor td_, the release/retain/share routines tsrel_/tsret_/tsshr_, and object-literal class names such as Shape.136163259. Each of those hashes one type's address rather than combining several, so a collision is much less likely, but it is possible, and those names also vary between runs. Because they differ from run to run, two builds of the same program aren't byte-identical.

🤖 Generated with Claude Code

…ribute addresses

calc_hash_value combined hash_value of the elements' attributes, which hashes their
addresses with a weak mix: [1, 2] and [3, 4] were named about 1200 apart, the names
changed from run to run, and a collision gave one constant array another's data
(00owned_iteration failed once on wasm32 rc debug, a rebuild passed). The name is now
an xxh3 hash of the type and elements as MLIR prints them, and an array's size is
kept apart from it ("a_2" + "11..." was "a_21" + "1...").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 21ddacb into main Nov 12, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the constant-array-names branch November 12, 2026 09:32
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