semantic_mutants: leave docstrings alone, so their op names are not reported as surviving mutants (OLD-9432) #660

Manually merged
github merged 3 commits from gh-pr/660/head into gh-pr/660/base 2026-11-26 09:14:39 +00:00
Owner

@⁠qhukz13 on GitHub · 2026-11-24 11:13 UTC · original
qhukz13:cont/semantic-mutants-docstrings → main · +138 −0 · 2 files · 3 commits · merged 2026-11-24 16:06 UTC

Claimed in the coordination issue as: OLD-9432 (restoration of ItsNotRexed/Leonida#9432, closed unmerged when that repository went private)

mutants_for treated any line starting with a quote as code (meant for f"... OpIAdd ..." emit lines), so a docstring naming an opcode 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 and skip strings that stand alone as a statement; a range that does not tokenize keeps the old behaviour.
  • A --lines range that starts inside a docstring is widened to the whole string (from review on the original PR: --lines 595-595 inside u16_half's docstring was mutated as code). Every one of the translator's 1,049 docstring lines now gives 0 mutants as a one-line range.

Tested: python -I tests/test_semantic_mutants.py (13 tests OK) on main 21625bca8, Linux, CPU only; no GPU needed. No game files.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠qhukz13** on GitHub · 2026-11-24 11:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/660) `qhukz13:cont/semantic-mutants-docstrings` → `main` · +138 −0 · 2 files · 3 commits · merged 2026-11-24 16:06 UTC Claimed in the coordination issue as: OLD-9432 (restoration of ItsNotRexed/Leonida#9432, closed unmerged when that repository went private) `mutants_for` treated any line starting with a quote as code (meant for `f"... OpIAdd ..."` emit lines), so a docstring naming an opcode 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 and skip strings that stand alone as a statement; a range that does not tokenize keeps the old behaviour. - A `--lines` range that starts inside a docstring is widened to the whole string (from review on the original PR: `--lines 595-595` inside `u16_half`'s docstring was mutated as code). Every one of the translator's 1,049 docstring lines now gives 0 mutants as a one-line range. Tested: `python -I tests/test_semantic_mutants.py` (13 tests OK) on `main` 21625bca8, Linux, CPU only; no GPU needed. 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]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:14:37 +00:00
github manually merged commit ea10ffd572 into gh-pr/660/base 2026-11-26 09:14:39 +00:00
Author
Owner

@⁠lixonik on GitHub · 2026-11-24 11:53 UTC · original · reviewed

Independent CLI check at e3c4d0c1 with synthetic Python sources and --lines N-N --list. A one-line range inside an ordinary multiline docstring yields zero mutants. Adding a preceding comment containing """ makes the equivalent range yield one mutant, OpIAdd to OpISub. An implicitly concatenated first-statement docstring also yields one mutant: "OpIAdd is an example. " "Emit an instruction.".

Python's ast.get_docstring() recognizes both variants. The first appears to come from counting delimiters in raw lines and the second from treating adjacent string tokens as separate statements. A scan of the checked-in translator's docstrings found zero mutants, so these are synthetic coverage cases. Could both be added to the regression tests? Relevant logic

AI-assisted testing. No game data or GPU used.

**@⁠lixonik** on GitHub · 2026-11-24 11:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/660#pullrequestreview-6038702490) · **reviewed** Independent CLI check at `e3c4d0c1` with synthetic Python sources and `--lines N-N --list`. A one-line range inside an ordinary multiline docstring yields zero mutants. Adding a preceding comment containing `"""` makes the equivalent range yield one mutant, `OpIAdd` to `OpISub`. An implicitly concatenated first-statement docstring also yields one mutant: `"OpIAdd is an example. " "Emit an instruction."`. Python's `ast.get_docstring()` recognizes both variants. The first appears to come from counting delimiters in raw lines and the second from treating adjacent string tokens as separate statements. A scan of the checked-in translator's docstrings found zero mutants, so these are synthetic coverage cases. Could both be added to the regression tests? [Relevant logic](https://github.com/ubiquitarianism/leonida/blob/e3c4d0c1f6c282f8587b8cea6637d4ff7db96810/tools/semantic_mutants.py#L151-L186) AI-assisted testing. No game data or GPU used.
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-24 13:03 UTC · original

Ran e3c4d0c1f on Apple M5 Pro, macOS 26.7.3 (25G342), Python 3.15.2, against main d42773d07:

  • tests/test_semantic_mutants.py: 13 tests OK at this head.
  • The same file against main's tools/semantic_mutants.py fails 5 of 13, so the docstring handling is covered by the new cases.

No GPU leg (CPU tool). AI-assisted.

**@⁠GeorgiyDemo** on GitHub · 2026-11-24 13:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/660#issuecomment-7132295981) Ran `e3c4d0c1f` on Apple M5 Pro, macOS 26.7.3 (25G342), Python 3.15.2, against `main` `d42773d07`: - `tests/test_semantic_mutants.py`: 13 tests OK at this head. - The same file against `main`'s `tools/semantic_mutants.py` fails 5 of 13, so the docstring handling is covered by the new cases. No GPU leg (CPU tool). AI-assisted.
Author
Owner

@⁠qhukz13 on GitHub · 2026-11-24 13:13 UTC · original

Thanks — both reproduced and fixed in 4a5458b05:

  • A """ in a comment no longer counts as a delimiter: string_context now follows triple quotes with a small scanner that skips comments, one-line strings and escaped delimiters, instead of counting them in raw lines.
  • Adjacent literals are one docstring: docstring_lines takes a run of string tokens that ends the statement ("OpIAdd is an example. " "Emit an instruction."). A literal the code goes on to read (("..." "...") and self.emit(...)) stays code and is still mutated.

Both cases are in test_docstring_after_a_comment_with_quotes_and_concatenated_docstring, plus the stays-code one; it fails on e3c4d0c1f and passes now. tests/test_semantic_mutants.py: 14 tests OK. #734, which builds on this branch, is rebased on it (20 tests OK).

**@⁠qhukz13** on GitHub · 2026-11-24 13:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/660#issuecomment-7132519148) Thanks — both reproduced and fixed in 4a5458b05: - A `"""` in a comment no longer counts as a delimiter: `string_context` now follows triple quotes with a small scanner that skips comments, one-line strings and escaped delimiters, instead of counting them in raw lines. - Adjacent literals are one docstring: `docstring_lines` takes a run of string tokens that ends the statement (`"OpIAdd is an example. " "Emit an instruction."`). A literal the code goes on to read (`("..." "...") and self.emit(...)`) stays code and is still mutated. Both cases are in `test_docstring_after_a_comment_with_quotes_and_concatenated_docstring`, plus the stays-code one; it fails on e3c4d0c1f and passes now. `tests/test_semantic_mutants.py`: 14 tests OK. #734, which builds on this branch, is rebased on it (20 tests OK).
Author
Owner

@⁠lixonik on GitHub · 2026-11-24 13:35 UTC · original

Thanks for the fix. I independently retested 4a5458b05 from a full Git checkout on Windows. The new regression test covering the quote-in-comment case, the concatenated docstring, and the expression that should remain mutable passes. The full python -I -B tests/test_semantic_mutants.py -v run passed all 14 tests.

AI-assisted testing with synthetic inputs. No game data or GPU used.

**@⁠lixonik** on GitHub · 2026-11-24 13:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/660#issuecomment-7133055028) Thanks for the fix. I independently retested `4a5458b05` from a full Git checkout on Windows. The new regression test covering the quote-in-comment case, the concatenated docstring, and the expression that should remain mutable passes. The full `python -I -B tests/test_semantic_mutants.py -v` run passed all 14 tests. AI-assisted testing with synthetic inputs. No game data or GPU used.
This discussion has been locked. Commenting is limited to contributors.
No description provided.