mem_diff: narrow skip catch to UnsupportedConstruct, guard memory/export compares, deduplicate families #1679

Open
github-bot wants to merge 1 commit from github-bot/gh-1679 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 07:55 UTC · original
IlyassRS3:fix/mem-diff-compare-and-harness-errors → main · +61 −6 · 2 files · 1 commits · open

Item ID: MEM-DIFF-COMPARE-AND-HARNESS-ERRORS (claimed in #1608)

Summary

  • Narrow run_fragment skip handling (tools/mem_diff.py):
    • Catch only spirv_mini_interp.UnsupportedConstruct instead of broad Exception in run_one() (matching tools/shader_diff.py), so real interpreter/harness failures (RuntimeError, AssertionError, KeyError, etc.) surface as harness-error (exit 2) instead of being silently downgraded to "skip".
  • Fix IndexError crashes in run_one() comparison logic:
    • Compute differing memory addresses ((memory.get(a, 0) & MASK32) != (ref.mem.get(a, 0) & MASK32)) before indexing bad[0], preventing an IndexError: list index out of range whenever one side explicitly stores 0 at an unseeded address absent from the other side.
    • Handle overlong %out_mrt0 exports (len(got) > 4 whose first 4 words match want) by reporting "export shape mismatch: expected 4 words, translated N" instead of crashing on bad[0], and mask exported words to 32 bits (MASK32).
  • Deduplicate --family selections:
    • Deduplicate families via sorted(set(families)) in generate_program() so repeated --family flags do not skew random family sampling.
  • Regression tests (tests/test_mem_diff.py):
    • Added CompareAndHarnessRegression covering UnsupportedConstruct vs unexpected RuntimeError harness error, zero-valued extra memory entries, overlong %out_mrt0 exports, and duplicate --family deduplication.

Checklist & Verification

  • AI-assisted: yes
  • Game data included: none (python3 -I scripts/check_no_game_data.py tools/mem_diff.py tests/test_mem_diff.py passed)
  • GPUs tested: none (hostless macOS CPU/unit test run)
  • Tests run:
    • python3 -W error -I tests/test_mem_diff.py -v: Ran 23 tests ... OK
    • Mutation test (CompareAndHarnessRegression against unpatched main tools/mem_diff.py): Ran 4 tests ... FAILED (failures=1, errors=3)
    • python3 -m compileall -q make_game.py tools tests: passed
    • python3 -I tests/test_text_write_line_endings.py: Ran 3 tests ... OK
**@⁠IlyassRS3** on GitHub · 2026-11-25 07:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1679) `IlyassRS3:fix/mem-diff-compare-and-harness-errors` → `main` · +61 −6 · 2 files · 1 commits · open Item ID: `MEM-DIFF-COMPARE-AND-HARNESS-ERRORS` (claimed in https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ## Summary - **Narrow `run_fragment` skip handling (`tools/mem_diff.py`)**: - Catch only `spirv_mini_interp.UnsupportedConstruct` instead of broad `Exception` in `run_one()` (matching `tools/shader_diff.py`), so real interpreter/harness failures (`RuntimeError`, `AssertionError`, `KeyError`, etc.) surface as `harness-error` (exit `2`) instead of being silently downgraded to `"skip"`. - **Fix `IndexError` crashes in `run_one()` comparison logic**: - Compute differing memory addresses (`(memory.get(a, 0) & MASK32) != (ref.mem.get(a, 0) & MASK32)`) before indexing `bad[0]`, preventing an `IndexError: list index out of range` whenever one side explicitly stores `0` at an unseeded address absent from the other side. - Handle overlong `%out_mrt0` exports (`len(got) > 4` whose first 4 words match `want`) by reporting `"export shape mismatch: expected 4 words, translated N"` instead of crashing on `bad[0]`, and mask exported words to 32 bits (`MASK32`). - **Deduplicate `--family` selections**: - Deduplicate `families` via `sorted(set(families))` in `generate_program()` so repeated `--family` flags do not skew random family sampling. - **Regression tests (`tests/test_mem_diff.py`)**: - Added `CompareAndHarnessRegression` covering `UnsupportedConstruct` vs unexpected `RuntimeError` harness error, zero-valued extra memory entries, overlong `%out_mrt0` exports, and duplicate `--family` deduplication. ## Checklist & Verification - **AI-assisted**: yes - **Game data included**: none (`python3 -I scripts/check_no_game_data.py tools/mem_diff.py tests/test_mem_diff.py` passed) - **GPUs tested**: none (hostless macOS CPU/unit test run) - **Tests run**: - `python3 -W error -I tests/test_mem_diff.py -v`: `Ran 23 tests ... OK` - Mutation test (`CompareAndHarnessRegression` against unpatched `main` `tools/mem_diff.py`): `Ran 4 tests ... FAILED (failures=1, errors=3)` - `python3 -m compileall -q make_game.py tools tests`: passed - `python3 -I tests/test_text_write_line_endings.py`: `Ran 3 tests ... OK`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:00:32 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 07:55 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 07:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1679#pullrequestreview-6053753014) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠GrahamboJangles on GitHub · 2026-11-25 11:57 UTC · original

Independent review (CPU-only Windows 11, python 3.14.9 python -I, fresh clone; head c064f0718, current main 57ba40bd6).

Coordination. Claim comment 7156347986 (IlyassRS3, 2026-11-25T07:52:26Z) predates the PR (created 07:55:04Z). The #1608 roster shows MEM-DIFF-COMPARE-AND-HARNESS-ERRORS -> #1679, and gh pr list --search "mem_diff" --state all returns exactly this PR — no duplicate work.

The new test bites (inverse check). tests/test_mem_diff.py at head: Ran 23 tests ... OK (the file at main runs 19, so +4 exactly as claimed). The same test file against main's tools/mem_diff.py: FAILED (failures=1, errors=3), and the errors name the real crashes — IndexError: list index out of range twice (zero-valued extra memory entry and overlong %out_mrt0 export), and the missing UnsupportedConstruct name. All 19 pre-existing tests stay green against main, so the delta is fully localized to the new CompareAndHarnessRegression class.

Whole-suite check. Clean main 57ba40bd6: 915 test files emitting unittest output, 13,976 tests, 6 pre-existing red files (test_bink_names, test_opus_tags, test_runner_calls_all_tests, test_runtime_paths, test_tool_stdout_encoding, test_world_names — all red on main itself, untouched by this PR). On the pr1679 branch tree: 914 files / 13,972. That −8 is noise from the branch base, not a regression: pr1679 is based on 3f81d46ac and predates the #1493 merge that added tests/semantic/test_valu_signed_literal64.py (−8) to main; +4 is the new class. Failing-file sets are identical (plus one flaky test_run_wine_tests error on the branch run only — that file is byte-identical on both trees).

Mergeability. git diff 3f81d46ac..origin/main over the PR's two files is empty — main's moves since the base (#1493 etc.) touch disjoint files, so this rebases clean. (GitHub still reports mergeable: UNKNOWN at posting time; the checks change-scope and no-game-data were pending at head when I looked.)

Code notes.

  • The narrowed except UnsupportedConstruct matches the sibling tools/shader_diff.py exactly (same import form at its line 42, same catch at its line 252). Worth knowing: spirv_mini_interp also raises InvalidModule (an AssertionError subclass), UndefinedResult, and ValueError, which the old broad except Exception silently turned into skip; these now surface as harness errors (exit 2). That's the item's stated intent — bad module shapes and undefined lane reads are harness bugs, not untested constructs — and it matches the rest of the tool family, so not a concern, just flagging the reclassification.
  • The memory-diff fix is right: main computed bad with unmasked != only after memory != ref.mem, so a zero at an address present on one side only crashed on bad[0]; the new code masks both sides and guards the empty list, and the export compare now masks words to MASK32 and reports export shape mismatch: expected 4 words, translated N for overlong exports instead of crashing.
  • sorted(set(families)) dedup verified: generate_program with families=["s_load","s_load","s_load","global"] reproduces the same lines/memory as the deduped call; without dedup main skews the family sampling.

python -I scripts/check_no_game_data.py tools/mem_diff.py tests/test_mem_diff.py exits 0; compileall clean on both files.

Verdict: LGTM — the four fixes are real crash fixes against the interpreter's known raise types, the regression tests bite only on unpatched main, and the branch rebases onto current main with zero file overlap.

AI-assisted (Hermes overnight shift). Environment: Windows 11, python 3.14.9 -I, no GPU involved.

**@⁠GrahamboJangles** on GitHub · 2026-11-25 11:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1679#issuecomment-7161739650) Independent review (CPU-only Windows 11, python 3.14.9 `python -I`, fresh clone; head `c064f0718`, current main `57ba40bd6`). **Coordination.** Claim comment 7156347986 (IlyassRS3, 2026-11-25T07:52:26Z) predates the PR (created 07:55:04Z). The #1608 roster shows `MEM-DIFF-COMPARE-AND-HARNESS-ERRORS -> #1679`, and `gh pr list --search "mem_diff" --state all` returns exactly this PR — no duplicate work. **The new test bites (inverse check).** `tests/test_mem_diff.py` at head: `Ran 23 tests ... OK` (the file at main runs 19, so +4 exactly as claimed). The same test file against **main's** `tools/mem_diff.py`: `FAILED (failures=1, errors=3)`, and the errors name the real crashes — `IndexError: list index out of range` twice (zero-valued extra memory entry and overlong `%out_mrt0` export), and the missing `UnsupportedConstruct` name. All 19 pre-existing tests stay green against main, so the delta is fully localized to the new `CompareAndHarnessRegression` class. **Whole-suite check.** Clean main `57ba40bd6`: 915 test files emitting unittest output, 13,976 tests, 6 pre-existing red files (test_bink_names, test_opus_tags, test_runner_calls_all_tests, test_runtime_paths, test_tool_stdout_encoding, test_world_names — all red on main itself, untouched by this PR). On the pr1679 branch tree: 914 files / 13,972. That −8 is noise from the branch base, not a regression: pr1679 is based on `3f81d46ac` and predates the #1493 merge that added `tests/semantic/test_valu_signed_literal64.py` (−8) to main; +4 is the new class. Failing-file sets are identical (plus one flaky `test_run_wine_tests` error on the branch run only — that file is byte-identical on both trees). **Mergeability.** `git diff 3f81d46ac..origin/main` over the PR's two files is empty — main's moves since the base (#1493 etc.) touch disjoint files, so this rebases clean. (GitHub still reports `mergeable: UNKNOWN` at posting time; the checks `change-scope` and `no-game-data` were pending at head when I looked.) **Code notes.** - The narrowed `except UnsupportedConstruct` matches the sibling `tools/shader_diff.py` exactly (same import form at its line 42, same catch at its line 252). Worth knowing: `spirv_mini_interp` also raises `InvalidModule` (an `AssertionError` subclass), `UndefinedResult`, and `ValueError`, which the old broad `except Exception` silently turned into `skip`; these now surface as harness errors (exit 2). That's the item's stated intent — bad module shapes and undefined lane reads are harness bugs, not untested constructs — and it matches the rest of the tool family, so not a concern, just flagging the reclassification. - The memory-diff fix is right: main computed `bad` with unmasked `!=` only after `memory != ref.mem`, so a zero at an address present on one side only crashed on `bad[0]`; the new code masks both sides and guards the empty list, and the export compare now masks words to `MASK32` and reports `export shape mismatch: expected 4 words, translated N` for overlong exports instead of crashing. - `sorted(set(families))` dedup verified: `generate_program` with `families=["s_load","s_load","s_load","global"]` reproduces the same lines/memory as the deduped call; without dedup main skews the family sampling. `python -I scripts/check_no_game_data.py tools/mem_diff.py tests/test_mem_diff.py` exits 0; `compileall` clean on both files. **Verdict: LGTM** — the four fixes are real crash fixes against the interpreter's known raise types, the regression tests bite only on unpatched main, and the branch rebases onto current main with zero file overlap. AI-assisted (Hermes overnight shift). Environment: Windows 11, python 3.14.9 `-I`, no GPU involved.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1679/head:github-bot/gh-1679'
git switch 'github-bot/gh-1679'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1679'
git switch 'github-bot/gh-1679'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1679'
git switch 'github-bot/gh-1679'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1679'
git switch 'main'
git merge --squash 'github-bot/gh-1679'
git switch 'main'
git merge --ff-only 'github-bot/gh-1679'
git switch 'main'
git merge 'github-bot/gh-1679'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.