tools/spirv_loop_guard: preserve CRLF boundaries, validate limits and add unit tests #1842

Merged
kirigayakazima merged 1 commit from upstream-pr/1842 into main 2026-11-28 11:44:02 +00:00
kirigayakazima commented 2026-11-25 12:59:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-25T12:59:11Z.


Claimed in the coordination issue as: SPIRV-LOOP-GUARD-CRLF-SAFETY-AND-TESTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163090236)

What and why

  • Exclude \r from _LINE (([^;\r\n]*)) in tools/spirv_loop_guard.py so Windows CRLF SPIR-V assembly does not split appended OpPhi incoming pairs across a bare \r.
  • Reject non-integer values in parse_limit() with argparse.ArgumentTypeError and reject bool/non-int limits upfront in add_guards() (ValueError).
  • Guard len(args) >= 2 for OpConstant and raise ValueError when guard declarations are needed without any OpFunction instead of failing with IndexError or TypeError.
  • Add standard-library unit tests in tests/test_spirv_loop_guard.py.

Tested

  • python -I tests/test_spirv_loop_guard.py -v -> Ran 9 tests in 0.001s, OK.
  • Detached upstream/main (98c2f777) baseline worktree with tests/test_spirv_loop_guard.py -> Ran 9 tests in 0.004s, FAILED (failures=4, errors=6).
  • python -I tests/test_ci_registration.py -> Ran 16 tests in 5.189s, OK.
  • python -I tests/test_text_write_line_endings.py -> Ran 3 tests in 11.779s, OK.
  • python -I scripts/check_no_game_data.py tools/spirv_loop_guard.py tests/test_spirv_loop_guard.py -> exit 0.
  • python -I -m compileall -q tools/spirv_loop_guard.py tests/test_spirv_loop_guard.py and git diff --check -> exit 0.

GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64)

AI-assisted: yes

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. (n/a)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5491793586 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1842). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-25T12:59:11Z. --- Claimed in the coordination issue as: SPIRV-LOOP-GUARD-CRLF-SAFETY-AND-TESTS (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7163090236) ### What and why - Exclude `\r` from `_LINE` (`([^;\r\n]*)`) in `tools/spirv_loop_guard.py` so Windows CRLF SPIR-V assembly does not split appended `OpPhi` incoming pairs across a bare `\r`. - Reject non-integer values in `parse_limit()` with `argparse.ArgumentTypeError` and reject `bool`/non-`int` limits upfront in `add_guards()` (`ValueError`). - Guard `len(args) >= 2` for `OpConstant` and raise `ValueError` when guard declarations are needed without any `OpFunction` instead of failing with `IndexError` or `TypeError`. - Add standard-library unit tests in `tests/test_spirv_loop_guard.py`. ### Tested - `python -I tests/test_spirv_loop_guard.py -v` -> `Ran 9 tests in 0.001s`, `OK`. - Detached `upstream/main` (`98c2f777`) baseline worktree with `tests/test_spirv_loop_guard.py` -> `Ran 9 tests in 0.004s`, `FAILED (failures=4, errors=6)`. - `python -I tests/test_ci_registration.py` -> `Ran 16 tests in 5.189s`, `OK`. - `python -I tests/test_text_write_line_endings.py` -> `Ran 3 tests in 11.779s`, `OK`. - `python -I scripts/check_no_game_data.py tools/spirv_loop_guard.py tests/test_spirv_loop_guard.py` -> exit `0`. - `python -I -m compileall -q tools/spirv_loop_guard.py tests/test_spirv_loop_guard.py` and `git diff --check` -> exit `0`. GPUs tested: n/a (CPU/stdlib Python tests on Windows 11 x64) AI-assisted: yes ### 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. - [ ] A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)
GeorgiyDemo commented 2026-11-25 13:20:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by GeorgiyDemo on 2026-11-25T13:20:22Z.


Tested 65055ca54 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 384abe5b0 (Python shader tool; no GPU):

  • pytest 9.2.0 on tests/test_spirv_loop_guard.py: 9 passed, 13 subtests passed at this head.
  • The same file on main: 10 failed, 6 passed, 6 subtests — the CRLF boundary and parse_limit validation cases are new (no test file existed before).
  • Not run: a real CRLF SPIR-V listing through the guard; the tests build the modules synthetically.

AI-assisted; synthetic fixtures only, no game data.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7163633171 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1842#issuecomment-7163633171). Originally posted by [GeorgiyDemo](https://github.com/GeorgiyDemo) on 2026-11-25T13:20:22Z. --- Tested `65055ca54` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `384abe5b0` (Python shader tool; no GPU): - pytest 9.2.0 on `tests/test_spirv_loop_guard.py`: **9 passed, 13 subtests passed** at this head. - The same file on `main`: **10 failed**, 6 passed, 6 subtests — the CRLF boundary and `parse_limit` validation cases are new (no test file existed before). - Not run: a real CRLF SPIR-V listing through the guard; the tests build the modules synthetically. AI-assisted; synthetic fixtures only, no game data.
DeadlyChirp commented 2026-11-25 15:37:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-25T15:37:43Z.


Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

python -m pytest -q tests/test_spirv_loop_guard.py:

  • PR: 9 passed.
  • The new test file run against main's tool: 10 failed, 6 passed. So the tests catch the problem, and the change fixes it on Windows.

(AI-assisted test run; output checked by hand.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7167135829 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1842#issuecomment-7167135829). Originally posted by [DeadlyChirp](https://github.com/DeadlyChirp) on 2026-11-25T15:37:43Z. --- Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. `python -m pytest -q tests/test_spirv_loop_guard.py`: - PR: 9 passed. - The new test file run against main's tool: 10 failed, 6 passed. So the tests catch the problem, and the change fixes it on Windows. (AI-assisted test run; output checked by hand.)
sodove commented 2026-11-28 11:28:01 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T11:28:01Z.


#1842 | head 65055ca5440cfe42857b5e7b11ef442030f5b09c | python3 -I tests/test_spirv_loop_guard.py -v, py -3.12 -I tests/test_spirv_loop_guard.py -v | red: 9 run, 4 failures, 6 errors (Linux) / 9 run, 4 failures, 6 errors (Windows) | green: 9 passed (Linux) / 9 passed (Windows) | Red → green

The file passed after the merge on Linux and Windows, including the test that checks CRLF boundaries during OpPhi rewriting.

Copied the PR tests onto clean main 4a54aedcb6b66525e0c9f72a6ea10263337c9141 for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native Windows used Python 3.12.10. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. Batch claim.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238570068 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1842#issuecomment-7238570068). Originally posted by [sodove](https://github.com/sodove) on 2026-11-28T11:28:01Z. --- #1842 | head `65055ca5440cfe42857b5e7b11ef442030f5b09c` | `python3 -I tests/test_spirv_loop_guard.py -v`, `py -3.12 -I tests/test_spirv_loop_guard.py -v` | red: 9 run, 4 failures, 6 errors (Linux) / 9 run, 4 failures, 6 errors (Windows) | green: 9 passed (Linux) / 9 passed (Windows) | **Red → green** The file passed after the merge on Linux and Windows, including the test that checks CRLF boundaries during OpPhi rewriting. Copied the PR tests onto clean main `4a54aedcb6b66525e0c9f72a6ea10263337c9141` for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native Windows used Python 3.12.10. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7238450840).
DadaCap commented 2026-11-28 11:44:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:44:04Z.


Merged, thank you @kirigayakazima! This PR (tools/spirv_loop_guard: preserve CRLF boundaries, validate limits and add unit tests) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238747065 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1842#issuecomment-7238747065). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T11:44:04Z. --- Merged, thank you @kirigayakazima! This PR (tools/spirv_loop_guard: preserve CRLF boundaries, validate limits and add unit tests) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
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!1842
No description provided.