jmid / mutaml

An OCaml mutation tester
BSD 2-Clause "Simplified" License
66 stars 3 forks source link

Instrumentation and preprocessing #9

Open epatrizio opened 1 year ago

epatrizio commented 1 year ago

Hello, It seems that the instrumentation is launched before the preprocessor, generating errors in some cases. Here is a minimalistic example with sedlex preprocessing :

$ git clone https://github.com/jmid/mutaml.git
$ cd mutaml
$ opam install .
$ cd ..
$ git clone https://github.com/epatrizio/mutaml_exp.git
$ cd mutaml_exp
$ dune runtest --instrument-with mutaml
File "lib/dune", line 4, characters 2-18:
4 |   (pps sedlex.ppx))
      ^^^^^^^^^^^^^^^^
Running mutaml instrumentation on "lib/lib.ml"
Randomness seed: 374585493   Mutation rate: 50   GADTs enabled: true
Created 4 mutations of lib/lib.ml
Writing mutation info to lib/lib.muts
File "lib/lib.ml", line 12, characters 4-24:
12 |   | "hello" -> token buf
         ^^^^^^^^^^^^^^^^^^^^
Error: Sedlex: 'when' guards are not supported

What happens is that mutaml inserts some when guards on a branch from a match%sedlex construct. Sedlex then complains because it can not handle such guards. I don't know if it's possible to tell dune to instrument the code only after preprocessing ? Otherwise, should the instrumentation tool (mutaml) be careful and not modify code that contains preprocessing annotations ? Thanks a lot!

jmid commented 1 year ago

Acknowledged! Thanks for the report and the small repro :+1:

Sorry, the details of ppxlib are a bit hazy ATM... :sweat_smile: I suspect this is due to https://github.com/jmid/mutaml/blob/4a3e83feff4e3f7c2e0d9c7fa3caacc4b7c2dcaa/src/ppx/entry.ml#L64

As an experiment could you try changing it to After instead?

I don't know if it's possible to tell dune to instrument the code only after preprocessing ? Otherwise, should the instrumentation tool (mutaml) be careful and not modify code that contains preprocessing annotations ?

Yep, I suspect something like that would be preferable. In the present case we don't want Before - but I don't think we want After either, as that would enable mutations of preprocessor-generated code that a developer is not writing themself... :thinking:

zapashcanon commented 1 year ago

It seems to work with After, thanks !

Indeed, I'm not sure we want to instrument code that has been generated by a preprocessor. Maybe we could just keep Before and ignore code that is annotated ?

epatrizio commented 1 year ago

Same on my small example, it works with After, thanks!