semantic_mutants: mutate the Python logic around the emission too (MUTANTS-PY-LOGIC) #734

Merged
qhukz13 merged 4 commits from upstream-pr/734 into main 2026-11-24 16:06:31 +00:00
qhukz13 commented 2026-11-24 13:06:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by qhukz13 on 2026-11-24T13:06:40Z.


Claimed in the coordination issue as: MUTANTS-PY-LOGIC

Depends on: #660 (same file; this branch is on top of it, so its two commits show here until #660 is merged)

What and why

tools/semantic_mutants.py only mutated SPIR-V emission (opcode pairs, self.cu constants, OpSelect arms, the last operand), so the translator's Python analysis code - register liveness, lane-mask tracking, operand checks - got no mutants: --function read_before_write_vgprs listed 0. In the reviews of #658, #647, #593 and #637 the logic mutations had to be written by hand.

This adds token-based mutations of that code (strings, f-strings and comments are left alone):

  • comparisons flipped: ==/!=, </<=, >/>=, in/not in, is/is not (the in of a for loop or comprehension stays);
  • and/or, a not dropped, True/False;
  • a one-line statement that can fail silently replaced by pass: a call that is not an emit, an augmented assignment, or a rebinding of a name assigned earlier in the range (removing a first assignment would only be a NameError).

The branch's own if op ... condition gets none (a mutant there only sends other ops through the branch). The same flip twice on one line is numbered from the left (and -> or #1, #2).

Tested

  • python -I tests/test_semantic_mutants.py: 19 tests OK. The new PythonLogic class covers each mutation kind, what is left alone (strings, comments, emit lines, the branch condition, first assignments, loop in), the numbering, and that every mutant still compiles.
  • On #658's head, --function read_before_write_vgprs tests/semantic/test_writelane_read_before_write.py: 36 mutants, 27 caught in 40 s. The survivors include carried.difference_update(dst) removed, which my hand-written review of #658 found equivalent, and regs += x["r"] removed (vlist operands), which no case reaches.
  • tests/test_text_write_line_endings.py OK, scripts/check_no_game_data.py clean, compileall clean.

Linux, CPU only; no GPU, no game files.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5472721032 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/734). Originally posted by [qhukz13](https://github.com/qhukz13) on 2026-11-24T13:06:40Z. --- Claimed in the coordination issue as: MUTANTS-PY-LOGIC Depends on: #660 (same file; this branch is on top of it, so its two commits show here until #660 is merged) ### What and why `tools/semantic_mutants.py` only mutated SPIR-V emission (opcode pairs, `self.cu` constants, `OpSelect` arms, the last operand), so the translator's Python analysis code - register liveness, lane-mask tracking, operand checks - got no mutants: `--function read_before_write_vgprs` listed 0. In the reviews of #658, #647, #593 and #637 the logic mutations had to be written by hand. This adds token-based mutations of that code (strings, f-strings and comments are left alone): - comparisons flipped: `==`/`!=`, `<`/`<=`, `>`/`>=`, `in`/`not in`, `is`/`is not` (the `in` of a `for` loop or comprehension stays); - `and`/`or`, a `not` dropped, `True`/`False`; - a one-line statement that can fail silently replaced by `pass`: a call that is not an `emit`, an augmented assignment, or a rebinding of a name assigned earlier in the range (removing a first assignment would only be a NameError). The branch's own `if op ...` condition gets none (a mutant there only sends other ops through the branch). The same flip twice on one line is numbered from the left (`and -> or #1`, `#2`). ### Tested - `python -I tests/test_semantic_mutants.py`: 19 tests OK. The new `PythonLogic` class covers each mutation kind, what is left alone (strings, comments, emit lines, the branch condition, first assignments, loop `in`), the numbering, and that every mutant still compiles. - On #658's head, `--function read_before_write_vgprs tests/semantic/test_writelane_read_before_write.py`: 36 mutants, 27 caught in 40 s. The survivors include `carried.difference_update(dst)` removed, which my hand-written review of #658 found equivalent, and `regs += x["r"]` removed (vlist operands), which no case reaches. - `tests/test_text_write_line_endings.py` OK, `scripts/check_no_game_data.py` clean, `compileall` clean. Linux, CPU only; no GPU, no game files. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
abnalstlll-byte commented 2026-11-24 13:24:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T13:24:34Z.

Review: APPROVED


Audited and verified. Clean-room compliant.

  • Expands semantic_mutants.py to mutate Python logic constructs around shader emission (comparisons, boolean operators, membership, identity, statement removal).
  • Distinguishes code from docstrings and comments.
  • Test coverage in tests/test_semantic_mutants.py passes.
<!-- greyfinch-sync:ubiquitarianism/leonida:review:6039969563 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/734#pullrequestreview-6039969563). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T13:24:34Z. **Review:** APPROVED --- Audited and verified. Clean-room compliant. - Expands semantic_mutants.py to mutate Python logic constructs around shader emission (comparisons, boolean operators, membership, identity, statement removal). - Distinguishes code from docstrings and comments. - Test coverage in tests/test_semantic_mutants.py passes.
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!734
No description provided.