Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dune / OMP support #26

Closed
ejgallego opened this issue Sep 4, 2018 · 37 comments
Closed

Dune / OMP support #26

ejgallego opened this issue Sep 4, 2018 · 37 comments

Comments

@ejgallego
Copy link
Collaborator

Dear ppx_import devs, as noted in ocaml/dune#193 (comment) , Dune can support ppx_import style rewriters now.

However, some action would be needed on the ppx_import part. In particular, migrating it to use ocaml-migrate-parsetree, and maybe, even porting the build system to Dune (which IMVHO seems like a good idea).

Do you think any of these goals are desirable? Would you welcome a patch?

@whitequark
Copy link
Contributor

Yes and yes.

@ejgallego
Copy link
Collaborator Author

Great, thanks @whitequark ; IIUC, using OMP requires to choose a version to start with, I understand that Ast_407 is the preferred choice?

@whitequark
Copy link
Contributor

Sure.

@ejgallego
Copy link
Collaborator Author

ejgallego commented Sep 4, 2018

I opted to use Ast_406 as the versioned ppx_tools.metaquot does not yet support 4.07.

The main roadblock I'm facing for now is the lack of Types support in OMP. Example:

  | Tarrow (label, lhs, rhs, _) ->
    Typ.arrow label (core_type_of_type_expr ~subst lhs)
                    (core_type_of_type_expr ~subst rhs)

Here, label comes from the current OCaml compiler, however Typ.arrow is in OMP so types do not match.

What strategy would you recommend folks ? Thanks!

p.s: The tree I'm working on is at https://github.com/ejgallego/ppx_import/tree/dune%2Bomp compilation with dune works up to the point of seeing the above error.

@whitequark
Copy link
Contributor

Right. I'm not actually sure this is easily solvable.

@ejgallego
Copy link
Collaborator Author

There's not a lot of stuff to "migrate"; I could file a request to OMP so they support Types, or build a compat module in ppx_import itself.

However I have 0 experience with ppx so I'd appreciate guidance from the far more experienced people around.

@whitequark
Copy link
Contributor

The problem is that ppx_import depends on Untypeast...

@ejgallego
Copy link
Collaborator Author

Untypeast

Sorry if my questions are naïve @whitequark , where is this dependency inserted? I can't seem to locate it.

@ejgallego
Copy link
Collaborator Author

Another naïve question I have is whether we should target ppxlib or ppx_tools_versioned.

@whitequark
Copy link
Contributor

Hm, maybe not anymore. Really, I haven't worked with any of this in ages, @gasche would probably be in a much better position to answer.

@gasche
Copy link
Contributor

gasche commented Sep 4, 2018

I think it should be possible to separate (conceptually) the aspects of ppx_import that rely on the parsetree, and those that rely on the typedtree. Then the parsetree stuff would be versioned, and the typedtree stuff I guess would remain version-pinned (or you motivate people to implement ocaml-migrate-typedtree indeed).

The case you highlight is special in that a typedtree-world value, label, is sent to the parsetree-world. This doesn't happen very often. In the non-versioned master it works because they share the same Asttypes definition, but in the versioned work the asttypes definitions are distinct.

I would just consider that there are two Asttypes modules, and write conversion functions from one to the other. So write identity-looking functions from "the typedtree Asttypes" to "the parsetree Astty[pes". It's not a very big module, so it wouldn't be a lot of work.

@ejgallego
Copy link
Collaborator Author

Well, the only place I can see is Ast_mapper.register, in fact, I am not sure how this should be replaced in the new code.

If we forget about the typedtree migration [which can be achieved by compiling the plugin in 4.06.1], the only bits to replace in order to get the rewrite to compiler are:

  • Ast_mapper.tool_name: I'm unsure what's the equivalence now.
  • Ast_mapper.register: ditto.

@ejgallego
Copy link
Collaborator Author

ejgallego commented Sep 4, 2018

I would just consider that there are two Asttypes module, and write conversion functions from one to the other. So write identity-looking functions from "the typedtree Asttypes" to "the parsetree Astty[pes". It's not a very big module, so it wouldn't be a lot of work.

Yup, that looks like a good plan. However before we do this I'd like to get the rewriter working with 4.06.1 + Ast_406 [which seems to work]. Then we can go back and support a few compilers more with a mini-migrate typedtree.

@ghost
Copy link

ghost commented Sep 4, 2018

@ejgallego Ast_mapper.register should be replaced by Migrate_parsetree.Driver.register. The callback gets a config record containing a tool_name field.

@ejgallego
Copy link
Collaborator Author

@ejgallego Ast_mapper.register should be replaced by Migrate_parsetree.Driver.register. The callback gets a config record containing a tool_name field.

Thanks @diml !

@gasche
Copy link
Contributor

gasche commented Sep 4, 2018

@diml while you are here (thanks!), how do Ppxlib.Deriving plugins deal with the typedtree versioning issue? Do they never observe typed declarations or use Env?

@ghost
Copy link

ghost commented Sep 4, 2018

They don't... In general, it's not clear how two ppx rewriters using the typer can be used together, so ppxlib doesn't try to support these. ppx_import is a particular case as it doesn't need to type the input. However, if you consider ppx rewriters such as ppx_show, it is not possible to use two of these on the same file.

It seems to me that the current ppx model is not very friendly to rewriters using the typer. I thought about how it could be changed to make it easier to write ppx rewriters using the typer and especially compose them. It seems to me that given that most ppx rewriters only generate code locally, we could simply do the expansion in the typer: i.e. whenever the typer encounters a foreign syntax, such as an extension point or a type declaration with a [@@deriving] attribute, then it would call a callback that would expand it and recurse on the result. The typer could pass typing informations to the callback. I believe that this would be a better model, although it's a non trivial amount of work.

Regarding the data types themselves and compatibility with multiple compiler versions, it seems to me that the most straightforward solution is to provide construction functions + view patterns. These can be versioned independently of the underlying data types.

@ejgallego
Copy link
Collaborator Author

Ok, I got the rewriter compiling now, however tests fail with:

$ dune build
    ocamldep src_test/.test_ppx_import.eobjs/test_ppx_import.ml.d (exit 2)
(cd _build/default && /home/egallego/.opam/4.06.1/bin/ocamldep.opt -modules -ppx .ppx/ppx_import/ppx.exe -impl src_test/test_ppx_import.ml) > _build/default/src_test/.test_ppx_import.eobjs/test_ppx_import.ml.d
File "/tmp/camlppx7c32d4", line 1:
Error: I can't decide whether /tmp/camlppx7c32d4 is an implementation or interface file
File "src_test/test_ppx_import.ml", line 1:
Error: Error while running external preprocessor
Command line: .ppx/ppx_import/ppx.exe '/tmp/camlppx7c32d4' '/tmp/camlppx7b156a'

will investigate more later.

@ghost
Copy link

ghost commented Sep 4, 2018

Oops, that's a bug in dune. This PR should fix the issue: ocaml/dune#1218

@ejgallego
Copy link
Collaborator Author

Thanks again @diml !

@ejgallego
Copy link
Collaborator Author

Ok, so with the dune fix things seem to be working now with ppx_import in isolation :)

However, combining with ppx_deriving.show seems to be a problem:

dune build
    ocamldep src_test/.test_ppx_import.eobjs/test_ppx_import.ml.d (exit 2)
(cd _build/default && /home/egallego/.opam/4.06.1/bin/ocamldep.opt -modules -ppx '.ppx/ppx_deriving.show+ppx_import/ppx.exe --as-ppx' -impl src_test/test_ppx_import.ml) > _build/default/src_test/.test_ppx_import.eobjs/test_ppx_import.ml.d
File "src_test/test_ppx_import.ml", line 26, characters 10-28:
Error: show cannot be derived for [%import :Stuff.a]
Makefile:2: recipe for target 'build' failed
make: *** [build] Error 1

I do understand that this will be trickier to solve, right?

@ghost
Copy link

ghost commented Sep 4, 2018

Yh, it's an ordering problem: ppx_import is not applied soon enough. I'm preparing a patch for omp to allow specifying that a rewriter must be applied before other ones.

@ghost
Copy link

ghost commented Sep 4, 2018

I made the PR: ocaml-ppx/ocaml-migrate-parsetree#51

@ejgallego
Copy link
Collaborator Author

Thanks @diml . Another weird problem I'm hitting is that (libraries ...) don't seem to be properly set when calling ocamlfind. For example, I have:

(library
 (public_name coq-serapi.serlib)
 (name serlib)
 (synopsis "Serialization Library for Coq")
 (preprocess (staged_pps ppx_import ppx_sexp_conv))
 (libraries coq.stm sexplib))

But I do get:

ocamldep serlib/.serlib.objs/ser_equality.ml.d (exit 2)
(cd _build/default && /home/egallego/.opam/4.06.1/bin/ocamldep.opt -modules -ppx '.ppx/ppx_import+ppx_sexp_conv/ppx.exe --as-ppx --cookie '\''library-name="serlib"'\''' -impl serlib/ser_equality.ml) > _build/default/serlib/.serlib.objs/ser_equality.ml.d
File "serlib/ser_equality.ml", line 4, characters 12-26:
Error: [%import]: cannot locate module Equality

@ejgallego
Copy link
Collaborator Author

Does that mean that coq.stm should become a runtime dependency of the ppx?

@ghost
Copy link

ghost commented Sep 4, 2018

Hmm, normally when tool_name = "ocamldep" ppx_import shouldn't lookup modules in the environment. Could you try printing tool_name?

@ejgallego
Copy link
Collaborator Author

File "serlib/ser_vernacexpr.ml", line 46, characters 31-55:
Error: [%import]: cannot locate module Vernacexpr
    ocamldep serlib/.serlib.objs/ser_xml_datatype.ml.d (exit 2)
(cd _build/default && /home/egallego/.opam/4.06.1/bin/ocamldep.opt -modules -ppx '.ppx/ppx_import+ppx_sexp_conv/ppx.exe --as-ppx --cookie '\''library-name="serlib"'\''' -impl serlib/ser_xml_datatype.ml) > _build/default/serlib/.serlib.objs/ser_xml_datatype.ml.d
tool_name: ppxlib_driver

@ghost
Copy link

ghost commented Sep 4, 2018

Ah, I see the issue. We need a patch in ppxlib as well to not override the tool name. I'm looking at this.

@ghost
Copy link

ghost commented Sep 4, 2018

This PR for ppxlib should fix the issue: ocaml-ppx/ppxlib#41

@ejgallego
Copy link
Collaborator Author

ejgallego commented Sep 4, 2018

I confirm that with the above PR ppx_import + ppx_sexp_conv do work ! 🎉 🎉 🎉

The problem with ppx_deriving.std persists tho, strange as I'm using [@@deriving sexp] without trouble in the other repo.

ejgallego added a commit to ejgallego/ppx_import that referenced this issue Sep 4, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`

This is still work in progress, in particular, it only works with
OCaml 4.06 due to the need to have `typedtree` versioning. This will
need to be resolved before this PR can be merged.

Another question is whether we should use `ppx_tools_versioned` or
`ppxlib` directly.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Sep 4, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`

This is still work in progress, in particular, it only works with
OCaml 4.06 due to the need to have `typedtree` versioning. This will
need to be resolved before this PR can be merged.

Another question is whether we should use `ppx_tools_versioned` or
`ppxlib` directly.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Sep 4, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`

This is still work in progress, in particular, it only works with
OCaml 4.06 due to the need to have `typedtree` versioning. This will
need to be resolved before this PR can be merged.

Another question is whether we should use `ppx_tools_versioned` or
`ppxlib` directly.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Sep 4, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`

This is still work in progress, in particular, it only works with
OCaml 4.06 due to the need to have `typedtree` versioning. This will
need to be resolved before this PR can be merged.

Another question is whether we should use `ppx_tools_versioned` or
`ppxlib` directly.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Sep 4, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`

This is still work in progress, in particular, it only works with
OCaml 4.06 due to the need to have `typedtree` versioning. This will
need to be resolved before this PR can be merged.

Another question is whether we should use `ppx_tools_versioned` or
`ppxlib` directly.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Sep 4, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`

This is still work in progress, in particular, it only works with
OCaml 4.06 due to the need to have `typedtree` versioning. This will
need to be resolved before this PR can be merged.

Another question is whether we should use `ppx_tools_versioned` or
`ppxlib` directly.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Sep 4, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`

This is still work in progress, in particular, it only works with
OCaml 4.06 due to the need to have `typedtree` versioning. This will
need to be resolved before this PR can be merged.

Another question is whether we should use `ppx_tools_versioned` or
`ppxlib` directly.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Sep 4, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`

This is still work in progress, in particular, it only works with
OCaml 4.06 due to the need to have `typedtree` versioning. This will
need to be resolved before this PR can be merged.

Another question is whether we should use `ppx_tools_versioned` or
`ppxlib` directly.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Sep 4, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`

This is still work in progress, in particular, it only works with
OCaml 4.06 due to the need to have `typedtree` versioning. This will
need to be resolved before this PR can be merged.

Another question is whether we should use `ppx_tools_versioned` or
`ppxlib` directly.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Sep 4, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`

This is still work in progress, in particular, it only works with
OCaml 4.06 due to the need to have `typedtree` versioning. This will
need to be resolved before this PR can be merged.

Another question is whether we should use `ppx_tools_versioned` or
`ppxlib` directly.
@ejgallego
Copy link
Collaborator Author

@gasche a small note, I think that ppx_import doesn't rely on typedtree per-se, but in typed.

ejgallego added a commit to ejgallego/ppx_import that referenced this issue Sep 10, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`

This is still work in progress, in particular, it only works with
OCaml 4.06 due to the need to have `typedtree` versioning. This will
need to be resolved before this PR can be merged.

Another question is whether we should use `ppx_tools_versioned` or
`ppxlib` directly.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Sep 21, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Introduce migration functions for elements of `Asttypes`
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`

We had to raise dependencies on quite a few packages, thus ppx_import
only works now with OCaml >= 4.04.2.

A couple of questions remain:
- What to do with `Outcometree` [c.f: "Primitive.print p oval"]
- Should we use ppx_tools_versioned or ppxlib directly?
@ejgallego
Copy link
Collaborator Author

Note that #27 , fixing this issue is basically ready for review, and maybe merge.

ejgallego added a commit to ejgallego/ppx_import that referenced this issue Nov 9, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Introduce migration functions for elements of `Asttypes`
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`
- Upgrade to OPAM 2.0
- Update Travis CI.

We had to raise dependencies on quite a few packages, thus ppx_import
now requires OCaml >= 4.04.2.

The question of whether we should use `ppx_tools_versioned` or
`ppxlib` does remain, but it can be addressed at a later point.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Nov 9, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Introduce migration functions for elements of `Asttypes`
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`
- Upgrade to OPAM 2.0
- Update Travis CI.

We had to raise dependencies on quite a few packages, thus ppx_import
now requires OCaml >= 4.04.2.

The question of whether we should use `ppx_tools_versioned` or
`ppxlib` does remain, but it can be addressed at a later point.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Nov 9, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Introduce migration functions for elements of `Asttypes`
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`
- Upgrade to OPAM 2.0
- Update Travis CI.

We had to raise dependencies on quite a few packages, thus ppx_import
now requires OCaml >= 4.04.2.

The question of whether we should use `ppx_tools_versioned` or
`ppxlib` does remain, but it can be addressed at a later point.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Nov 9, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Introduce migration functions for elements of `Asttypes`
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`
- Upgrade to OPAM 2.0
- Update Travis CI.

We had to raise dependencies on quite a few packages, thus ppx_import
now requires OCaml >= 4.04.2.

The question of whether we should use `ppx_tools_versioned` or
`ppxlib` does remain, but it can be addressed at a later point.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Nov 9, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Introduce migration functions for elements of `Asttypes`
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`
- Upgrade to OPAM 2.0
- Update Travis CI.

We had to raise dependencies on quite a few packages, thus ppx_import
now requires OCaml >= 4.04.2.

The question of whether we should use `ppx_tools_versioned` or
`ppxlib` does remain, but it can be addressed at a later point.
ejgallego added a commit to ejgallego/ppx_import that referenced this issue Nov 9, 2018
Fixes ocaml-ppx#26. Changes:

- Build system migrated to Dune.
- Remove use of `cppo` in favor of ocaml-migrate-parsetree
- Introduce migration functions for elements of `Asttypes`
- Remove use of `topkg` in favor of `dune-release`
- Updated `.gitignore`
- Upgrade to OPAM 2.0
- Update Travis CI.

We had to raise dependencies on quite a few packages, thus ppx_import
now requires OCaml >= 4.04.2.

The question of whether we should use `ppx_tools_versioned` or
`ppxlib` does remain, but it can be addressed at a later point.
ejgallego added a commit to ejgallego/opam-repository that referenced this issue Nov 10, 2018
CHANGES:

1.6
---

  * ocaml-migrate-parsetree + dune support ocaml-ppx/ppx_import#26
    (Jérémie Dimino & Emilio Jesús Gallego Arias)

  * Move to OPAM 2.0, adapt Travis CI.
    (Emilio Jesús Gallego Arias)

1.5
---

  * OCaml 4.07 support
    ocaml-ppx/ppx_import#24
    (Damien Doligez)

  * Call the type-checker (through compiler-libs) instead of reading
    `.cmi` files directly, to correctly resolve module aliases.
    ocaml-ppx/ppx_import#25
    (Gabriel Scherer)

1.4
---

  * OCaml 4.06 support
    ocaml-ppx/ppx_import#19
    (Gabriel Scherer)

1.3
---

  * Also allow extraction of module types from the current module's interface file.
    ocaml-ppx/ppx_import#12
    (Xavier Guérin)

1.2
---

  * Allow extracting types from the current module's interface file.
    (Xavier Guérin)

1.1
---

  * OCaml 4.03 support.
    (whitequark)

1.0
---

  * Allow extracting types from module types.
    (whitequark)

0.1
---

  * Initial release.
    (whitequark)
ejgallego added a commit to ejgallego/opam-repository that referenced this issue Nov 10, 2018
CHANGES:

  * ocaml-migrate-parsetree + dune support ocaml-ppx/ppx_import#26
    (Jérémie Dimino & Emilio Jesús Gallego Arias)

  * Move to OPAM 2.0, adapt Travis CI.
    (Emilio Jesús Gallego Arias)
ejgallego added a commit to ejgallego/opam-repository that referenced this issue Nov 10, 2018
CHANGES:

  * ocaml-migrate-parsetree + dune support ocaml-ppx/ppx_import#26
    (Jérémie Dimino & Emilio Jesús Gallego Arias)

  * Move to OPAM 2.0, adapt Travis CI.
    (Emilio Jesús Gallego Arias)
ejgallego added a commit to ejgallego/opam-repository that referenced this issue Jan 30, 2019
CHANGES:

* ocaml-migrate-parsetree + dune support ocaml-ppx/ppx_import#26
    (Jérémie Dimino & Emilio Jesús Gallego Arias)

  * Move to OPAM 2.0, adapt Travis CI.
    (Emilio Jesús Gallego Arias)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants