Skip to content

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

Merged
ubiquitarianism merged 3 commits into
ProjectLeonida:mainfrom
qhukz13:cont/semantic-mutants-docstrings
Nov 24, 2026
Merged

ubiquitarianism merged 3 commits into
ProjectLeonida:mainfrom
qhukz13:cont/semantic-mutants-docstrings

Conversation

@qhukz13

@qhukz13 qhukz13 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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 21625bc, Linux, CPU only; no GPU needed. No game files.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@GeorgiyDemo

Copy link
Copy Markdown
Contributor

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.

qhukz13 added a commit to qhukz13/leonida-continued that referenced this pull request Nov 24, 2026
…longer hide or split a docstring

Review on ProjectLeonida#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 <noreply@anthropic.com>
@qhukz13

qhukz13 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — both reproduced and fixed in 4a5458b:

  • 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 e3c4d0c and passes now. tests/test_semantic_mutants.py: 14 tests OK. #734, which builds on this branch, is rebased on it (20 tests OK).

@lixonik

lixonik commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

qhukz13 and others added 3 commits November 24, 2026 16:01
…eported as surviving mutants

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 <noreply@anthropic.com>
…idened to the whole string

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 <noreply@anthropic.com>
…longer hide or split a docstring

Review on ProjectLeonida#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 <noreply@anthropic.com>
@qhukz13
qhukz13 force-pushed the cont/semantic-mutants-docstrings branch from 4a5458b to ea10ffd Compare November 24, 2026 14:02
@ubiquitarianism
ubiquitarianism merged commit 2f0d225 into ProjectLeonida:main Nov 24, 2026
6 of 9 checks passed
SwavyJayden pushed a commit to SwavyJayden/leonida that referenced this pull request Nov 24, 2026
…longer hide or split a docstring

Review on ProjectLeonida#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 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants