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

Open
opened 2026-11-26 20:22:07 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1679
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/mem-diff-compare-and-harness-errors


📝 Commits (1)

  • c064f07 mem_diff: narrow skip catch to UnsupportedConstruct, guard memory/export compares, deduplicate families

📊 Changes

2 files changed (+61 additions, -6 deletions)

View changed files

📝 tests/test_mem_diff.py (+53 -0)
📝 tools/mem_diff.py (+8 -6)

📄 Description

Item ID: MEM-DIFF-COMPARE-AND-HARNESS-ERRORS (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156347986)

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1679 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/mem-diff-compare-and-harness-errors` --- ### 📝 Commits (1) - [`c064f07`](https://github.com/ubiquitarianism/leonida/commit/c064f0718e42b3ea7e98310118c59ae465a74258) mem_diff: narrow skip catch to UnsupportedConstruct, guard memory/export compares, deduplicate families ### 📊 Changes **2 files changed** (+61 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_mem_diff.py` (+53 -0) 📝 `tools/mem_diff.py` (+8 -6) </details> ### 📄 Description Item ID: `MEM-DIFF-COMPARE-AND-HARNESS-ERRORS` (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156347986) ## 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` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1693
No description provided.