This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
36
unikernel/duniverse/ppxlib/test/migrations/driver.ml
Normal file
36
unikernel/duniverse/ppxlib/test/migrations/driver.ml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
open Ppxlib
|
||||
|
||||
module B = Ast_builder.Make (struct
|
||||
let loc = Location.none
|
||||
end)
|
||||
|
||||
let add_function =
|
||||
let param v = B.pparam_val Nolabel None (B.ppat_var (B.Located.mk v)) in
|
||||
let body =
|
||||
B.pexp_function
|
||||
[ param "b" ]
|
||||
None
|
||||
(Pfunction_body
|
||||
(B.pexp_apply
|
||||
(B.pexp_ident (B.Located.mk (Lident "+")))
|
||||
[
|
||||
(Nolabel, B.pexp_ident (B.Located.lident "a"));
|
||||
(Nolabel, B.pexp_ident (B.Located.lident "b"));
|
||||
]))
|
||||
in
|
||||
let func = B.pexp_function [ param "a" ] None (Pfunction_body body) in
|
||||
B.pstr_value Nonrecursive
|
||||
[ B.value_binding ~pat:(B.ppat_var (B.Located.mk "f")) ~expr:func ]
|
||||
|
||||
let generative_functor =
|
||||
let empty_struct = B.pmod_structure [] in
|
||||
B.pstr_module
|
||||
(B.module_binding ~name:(B.Located.mk (Some "F"))
|
||||
~expr:(B.pmod_apply (B.pmod_ident (B.Located.lident "F")) empty_struct))
|
||||
|
||||
let () =
|
||||
Driver.register_transformation
|
||||
~impl:(fun impl -> add_function :: generative_functor :: impl)
|
||||
"migrators"
|
||||
|
||||
let () = Driver.standalone ()
|
||||
9
unikernel/duniverse/ppxlib/test/migrations/dune
Normal file
9
unikernel/duniverse/ppxlib/test/migrations/dune
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(executable
|
||||
(name driver)
|
||||
(modules driver)
|
||||
(libraries ppxlib))
|
||||
|
||||
(cram
|
||||
(enabled_if
|
||||
(< %{ocaml_version} "5.2.0"))
|
||||
(deps driver.exe))
|
||||
22
unikernel/duniverse/ppxlib/test/migrations/run.t
Normal file
22
unikernel/duniverse/ppxlib/test/migrations/run.t
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
Ppxlib applies migrations to the AST. In some cases, especially when applying
|
||||
downward migrations, extra information must be encoded in the AST in order to
|
||||
be able to properly re-encode the AST when migrating back up.
|
||||
|
||||
This means that sometimes the extra information is left in the AST especially
|
||||
when printing the code as source of the current compiler (where the current
|
||||
compiler is less than the internal AST version).
|
||||
|
||||
Therefore we must clean the produced AST to remove ppxlib.migration attributes.
|
||||
|
||||
$ touch file.ml
|
||||
$ ./driver.exe file.ml
|
||||
let f a = fun b -> a + b
|
||||
module F = (F)(struct end)
|
||||
|
||||
Now we ensure no attributes are left in the AST after we force a downard
|
||||
migration using the --use-compiler-pp flag.
|
||||
|
||||
$ ./driver.exe --use-compiler-pp file.ml
|
||||
let f a b = a + b
|
||||
module F = (F)(struct end)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue