Bug in ppx processing: works with -dump-ast but not without it

I’m building js_of_ocaml with Bazel and I’ve found a discrepancy in ppx processing with and without -dump-ast.

Building lib/js_of_ocaml/js_of_ocaml.cmxa succeeds if I pass -dump-ast to the ppx that transforms all of its submodules. This is the default. But for debugging, I can omit that option so that the ppx transform emits text rather than binary files (cli flag --@rules_ocaml//ppx/print=text controls this globally). But when I do this I get the following error:

File "bazel-out/darwin-fastbuild-ST-a36c911cac36/bin/lib/js_of_ocaml/__obazl/Js_of_ocaml__Dom.mli", line 176, characters 31-32:
176 | val eventTarget : < .. >  as 'a#event t -> 'a t[@@ocaml.doc
                                     ^
Error: Syntax error

So the effect of the ppx transform seems to vary depending on whether output is set to binary or text.

I think this is a bug somewhere in the ppx code, rather than the build code, but I don’t know the ppx machinery well enough to debug it, and I’m not sure where I should report it. Advice?

Thanks,

Gregg

This is a bug in the Pprintast pretty-printer which output the parsetree AST in text format, as you can test with

class ['a] c = object end
module type t = sig val x: (< .. > as 'a) #c end

Using -dsource on this output prints

module type t  = sig val x : < .. >  as 'a#c end;

reproducing your syntax error.
You can report the issue directlu on the OCaml bugtracker.

2 Likes