translator: a listing the translator cannot read is refused, not fatal #3077

Merged
imShangLi merged 3 commits from upstream-pr/3077 into main 2026-12-02 14:35:51 +00:00
imShangLi commented 2026-12-02 09:32:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T09:32:34Z.


Claimed in the coordination issue as: TRANSLATOR-UNREADABLE-LISTING (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7339518154)

What and why

A listing is data: llvm-mc's text for what it decoded. What the translator does not model is reported (Unsupported, by name), never guessed — the contract in docs/design.md. Two shapes of text it cannot read ended the translation with a Python traceback instead of that report:

  • An operand the parser did not understand. tools/shader_ir.py leaves an operand it cannot parse as {"k": "raw"} and its own comment says such an operand is Unsupported. The translator honoured that on the paths that read an operand through src_u (a source) and dst (a destination), but not on the paths that read the operand dict directly — an address, a data register — where it failed with KeyError: 'r'. The check is now at the dispatch boundary (Gen.insn), so every position refuses the same way, naming the instruction and the operand.
  • A modifier whose value is not a number. op_sel:[...], op_sel_hi:[...] and neg_lo:[...] were read with int() in fourteen places, each of which failed with ValueError on a value that is not a number. They are read in one place now (_modifier_bits; modifier_bits turns it into the refusal, and the two analyses that only look at a modifier answer conservatively through it), which refuses the modifier by name.

A swizzle(...) modifier whose arguments are not numbers does not match the pattern the translator reads it with, so it is refused as such (ds_swizzle pattern), like any other listing the translator cannot read.

Tested

  • Red/green with the repository's own tool: python3 -I scripts/red_green.py fix/translator-refuse-unreadable-listing --remote fork --base origin/main --no-cargo — verdict red then green: the red side (the merge base 0ae5a266 plus only the new test file) fails all four new tests, the green side (the head) passes them, 0 regressions.
  • By hand: python3 -I -m unittest discover -s tests/semantic -p 'test_translator_unreadable.py' — with tools/rdna2spirv.py back to main and the new test kept: 3 failures and 1 error (the address case ends in KeyError: 'r', the modifier case in ValueError); with the change: 4 tests, all pass.
  • The new test (tests/semantic/test_translator_unreadable.py): an unreadable operand in the destination, a source and an address position; an unreadable modifier value; a modifier that is not one; and a seeded sweep that replaces one operand of one instruction of every fixture in tests/semantic/fixtures/disasm/ (112 listings) by text the parser cannot read and requires each one to be refused. 0.5 s.
  • The translator's suite: python3 -I scripts/run_semantic_tests.py tests/semantic — 560 files, 6,791 tests, 0 failed on the branch (the same on main).
  • python3 -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_translator_unreadable.py docs/design.md — clean.
  • The fixtures are hand-written, so the test needs no game files, no GPU and no SPIR-V tools.

Two shapes are not refused by this change, and are reported as findings instead (with the sites and the evidence): an instruction with fewer operands than its op reads (an IndexError or a ValueError), and an operand that is not a register where the op reads one (a KeyError, and an SGPR read as a VGPR of the same number — a wrong address, silently). The first needs the op's operand count (the IndexError carries no index); the second follows Gen.addr_regs, which refuses this for an image address already.

GPUs tested: n/a (no GPU test; the translator's suite is CPU-only)

AI-assisted: yes — MiniMax M3.1 Flash wrote the change; SenseNova 6.8 Flash Lite reviewed it read-only.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5603684263 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3077). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-02T09:32:34Z. --- Claimed in the coordination issue as: TRANSLATOR-UNREADABLE-LISTING (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7339518154) ### What and why A listing is data: llvm-mc's text for what it decoded. What the translator does not model is reported (`Unsupported`, by name), never guessed — the contract in `docs/design.md`. Two shapes of text it cannot read ended the translation with a Python traceback instead of that report: - **An operand the parser did not understand.** `tools/shader_ir.py` leaves an operand it cannot parse as `{"k": "raw"}` and its own comment says such an operand is `Unsupported`. The translator honoured that on the paths that read an operand through `src_u` (a source) and `dst` (a destination), but not on the paths that read the operand dict directly — an address, a data register — where it failed with `KeyError: 'r'`. The check is now at the dispatch boundary (`Gen.insn`), so every position refuses the same way, naming the instruction and the operand. - **A modifier whose value is not a number.** `op_sel:[...]`, `op_sel_hi:[...]` and `neg_lo:[...]` were read with `int()` in fourteen places, each of which failed with `ValueError` on a value that is not a number. They are read in one place now (`_modifier_bits`; `modifier_bits` turns it into the refusal, and the two analyses that only look at a modifier answer conservatively through it), which refuses the modifier by name. A `swizzle(...)` modifier whose arguments are not numbers does not match the pattern the translator reads it with, so it is refused as such (`ds_swizzle pattern`), like any other listing the translator cannot read. ### Tested - **Red/green with the repository's own tool**: `python3 -I scripts/red_green.py fix/translator-refuse-unreadable-listing --remote fork --base origin/main --no-cargo` — verdict **red then green**: the red side (the merge base `0ae5a266` plus only the new test file) fails all four new tests, the green side (the head) passes them, 0 regressions. - **By hand**: `python3 -I -m unittest discover -s tests/semantic -p 'test_translator_unreadable.py'` — with `tools/rdna2spirv.py` back to `main` and the new test kept: 3 failures and 1 error (the address case ends in `KeyError: 'r'`, the modifier case in `ValueError`); with the change: 4 tests, all pass. - **The new test** (`tests/semantic/test_translator_unreadable.py`): an unreadable operand in the destination, a source and an address position; an unreadable modifier value; a modifier that is not one; and a seeded sweep that replaces one operand of one instruction of **every** fixture in `tests/semantic/fixtures/disasm/` (112 listings) by text the parser cannot read and requires each one to be refused. 0.5 s. - **The translator's suite**: `python3 -I scripts/run_semantic_tests.py tests/semantic` — 560 files, 6,791 tests, 0 failed on the branch (the same on `main`). - `python3 -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_translator_unreadable.py docs/design.md` — clean. - The fixtures are hand-written, so the test needs no game files, no GPU and no SPIR-V tools. Two shapes are **not** refused by this change, and are reported as findings instead (with the sites and the evidence): an instruction with fewer operands than its op reads (an `IndexError` or a `ValueError`), and an operand that is not a register where the op reads one (a `KeyError`, and an SGPR read as a VGPR of the same number — a wrong address, silently). The first needs the op's operand count (the `IndexError` carries no index); the second follows `Gen.addr_regs`, which refuses this for an image address already. GPUs tested: n/a (no GPU test; the translator's suite is CPU-only) AI-assisted: yes — MiniMax M3.1 Flash wrote the change; SenseNova 6.8 Flash Lite reviewed it read-only. ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
MoonEyes commented 2026-12-02 14:23:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T14:23:12Z.


RUN (independent run on Windows, #3077 head cb7aa587, merged locally into main f6dd2242 with git merge --no-ff, merge commit 6e758d09; the machine was busy with other runs)

Red (the new test file against tools/rdna2spirv.py as on main, the rest of the merge unchanged): python -I -m unittest discover -s tests/semantic -p test_translator_unreadable.py -> 4 tests, all 4 fail (2 failures, 2 errors): ValueError: invalid literal for int() ... 'v3x' (modifier), KeyError: 'r' (the sweep over the 112 fixtures), and two assertions that "operand not understood" is not in the message. File swapped back afterwards, git status clean.

Green (merge): the same command -> 4 tests, OK. python -I scripts/run_semantic_tests.py tests/semantic -> 560 files, 6791 tests, 0 files failed (1844 s, 12 jobs, machine under load). check_no_game_data.py on the three changed files: clean.

Mutations of tools/rdna2spirv.py (6), run against test_translator_unreadable.py:

  • raw-operand check in Gen.insn disabled: killed (2 failures, 1 error)
  • check only on the first operand: killed
  • check only on the destination operand: killed
  • _modifier_bits catching only IndexError: killed
  • modifier_bits returning [0,0,0] instead of raising Unsupported: SURVIVED
  • _modifier_bits without the closing-] check: SURVIVED (the int() failure still refuses such text)

Not covered: the two surviving mutations (the new test never reaches the modifier_bits raise through a path whose refusal depends on it, and the ] check). The two shapes the PR reports as findings (fewer operands than the op reads, a non-register operand) are not refused by this change. No GPU test; no unrefused-listing corpus run (needs game files).

Merge conditions: CI on head cb7aa587 all green (change-scope, check, linux-python-and-viewer, no-game-data, semantic-tests); no review and no comment on the PR; claimed in #2570 (TRANSLATOR-UNREADABLE-LISTING, comment 7339518154); the author has 13 merged PRs; no Depends on.

Verdict: PASS (red and green shown, no blocker; two mutations survive, a gap in the test and not in the change)

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7348457186 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3077#issuecomment-7348457186). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T14:23:12Z. --- RUN (independent run on Windows, #3077 head cb7aa587, merged locally into `main` f6dd2242 with `git merge --no-ff`, merge commit 6e758d09; the machine was busy with other runs) **Red** (the new test file against `tools/rdna2spirv.py` as on `main`, the rest of the merge unchanged): `python -I -m unittest discover -s tests/semantic -p test_translator_unreadable.py` -> 4 tests, all 4 fail (2 failures, 2 errors): `ValueError: invalid literal for int() ... 'v3x'` (modifier), `KeyError: 'r'` (the sweep over the 112 fixtures), and two assertions that "operand not understood" is not in the message. File swapped back afterwards, `git status` clean. **Green** (merge): the same command -> 4 tests, OK. `python -I scripts/run_semantic_tests.py tests/semantic` -> 560 files, 6791 tests, 0 files failed (1844 s, 12 jobs, machine under load). `check_no_game_data.py` on the three changed files: clean. **Mutations** of `tools/rdna2spirv.py` (6), run against `test_translator_unreadable.py`: - raw-operand check in `Gen.insn` disabled: killed (2 failures, 1 error) - check only on the first operand: killed - check only on the destination operand: killed - `_modifier_bits` catching only `IndexError`: killed - `modifier_bits` returning `[0,0,0]` instead of raising `Unsupported`: SURVIVED - `_modifier_bits` without the closing-`]` check: SURVIVED (the `int()` failure still refuses such text) **Not covered**: the two surviving mutations (the new test never reaches the `modifier_bits` raise through a path whose refusal depends on it, and the `]` check). The two shapes the PR reports as findings (fewer operands than the op reads, a non-register operand) are not refused by this change. No GPU test; no unrefused-listing corpus run (needs game files). **Merge conditions**: CI on head cb7aa587 all green (change-scope, check, linux-python-and-viewer, no-game-data, semantic-tests); no review and no comment on the PR; claimed in #2570 (TRANSLATOR-UNREADABLE-LISTING, comment 7339518154); the author has 13 merged PRs; no `Depends on`. Verdict: PASS (red and green shown, no blocker; two mutations survive, a gap in the test and not in the change) AI-assisted (Claude Code).
MoonEyes commented 2026-12-02 14:23:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T14:23:51Z.


Merging. Head cb7aa587b merges cleanly with main 69cd4106c and does not force a rebase of #2566. Independent red/green by MoonEyes' agent on head cb7aa587bb (red: 4 of 4 new tests fail on main; green: 4 tests OK and 560 files / 6791 tests pass; 6 mutations, 4 killed and 2 survive as a test gap), see https://github.com/ProjectLeonida/mandy/pull/3077#issuecomment-7348457186; CI green including no-game-data, no open review or question, item TRANSLATOR-UNREADABLE-LISTING claimed in #2570. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7348475002 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3077#issuecomment-7348475002). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T14:23:51Z. --- Merging. Head `cb7aa587b` merges cleanly with `main` `69cd4106c` and does not force a rebase of #2566. Independent red/green by MoonEyes' agent on head cb7aa587bb3a61712ca72300545bdc874dd595cc (red: 4 of 4 new tests fail on main; green: 4 tests OK and 560 files / 6791 tests pass; 6 mutations, 4 killed and 2 survive as a test gap), see https://github.com/ProjectLeonida/mandy/pull/3077#issuecomment-7348457186; CI green including no-game-data, no open review or question, item TRANSLATOR-UNREADABLE-LISTING claimed in #2570. Merged by MoonEyes. AI-assisted (Claude Code).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!3077
No description provided.