mutaml icon indicating copy to clipboard operation
mutaml copied to clipboard

Instrumentation and preprocessing

Open epatrizio opened this issue 2 years ago • 3 comments

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!

epatrizio avatar Mar 31 '23 11:03 epatrizio

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:

jmid avatar Apr 04 '23 12:04 jmid

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 ?

redianthus avatar Apr 05 '23 13:04 redianthus

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

epatrizio avatar Apr 05 '23 14:04 epatrizio