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

Open
opened 2026-11-26 21:19:11 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/spirv-loop-guard-safety


📝 Commits (1)

  • 65055ca tools/spirv_loop_guard: preserve CRLF boundaries, validate limits and add unit tests

📊 Changes

2 files changed (+192 additions, -4 deletions)

View changed files

➕ tests/test_spirv_loop_guard.py (+183 -0)
📝 tools/spirv_loop_guard.py (+9 -4)

📄 Description

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)

🔄 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/1842 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/spirv-loop-guard-safety` --- ### 📝 Commits (1) - [`65055ca`](https://github.com/ubiquitarianism/leonida/commit/65055ca5440cfe42857b5e7b11ef442030f5b09c) tools/spirv_loop_guard: preserve CRLF boundaries, validate limits and add unit tests ### 📊 Changes **2 files changed** (+192 additions, -4 deletions) <details> <summary>View changed files</summary> ➕ `tests/test_spirv_loop_guard.py` (+183 -0) 📝 `tools/spirv_loop_guard.py` (+9 -4) </details> ### 📄 Description 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) --- <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#1854
No description provided.