Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate finding modules from generating mutants? #329

Open
sourcefrog opened this issue Apr 13, 2024 · 0 comments
Open

Separate finding modules from generating mutants? #329

sourcefrog opened this issue Apr 13, 2024 · 0 comments
Labels
internal Internal refactors and infrastructure maybe Uncertain if this is a good idea, discuss before implementing modules Bugs about following Rust `mod` statements performance Making cargo mutants faster

Comments

@sourcefrog
Copy link
Owner

In 24.3, we do one pass over source files, parsing them using syn and identifying (1) other source files that we need to recurse into and (2) mutants from this source file.

Possibly these should be separated into separate passes that each walk over the syn AST:

  1. Parse a file into an AST and find just the mod statements that point to other files we need to read. Queue those other files and repeat until we have all the source files loaded into memory.
  2. Walk each source file and generate mutants from it.

That is to say the two fields that are currently in Discovered would be generated separately:

pub struct Discovered {
pub mutants: Vec<Mutant>,
pub files: Vec<SourceFile>,
}

Why?

  • It would make the AST walk code somewhat simpler by separating concerns: not only less code in the visitor but also simpler interactions with the code that calls it
  • The mutant-generation code would be a pure function of a source tree already in memory
  • Probably it would be easier to test each part, e.g. we could write unit tests for mutations that just work off a string of source code, without needing a whole tree
  • It would probably also make it simpler to generate mutants or parse files in parallel on multiple threads.
  • Maybe this makes ownership simpler: the per-file mutant generator and all the mutants generated from it could reference and not outlive the source file they point into.

Why not?

  • We would walk each AST twice which would have some CPU cost.
  • Maybe it's just not worth it as a refactor.

Generally all the time taken walking the tree and generating mutants should be pretty trivial compared to the time taken actually running tests, so perhaps it's not important to make changes to optimize speed.

Maybe we should benchmark just --list --json on some large tree.

@sourcefrog sourcefrog added performance Making cargo mutants faster maybe Uncertain if this is a good idea, discuss before implementing internal Internal refactors and infrastructure labels Apr 13, 2024
@sourcefrog sourcefrog added the modules Bugs about following Rust `mod` statements label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Internal refactors and infrastructure maybe Uncertain if this is a good idea, discuss before implementing modules Bugs about following Rust `mod` statements performance Making cargo mutants faster
Projects
None yet
Development

No branches or pull requests

1 participant