PPX name conflict, what to do with dependencies

I’m trying to port my work project to the OCaml 5. I found that Core library now depends from ppx_log (through ppx_jane), and in ppx_log are defined logging macros just like we already use in our own proprietary framework.

Is it possible to install and use Core without installing ppx_log? Or maybe install ppx_log, but rename somehow the logging macros? Renaming our macros is for obvious reason much less comfortable for our team.

I haven’t used ppx_log. But I’ve written many ppx rewriters, and there’s a standard pattern of splittig their code into the rewriter per se and a “runtime” findlib module. Then a package that uses the rewriter will specify a dependency on the runtime module in it’s META file. Maybe Core didn’t do this? It should be easy to fix

1 Like

ppx_jane is a (meta package) with a collection of rewriters. You could try to cherry pick only rewriters suitable for you. For enlightenment, you could try to study the output of opam show ppx_jane

1 Like

ppx_jane is a (meta package) with a collection of rewriters. You could try to cherry pick only rewriters suitable for you.

Yes, I know. But the problem is we use Core library, and Core depends from ppx_jane.

Then a package that uses the rewriter will specify a dependency on the runtime module in it’s META file. Maybe Core didn’t do this? It should be easy to fix

Could you please clarify, how can I fix this (without forking and rebuilding Core)?

There are two sets of dependencies:

  1. the dependencies in the opam file, which specify what packages (and what versions) must be installed, before installing this package

  2. the dependencies in the META file, which specify for each findlib module, what findlib modules need to be linked or visible prior to this module being linked/visible.

#1 is where the PPX rewriter ppx_log (or _jane, whatever) must be listed. #2 … well, you need to investigate whether the META file for Core (or any modules it depends upon in its META file, and transitively so) depends on ppx_log/_jane.

I don’t use any of that Jane Street infra, so I don’t actually know. But I do know that this is how it works, b/c I’ve had to arrange things that way for Camlp5’s PPX rewriters and runtime libraries.

IF you found that ppx_log was somehow pulled-in by the findlib module “core” (or whatever it’s called), I suspect it would be easy to remove that dependency. If you feel uncomfortable with digging into this, you might want to contact the Jane Street folks (e.g., open an issue on the github repo for “core”) and see if they can help you resolve this problem.

you need to investigate whether the META file for Core (or any modules it depends upon in its META file, and transitively so) depends on ppx_log/_jane

I see no META file in Core source code. Does it mean I should try to modify dune file for Core and rebuild it without ppx_jane and ppx_log dependencies?

How does the problem look like in practice? Core depending on ppx_log does not mean that your code has to be preprocessed by ppx_log.

How does the problem look like in practice?

# [...]
# Called from Ppxlib__Extension.V3.declare in file "src/extension.ml", line 451, characters 6-95
# Called from Ppx_log_kernel in file "kernel/ppx_log_kernel.ml", line 78, characters 8-51
# File "lib-core/kernel/future/dune", line 8, characters 2-62:
# 8 |   (pps ppx_jane lwt_ppx bisect_ppx --conditional our-core.ppx)))
#       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# (cd _build/default && .ppx/37a40f2b6350429b8ea1d642bf52f962/ppx.exe --conditional --cookie 'library-name="our_core_kernel_future"' -o lib-core/kernel/future/Notification.pp.ml --impl lib-core/kernel/future/Notification.ml -corrected-suffix .ppx-corrected -diff-cmd - -dump-ast)
# Fatal error: exception Failure("Some ppx-es tried to register conflicting transformations: Extension 'log.error' on expressions declared at kernel/ppx_log_kernel.ml:78 matches extension 'log.error' declared at ppx/src/Logging_ppx.re:326")
# Raised at Stdlib.failwith in file "stdlib.ml", line 29, characters 17-33
# Called from Ppxlib__Name.Registrar.register in file "src/name.ml", line 245, characters 4-70
# Called from Ppxlib__Extension.Make.declare in file "src/extension.ml", line 172, characters 4-79
# Called from Ppxlib__Extension.V3.declare in file "src/extension.ml", line 451, characters 6-95
# Called from Ppx_log_kernel in file "kernel/ppx_log_kernel.ml", line 78, characters 8-51

Core depending on ppx_log does not mean that your code has to be preprocessed by ppx_log.

I hope so; but how can I prevent preprocessing of my code by ppx_log?

This is a useful error message which makes it immensely easier to help you.

What happens is that 2 rewriters (ppx_log and the one defined at ppx/src/Logging_ppx.re) specify how [%log.error ...] should be rewritten. This happens because they are registered in a same driver, because in lib-core/kernel/future/dune you’re asking for both of these rewriters.
2 solutions:

  • you use a different extension name, so that the rewriters can be registered into a single driver
  • you change the (preprocessing) part so that it contains only the bits you use: ppx_jane is a collection of ppx rewriters that includes ppx_expect, ppx_sexp_conv, and ppx_log, but if you don’t use all of that, you can only specify the bits you use. for example, (pps ppx_expect lwt_ppx bisect_ppx --conditional our-core.ppx).
1 Like

you use a different extension name, so that the rewriters can be registered into a single driver

Thank you! Just now I’m trying this approach.

The second is, of course, much better; I’ll try it a bit later.

Thank you again.

You were right: using subpackages of ppx_jane instead of ppx_jane itself is the solution.