Ppx derivers vs rewriters, rationale

I have a few T/F questions about ppx derivers vs rewriters.

  1. ppx derive = keep old AST in place, we inject new AST

  2. ppx rewriter = delete old AST, inject new AST

  3. all ppx derivers can be written as ppx rewriters (at the cost of not composing well)

  4. not all ppx rewriters can be written as ppx derivers

so why do we have ppx derivers at all, is the main benefits:

  1. ppx derivers is a compiler enforced contract of “this old AST stays in place”

  2. because old AST remains in place and we only add new things, ppx derive composes well, i.e. [@@deriving ppx1, ppx2, ppx3] – this guarantees, up to naming conflict issues, that ppx1, ppx2, ppx3 will not cause problems for each other

Is the above correct? Is there any other benefit to having this deriver / rewriter split ?


1 Like