Files
metal2vulkan/tests
Anees Iqbal e73c87d49b Stop three emission decisions from following hash-map iteration order
The same AIR translated to different SPIR-V on every run. Not different ids that
canonicalization normalizes away -- genuinely different modules: a different
prologue order, different constant declarations, different type declarations. Each
run was individually correct and passed spirv-val, which is why nothing caught it.

It matters because the validation ladder compares a candidate's output by SHA-256,
consumers cache translated SPIR-V by content hash, and a bug report is only
reproducible if the module that produced it can be produced again.

Three sources, all the same shape -- an unordered collection deciding the order
something is emitted or minted in:

- native emitter (functions.rs): the device-address prologue materializes one
  address per direct buffer parameter, and that list was built by iterating
  `raw_offsets`. The position each address lands at fixes which address-table slot
  the module reads there, so the whole prologue permuted. Order by entry parameter
  ordinal, which is stable and is the order a reader expects. The rewrite also
  drops a redundant `contains_key` and, with it, an eager map index that would have
  panicked on any raw offset that is not a direct parameter.
- buffer-address lowering (buffer_addresses.rs): `ctx.const_uint` mints a constant
  the first time it sees a value, so the order the table's location constants were
  requested in -- taken from a `HashSet` -- was their declaration order.
- nesting structurizer (reloop_nest/emit.rs): `demote_phis` walked `blocks.keys()`,
  minting a variable and a `TypePointer Function` per demoted phi in hash-map
  order. Record the function's own block order at indexing time and walk that.

tests/deterministic_output.rs pins the contract. Rust seeds every HashMap's hasher
differently, including two built in the same process, so translating one input
twice in one test is enough to expose an order-following emission decision -- it is
strictly stronger than comparing two CLI runs, and it found the second and third
sources after the first was already fixed. It covers an authored four-buffer
device-address kernel (with a guard that the kernel still lowers to an address
table, so the case cannot decay into covering nothing) and every public fixture
that translates.

Verified: the authored kernel produced 6 distinct hashes in 6 CLI runs before the
first fix and 1 after; 12 in-process runs collapsed from 2 distinct modules to 1
after the second. Over 1267 sampled local-corpus sources, 1159 translated and 2
still varied before the third fix; after it, a 240-source sample was fully stable
and the two known varying cases were checked individually. cargo test -p
metal2vulkan: 1704 lib + 3 determinism + 3 env + 6 fallback, all passing.
Workspace clippy -D warnings and all-features Rustdoc: clean.
2026-08-31 15:39:00 +03:00
..
2026-07-22 13:15:24 +03:00