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

Manually merged
github merged 4 commits from gh-pr/734/head into gh-pr/734/base 2026-11-26 09:18:39 +00:00
Owner

@⁠qhukz13 on GitHub · 2026-11-24 13:06 UTC · original
qhukz13:cont/mutants-py-logic → main · +353 −1 · 2 files · 4 commits · merged 2026-11-24 16:06 UTC

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

**@⁠qhukz13** on GitHub · 2026-11-24 13:06 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/734) `qhukz13:cont/mutants-py-logic` → `main` · +353 −1 · 2 files · 4 commits · merged 2026-11-24 16:06 UTC 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)
mutants_for treated any line that starts with a quote as code (meant for `f"... OpIAdd ..."` emit lines), so a
docstring that names an opcode or GLSL op produced mutants that can never fail a test and were always reported
SURVIVED: `--function nminmax_f32` listed 5 mutants, 4 of them in its docstring, and 47 across rdna2spirv.py.
Tokenize the mutated range (dedented) and skip strings that stand alone as a statement; a range that does not
tokenize keeps the old behaviour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review on ItsNotRexed/Leonida#9432 (Gevroska): `--lines 595-595` falls inside u16_half's docstring, so the tokenized slice had no
opening delimiter and the text was mutated as code. Widen the tokenized span to whole triple-quoted strings,
counting delimiters from the enclosing def or class (a text scan, cheap inside the long dispatch method).
Every one of the translator's 1,049 docstring lines now gives 0 mutants as a one-line range.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review on #660 (lixonik): a comment holding `"""` before a docstring flipped the delimiter count, so a --lines range
inside the docstring was mutated as code, and a docstring written as adjacent literals ("a " "b") was not recognised.
Follow triple-quote delimiters with a small scanner that skips comments, one-line strings and escaped delimiters,
and take a run of adjacent string tokens ending the statement as one docstring. A literal that is read by the code
after it stays code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The tool only mutated SPIR-V emission (opcode pairs, self.cu constants, OpSelect arms, the last operand), so the
translator's analysis code - register liveness, lane-mask tracking, operand checks - got no mutants at all:
`--function read_before_write_vgprs` listed 0. Mutate its names and operators by token, so strings, f-strings and
comments stay as they are: comparisons flipped (== / !=, < / <=, > / >=, in / not in, is / is not; the `in` of a
for loop or comprehension stays), and / or, a `not` dropped, True / False, and a one-line statement that can fail
silently replaced by `pass` (a call that is not an emit, an augmented assignment, a rebinding of a name assigned
earlier in the range). The branch's own `if op ...` condition is left alone. Repeated labels on one line are
numbered from the left.

On #658's read_before_write_vgprs with its test file: 36 mutants, 27 caught; the survivors include the
`carried.difference_update(dst)` removal found equivalent by hand in that review, and `regs += x["r"]` (vlist
operands), which no case reaches.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:18:38 +00:00
github manually merged commit 15f3599111 into gh-pr/734/base 2026-11-26 09:18:39 +00:00
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 13:24 UTC · original · approved these changes

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.
**@⁠abnalstlll-byte** on GitHub · 2026-11-24 13:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/734#pullrequestreview-6039969563) · **approved these changes** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.