OCaml 4.04 and ppx-jane in v0.9

44 views
Skip to first unread message

usch...@googlemail.com

unread,
May 27, 2017, 11:19:11 AM5/27/17
to ocaml-core
Hello,

I'm trying to update some code that uses OCaml 4.04 features to core v0.9. But the rewriting of ppx-annotations with ppx-jane fails for files that use 4.04 syntax. A small example where the error occurs is appended below. 

It seems that ppx-jane tries to migrate the code to 4.03!?! Does it need to be told which version to use or am I using it wrong?

Best,
Ulrich


$ ocamlc -version
4.04.1

$ cat t.ml 
module M = struct
  type t = A of int
  [@@deriving sexp]
end

let f x = match x with
  | M.(A(_)) -> 3


$ ocamlc t.ml

$ cat jbuild 
(jbuild_version 1)

(executables
 ((names (t))
  (preprocess (pps (ppx_jane)))
 )
)

$ jbuilder build t.exe
    ocamlopt .ppx/ppx_jane/ppx.exe
         ppx t.pp.ml (exit 2)
(cd _build/default && ./.ppx/ppx_jane/ppx.exe --dump-ast -o t.pp.ml --impl t.ml)
Fatal error: exception File "t.ml", line 7, characters 4-12: module open in patterns are not supported before OCaml 4.04
Raised at file "src/migrate_parsetree_404_403_migrate.ml", line 24, characters 2-49
Called from file "src/migrate_parsetree_404_403_migrate.ml", line 260, characters 8-46
Called from file "src/migrate_parsetree_404_403_migrate.ml", line 223, characters 8-29
Called from file "list.ml", line 59, characters 20-23
Called from file "src/migrate_parsetree_404_403_migrate.ml", line 81, characters 10-33
Called from file "src/migrate_parsetree_404_403_migrate.ml", line 37, characters 8-49
Called from file "src/migrate_parsetree_404_403_migrate.ml", line 69, characters 10-30
Called from file "src/migrate_parsetree_404_403_migrate.ml", line 37, characters 8-49
Called from file "src/migrate_parsetree_404_403_migrate.ml", line 244, characters 8-34
Called from file "list.ml", line 59, characters 20-23
Called from file "src/migrate_parsetree_404_403_migrate.ml", line 502, characters 10-42
Called from file "src/migrate_parsetree_404_403_migrate.ml", line 485, characters 8-44
Called from file "list.ml", line 59, characters 20-23
Called from file "list.ml", line 59, characters 32-39
Called from file "src/migrate_parsetree_driver.ml", line 191, characters 21-67
Called from file "src/migrate_parsetree_driver.ml", line 197, characters 11-86
Called from file "src/migrate_parsetree_driver.ml", line 345, characters 10-60
Called from file "list.ml", line 77, characters 12-15
Called from file "src/migrate_parsetree_driver.ml", line 442, characters 4-86
Re-raised at file "parsing/location.ml", line 450, characters 12-23
Re-raised at file "parsing/location.ml", line 450, characters 12-23
Re-raised at file "parsing/location.ml", line 450, characters 12-23
Re-raised at file "parsing/location.ml", line 450, characters 12-23
Re-raised at file "parsing/location.ml", line 450, characters 12-23
Re-raised at file "parsing/location.ml", line 450, characters 12-23
Called from file "parsing/location.ml" (inlined), line 454, characters 31-61
Called from file "src/migrate_parsetree_driver.ml", line 444, characters 4-54
Called from file "src/migrate_parsetree_driver.ml", line 472, characters 4-31
Called from file "src/migrate_parsetree_driver_main.ml", line 1, characters 9-45



Yaron Minsky

unread,
May 27, 2017, 11:25:03 AM5/27/17
to ocaml...@googlegroups.com
I'm not sure exactly what's going on here, but the idea of the PPX
downgrading to 4.03 AST is reasonable. This is how we can upgrade to a
new version of the compiler without having to upgrade all of our PPXs
in one fell swoop --- you can have the older version of the PPX, and
then translate back and forth through the AST.

That said, I'm surprised that this affects code that doesn't have a
[@@deriving] annotation attached to it. Maybe Jeremie or Thomas can
answer this more effectively.

As a side note, I wonder if such questions would be better answered on
discuss.ocaml.org, under the Core/Async category:
https://discuss.ocaml.org/c/core

y
> --
> You received this message because you are subscribed to the Google Groups
> "ocaml-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ocaml-core+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Jeremie Dimino

unread,
May 29, 2017, 6:07:15 AM5/29/17
to ocaml...@googlegroups.com
Yes, downgrading to the 4.03 AST is the issue.

On Sat, May 27, 2017 at 4:24 PM, Yaron Minsky <ymi...@janestreet.com> wrote:
> That said, I'm surprised that this affects code that doesn't have a
> [@@deriving] annotation attached to it. Maybe Jeremie or Thomas can
> answer this more effectively.

The whole AST is translated, not just the matching parts. It's too
keep things simple and maintainable.

What we need to do is upgrade the version of the AST used by our ppx.
For the 4.04 AST this is fine as the changes are backward compatible,
so we should probably just do it. Moving forward this will be more
painful. There are more changes in 4.05 or 4.06 and we'll end up
having to change many of our ppx rewriters.

This is the main problem with this design. There have been some ideas
of encoding new features in attributes as a workaround. Moving
forward, I think the long term solution will be this:
https://github.com/diml/ppx_view_pattern
Reply all
Reply to author
Forward
0 new messages