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

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

@⁠kirigayakazima on GitHub · 2026-11-25 12:59 UTC · original
kirigayakazima:fix/spirv-loop-guard-safety → main · +192 −4 · 2 files · 1 commits · open

Claimed in the coordination issue as: SPIRV-LOOP-GUARD-CRLF-SAFETY-AND-TESTS (#1608)

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)
**@⁠kirigayakazima** on GitHub · 2026-11-25 12:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1842) `kirigayakazima:fix/spirv-loop-guard-safety` → `main` · +192 −4 · 2 files · 1 commits · open Claimed in the coordination issue as: SPIRV-LOOP-GUARD-CRLF-SAFETY-AND-TESTS (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:08:00 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 13:20 UTC · original

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.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 13:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1842#issuecomment-7163633171) 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.
Author
Owner

@⁠DeadlyChirp on GitHub · 2026-11-25 15:37 UTC · original

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.)

**@⁠DeadlyChirp** on GitHub · 2026-11-25 15:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1842#issuecomment-7167135829) 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.)
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/1842/head:github-bot/gh-1842'
git switch 'github-bot/gh-1842'

Merge

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