Conversation
A mutant is a copy of its function with one node replaced. Generation rebuilt the function tree (deep_replace) and rendered it once per mutant. Now the function is rendered once through a CodegenState subclass that records the output span of its name and of every mutation target, with the indentation in effect there. A mutant's text is the function's text with those two spans replaced; the replacement node is rendered with the recorded indentation, so the result matches rendering the rebuilt tree. A PrerenderedFunction node carries the text through module assembly and emits it verbatim, so line spans and the rest of the pipeline are unchanged. A mutant whose target was rendered more than once, or precedes the function name, falls back to the tree rebuild. CodegenState is libcst internal API, but libcst's own node classes are built on it. The test generates the generation corpus, plus sources with nested blocks, decorators, multi-line expressions, tabs and continuation lines, both ways and compares code, mutant names, line spans and hashes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In my testing, the mutant generation phase ran about 3x faster with text splicing. There is a small compatibility risk because this implementation relies on an internal libCST API, which won't have the same compatibility SLA as public facing parts. On the other hand, this internal class is small (25 lines), has been stable for years, and a lot of libCST is built on top of it. As explained later, the tree build method remains available.
A mutant is a copy of its function with one node replaced. Generation rebuilt the function tree (deep_replace) and rendered it once per mutant.
Now the function is rendered once through a CodegenState subclass that records the output span of its name and of every mutation target, with the indentation in effect there. A mutant's text is the function's text with those two spans replaced; the replacement node is rendered with the recorded indentation, so the result matches rendering the rebuilt tree. A PrerenderedFunction node carries the text through module assembly and emits it verbatim, so line spans and the rest of the pipeline are unchanged.
A mutant whose target was rendered more than once, or precedes the function name, falls back to the tree rebuild. CodegenState is libcst internal API, but libcst's own node classes are built on it.
The test generates the generation corpus, plus sources with nested blocks, decorators, multi-line expressions, tabs and continuation lines, both ways and compares code, mutant names, line spans and hashes.