mc-imperial / dredd

Framework for evaluating C/C++ compiler testing tools
Apache License 2.0
11 stars 3 forks source link

Add a function local __dredd_some_mutation_enabled check #242

Closed JamesLee-Jones closed 2 weeks ago

JamesLee-Jones commented 2 months ago

When Dredd instruments a program, it adds a check to the beginning of each mutation function of the form:

  if (!__dredd_some_mutation_enabled) return original_expression;

where __dredd_some_mutation_enabled is set to false if no mutations are enabled at runtime. This serves the purpose of skipping the mutant enabled checks if no mutants are enabled and thus speeds up the SUT. This variable is always true if any mutation is enabled and thus this optimization does nothing. It seems unlikely that a user would have only a version mutated with Dredd compiled without also having an unmutated copy of the SUT also compiled and thus also unlikey that this optimization would make much of a difference in practice.

What may be more useful is to have a function that takes in the local mutation ID and returns false if any mutant ID that falls within the function is enabled. This means this optimization would still be useful when mutations are enabled. This couldn't be implemented naively otherwise it would be more expensive than executing all of the if checks in the function.

afd commented 2 months ago

As we discussed during a meeting, this is a per-file variable. It serves the purpose of avoiding overhead when no mutants are enabled for a particular file, which should be a fairly common case in practice. So, the current variable is useful.

Still, it's worth having a think about whether a per-function variable could be useful, so let's keep this open for now.

afd commented 2 weeks ago

Closing because, on reflection, I don't think this will be easy to do. A Dredd mutator function may be called from various different places, so it seems hard to know whether a function will always have no mutations enabled.