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

Don't generate a mutation for .with_capacity #315

Closed
5 tasks
sourcefrog opened this issue Mar 24, 2024 Discussed in #314 · 1 comment · Fixed by #444
Closed
5 tasks

Don't generate a mutation for .with_capacity #315

sourcefrog opened this issue Mar 24, 2024 Discussed in #314 · 1 comment · Fixed by #444
Assignees
Labels
enhancement New feature or request generate Patterns of mutation good first issue Good for newcomers

Comments

@sourcefrog
Copy link
Owner

sourcefrog commented Mar 24, 2024

Discussed in #314

Originally posted by pashadia March 21, 2024
Hi all,

New contributor here, first of all congratulations on a great project!

I've used cargo mutants on a fairly large codebase (12kloc). One of the things that appear regularly on my project is to preallocate memory for some data structures. For instance, we use things like let v = Vec::with_capacity(a+b);. Obviously, cargo-mutants is generating a mutation for the argument, into things like a-b or a*b. However, this won't break any tests, as it doesn't actually introduce a bug in functionality, only the memory allocation footprint may be different.

My proposal is to remove the generation of mutations for the .with_capacity parameter, for all the structs in std::collections, and perhaps not only. I would gladly attempt an implementation, if this proposal is well received.


  • Add config, option, for skip_calls: Vec<String>
  • Set this by default to with_capacity
  • Don't generate mutants inside them when walking the tree
  • Document in the manual
  • Test
@sourcefrog sourcefrog added enhancement New feature or request good first issue Good for newcomers generate Patterns of mutation labels Mar 24, 2024
@sourcefrog
Copy link
Owner Author

Maybe this is best done by adding a configuration for functions whose calls will not be mutated, and that could start with with_capacity.

@sourcefrog sourcefrog self-assigned this Jun 11, 2024
sourcefrog added a commit that referenced this issue Nov 12, 2024
Partly addresses #315
@sourcefrog sourcefrog linked a pull request Nov 18, 2024 that will close this issue
sourcefrog added a commit that referenced this issue Nov 18, 2024
Adds new `skip_calls` args and config key, which prevent mutating
arguments to named functions.

Concretely these default to `with_capacity` which is often uninteresting
to mutate.

Fixes #315
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request generate Patterns of mutation good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant