This is actually a great tip. Thanks @mseri. I tried this out and it definitely works.
Here is an example to make this concrete for people who want more information about -dsource
.
Lets say I’m compiling the dream framework.
$ git clone https://github.com/aantron/dream.git
$ cd dream
$ opam install . --deps-only -with-test
$ dune build -p dream
# Lets see the transformation of the src/http/http.ml file
$ cd _build/default/src/http
# ocamlc dumps transformed source on stderr
$ ocamlc -dsource http.pp.ml 2>http.pp.out.ml
# meld is a great difftool. There are many others
$ meld http.ml http.pp.out.ml
A lot of de-sugaring has happened by the time you see http.pp.out.ml
e.g. fun ~a ~b ~c ->...
becomes fun ~a -> (fun ~b -> (fun ~c -> ...)))
, comments are stripped out etc. So it does become a bit difficult to compare the original with the transformed source.
However the good news is that ppx-es are indeed expanded as advertised.
Something like
let%lwt response = user's_dream_handler request in ...
Now becomes:
let __ppx_lwt_0 = user's_dream_handler request in
let module Reraise =
struct external reraise : exn -> 'a = "%reraise" end in
Lwt.backtrace_bind
(fun exn -> try Reraise.reraise exn with | exn -> exn)
__ppx_lwt_0
(fun response -> ...