Skip to content

Commit 59b49cd

Browse files
authored
Upgrade to ppxlib 0.36.0 (#1887)
* Upgrade to ppxlib 0.36.0 Signed-off-by: Sora Morimoto <[email protected]> * Add compatibility cases for wrapped `Pexp_function` expressions Signed-off-by: Sora Morimoto <[email protected]> * Fix `Pexp_function` pattern matching for compatibility with older parsetrees Signed-off-by: Sora Morimoto <[email protected]> --------- Signed-off-by: Sora Morimoto <[email protected]>
1 parent d4b1a17 commit 59b49cd

File tree

4 files changed

+199
-56
lines changed

4 files changed

+199
-56
lines changed

dune-project

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
(ocaml-version
4141
(>= 4.0))
4242
(ppxlib
43-
(and
44-
(>= 0.35)
45-
(< 0.36)))
43+
(>= 0.36))
4644
(opam-file-format
4745
(>= 2.1.6))
4846
(ocamlformat

src/ppx_tools/traverse_ast.ml

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class virtual ['res] lift =
231231
self#constr "Ptyp_class" [ "longident_loc", a; "core_type list", b ]
232232
| Ptyp_alias (a, b) ->
233233
let a = self#core_type a in
234-
let b = self#string b in
234+
let b = self#loc self#string b in
235235
self#constr "Ptyp_alias" [ "core_type", a; "label", b ]
236236
| Ptyp_variant (a, b, c) ->
237237
let a = self#list self#row_field a in
@@ -250,6 +250,10 @@ class virtual ['res] lift =
250250
| Ptyp_extension a ->
251251
let a = self#extension a in
252252
self#constr "Ptyp_extension" [ "extension", a ]
253+
| Ptyp_open (a, b) ->
254+
let a = self#longident_loc a in
255+
let b = self#core_type b in
256+
self#constr "Ptyp_open" [ "longident_loc", a; "core_type", b ]
253257

254258
method package_type : package_type -> 'res =
255259
fun (a, b) ->
@@ -429,17 +433,13 @@ class virtual ['res] lift =
429433
self#constr
430434
"Pexp_let"
431435
[ "rec_flag", a; "value_binding list", b; "expression", c ]
432-
| Pexp_function a ->
433-
let a = self#cases a in
434-
self#constr "Pexp_function" [ "cases", a ]
435-
| Pexp_fun (a, b, c, d) ->
436-
let a = self#arg_label a in
437-
let b = self#option self#expression b in
438-
let c = self#pattern c in
439-
let d = self#expression d in
436+
| Pexp_function (a, b, c) ->
437+
let a = self#list self#function_param a in
438+
let b = self#option self#type_constraint b in
439+
let c = self#function_body c in
440440
self#constr
441-
"Pexp_fun"
442-
[ "arg_label", a; "expression option", b; "pattern", c; "expression", d ]
441+
"Pexp_function"
442+
[ "function_param list", a; "type_constraint option", b; "function_body", c ]
443443
| Pexp_apply (a, b) ->
444444
let a = self#expression a in
445445
let b =
@@ -1371,6 +1371,9 @@ class virtual ['res] lift =
13711371
| Pmod_extension a ->
13721372
let a = self#extension a in
13731373
self#constr "Pmod_extension" [ "extension", a ]
1374+
| Pmod_apply_unit a ->
1375+
let a = self#module_expr a in
1376+
self#constr "Pmod_apply_unit" [ "module_expr", a ]
13741377

13751378
method structure : structure -> 'res = self#list self#structure_item
13761379

@@ -1434,17 +1437,19 @@ class virtual ['res] lift =
14341437
self#constr "Pstr_extension" [ "extension", a; "attributes", b ]
14351438

14361439
method value_binding : value_binding -> 'res =
1437-
fun { pvb_pat; pvb_expr; pvb_attributes; pvb_loc } ->
1440+
fun { pvb_pat; pvb_expr; pvb_attributes; pvb_loc; pvb_constraint } ->
14381441
let pvb_pat = self#pattern pvb_pat in
14391442
let pvb_expr = self#expression pvb_expr in
14401443
let pvb_attributes = self#attributes pvb_attributes in
14411444
let pvb_loc = self#location pvb_loc in
1445+
let pvb_constraint = self#option self#value_constraint pvb_constraint in
14421446
self#record
14431447
"value_binding"
14441448
[ "pvb_pat", pvb_pat
14451449
; "pvb_expr", pvb_expr
14461450
; "pvb_attributes", pvb_attributes
14471451
; "pvb_loc", pvb_loc
1452+
; "pvb_constraint", pvb_constraint
14481453
]
14491454

14501455
method module_binding : module_binding -> 'res =
@@ -1506,4 +1511,65 @@ class virtual ['res] lift =
15061511
self#constr "Pdir_bool" [ "bool", a ]
15071512

15081513
method cases : cases -> 'res = self#list self#case
1514+
1515+
method function_param : function_param -> 'res =
1516+
fun { pparam_loc; pparam_desc } ->
1517+
let pparam_loc = self#location pparam_loc in
1518+
let pparam_desc = self#function_param_desc pparam_desc in
1519+
self#record
1520+
"function_param"
1521+
[ "pparam_loc", pparam_loc; "pparam_desc", pparam_desc ]
1522+
1523+
method function_param_desc : function_param_desc -> 'res =
1524+
fun x ->
1525+
match x with
1526+
| Pparam_val (a, b, c) ->
1527+
let a = self#arg_label a in
1528+
let b = self#option self#expression b in
1529+
let c = self#pattern c in
1530+
self#constr
1531+
"Pparam_val"
1532+
[ "arg_label", a; "expression option", b; "pattern", c ]
1533+
| Pparam_newtype a ->
1534+
let a = self#loc self#string a in
1535+
self#constr "Pparam_newtype" [ "string loc", a ]
1536+
1537+
method type_constraint : type_constraint -> 'res =
1538+
fun x ->
1539+
match x with
1540+
| Pconstraint a ->
1541+
let a = self#core_type a in
1542+
self#constr "Pconstraint" [ "core_type", a ]
1543+
| Pcoerce (a, b) ->
1544+
let a = self#option self#core_type a in
1545+
let b = self#core_type b in
1546+
self#constr "Pcoerce" [ "core_type option", a; "core_type", b ]
1547+
1548+
method value_constraint : value_constraint -> 'res =
1549+
fun x ->
1550+
match x with
1551+
| Pvc_constraint { locally_abstract_univars; typ } ->
1552+
let locally_abstract_univars =
1553+
self#list (self#loc self#string) locally_abstract_univars
1554+
in
1555+
let typ = self#core_type typ in
1556+
self#constr
1557+
"Pvc_constraint"
1558+
[ "locally_abstract_univars", locally_abstract_univars; "typ", typ ]
1559+
| Pvc_coercion { ground; coercion } ->
1560+
let ground = self#option self#core_type ground in
1561+
let coercion = self#core_type coercion in
1562+
self#constr "Pvc_coercion" [ "ground", ground; "coercion", coercion ]
1563+
1564+
method function_body : function_body -> 'res =
1565+
fun x ->
1566+
match x with
1567+
| Pfunction_body a ->
1568+
let a = self#expression a in
1569+
self#constr "Pfunction_body" [ "expression", a ]
1570+
| Pfunction_cases (a, b, c) ->
1571+
let a = self#cases a in
1572+
let b = self#location b in
1573+
let c = self#attributes c in
1574+
self#constr "Pfunction_cases" [ "cases", a; "location", b; "attributes", c ]
15091575
end

src/ppx_tools/traverse_ast2.ml

Lines changed: 119 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class virtual ['res] lift2 =
312312
self#constr "Ptyp_class" [ "longident_loc", a; "core_type list", b ]
313313
| Ptyp_alias (a, b), Ptyp_alias (a', b') ->
314314
let a = self#core_type a a' in
315-
let b = self#string b b' in
315+
let b = self#loc self#string b b' in
316316
self#constr "Ptyp_alias" [ "core_type", a; "label", b ]
317317
| Ptyp_variant (a, b, c), Ptyp_variant (a', b', c') ->
318318
let a = self#list self#row_field a a' in
@@ -331,6 +331,10 @@ class virtual ['res] lift2 =
331331
| Ptyp_extension a, Ptyp_extension a' ->
332332
let a = self#extension a a' in
333333
self#constr "Ptyp_extension" [ "extension", a ]
334+
| Ptyp_open (a, b), Ptyp_open (a', b') ->
335+
let a = self#longident_loc a a' in
336+
let b = self#core_type b b' in
337+
self#constr "Ptyp_open" [ "longident_loc", a; "core_type", b ]
334338
| _ -> Error "core_type_desc"
335339

336340
method package_type : package_type -> package_type -> ('res, string) result =
@@ -532,17 +536,13 @@ class virtual ['res] lift2 =
532536
self#constr
533537
"Pexp_let"
534538
[ "rec_flag", a; "value_binding list", b; "expression", c ]
535-
| Pexp_function a, Pexp_function a' ->
536-
let a = self#cases a a' in
537-
self#constr "Pexp_function" [ "cases", a ]
538-
| Pexp_fun (a, b, c, d), Pexp_fun (a', b', c', d') ->
539-
let a = self#arg_label a a' in
540-
let b = self#option self#expression b b' in
541-
let c = self#pattern c c' in
542-
let d = self#expression d d' in
539+
| Pexp_function (a, b, c), Pexp_function (a', b', c') ->
540+
let a = self#list self#function_param a a' in
541+
let b = self#option self#type_constraint b b' in
542+
let c = self#function_body c c' in
543543
self#constr
544-
"Pexp_fun"
545-
[ "arg_label", a; "expression option", b; "pattern", c; "expression", d ]
544+
"Pexp_function"
545+
[ "function_param list", a; "type_constraint option", b; "function_body", c ]
546546
| Pexp_apply (a, b), Pexp_apply (a', b') ->
547547
let a = self#expression a a' in
548548
let b =
@@ -741,37 +741,34 @@ class virtual ['res] lift2 =
741741
self#constr
742742
"Pexp_let"
743743
[ "rec_flag", a; "value_binding list", b; "expression", c ]
744-
(*Caused by: [fun (t39 : t39 Js_of_ocaml.Js.t) -> ...] *)
745-
| ( Pexp_fun (a, b, c, d)
746-
, Pexp_apply ({ pexp_desc = Pexp_fun (a', b', c', d'); _ }, _) ) ->
747-
let a = self#arg_label a a' in
748-
let b = self#option self#expression b b' in
749-
let c = self#pattern c c' in
750-
let d = self#expression d d' in
744+
(*Caused by: [function param -> ...] when wrapped in Pexp_apply *)
745+
| ( Pexp_function ((_ :: _ as a), b, c)
746+
, Pexp_apply ({ pexp_desc = Pexp_function ((_ :: _ as a'), b', c'); _ }, _) ) ->
747+
let a = self#list self#function_param a a' in
748+
let b = self#option self#type_constraint b b' in
749+
let c = self#function_body c c' in
751750
self#constr
752-
"Pexp_fun"
753-
[ "arg_label", a; "expression option", b; "pattern", c; "expression", d ]
754-
(*Caused by: [fun x -> Ppx_deriving_runtime.Format.asprintf "%a" pp x] *)
755-
| ( Pexp_fun (a, b, c, d)
756-
, Pexp_constraint ({ pexp_desc = Pexp_fun (a', b', c', d'); _ }, _) ) ->
757-
let a = self#arg_label a a' in
758-
let b = self#option self#expression b b' in
759-
let c = self#pattern c c' in
760-
let d = self#expression d d' in
751+
"Pexp_function"
752+
[ "function_param list", a; "type_constraint option", b; "function_body", c ]
753+
(*Caused by: [function param -> ...] when wrapped in Pexp_constraint *)
754+
| ( Pexp_function ((_ :: _ as a), b, c)
755+
, Pexp_constraint ({ pexp_desc = Pexp_function ((_ :: _ as a'), b', c'); _ }, _)
756+
) ->
757+
let a = self#list self#function_param a a' in
758+
let b = self#option self#type_constraint b b' in
759+
let c = self#function_body c c' in
761760
self#constr
762-
"Pexp_fun"
763-
[ "arg_label", a; "expression option", b; "pattern", c; "expression", d ]
764-
(* Caused by: {[ fun env -> fun _visitors_this_0 -> fun _visitors_this_1
765-
-> ]} in opams package morbig/src/CST for instance *)
766-
| ( Pexp_fun (a, b, c, d)
767-
, Pexp_poly ({ pexp_desc = Pexp_fun (a', b', c', d'); _ }, _) ) ->
768-
let a = self#arg_label a a' in
769-
let b = self#option self#expression b b' in
770-
let c = self#pattern c c' in
771-
let d = self#expression d d' in
761+
"Pexp_function"
762+
[ "function_param list", a; "type_constraint option", b; "function_body", c ]
763+
(*Caused by: [function param -> ...] when wrapped in Pexp_poly *)
764+
| ( Pexp_function ((_ :: _ as a), b, c)
765+
, Pexp_poly ({ pexp_desc = Pexp_function ((_ :: _ as a'), b', c'); _ }, _) ) ->
766+
let a = self#list self#function_param a a' in
767+
let b = self#option self#type_constraint b b' in
768+
let c = self#function_body c c' in
772769
self#constr
773-
"Pexp_fun"
774-
[ "arg_label", a; "expression option", b; "pattern", c; "expression", d ]
770+
"Pexp_function"
771+
[ "function_param list", a; "type_constraint option", b; "function_body", c ]
775772
(* Caused by this recurent piece of code: {[ ((fun (type res) -> fun
776773
(type t9) -> fun (type t8) -> fun (t9 : t9 Js_of_ocaml.Js.t) -> fun
777774
(t8 : t8) -> fun (_ : t9 -> < set: t8 -> unit ;.. >
@@ -1748,6 +1745,9 @@ class virtual ['res] lift2 =
17481745
| Pmod_extension a, Pmod_extension a' ->
17491746
let a = self#extension a a' in
17501747
self#constr "Pmod_extension" [ "extension", a ]
1748+
| Pmod_apply_unit a, Pmod_apply_unit a' ->
1749+
let a = self#module_expr a a' in
1750+
self#constr "Pmod_apply_unit" [ "module_expr", a ]
17511751
| _ -> Error "module_expr_desc"
17521752

17531753
method structure : structure -> structure -> ('res, string) result =
@@ -1815,22 +1815,27 @@ class virtual ['res] lift2 =
18151815
| _ -> Error "structure_item_desc"
18161816

18171817
method value_binding : value_binding -> value_binding -> ('res, string) result =
1818-
fun { pvb_pat; pvb_expr; pvb_attributes; pvb_loc }
1818+
fun { pvb_pat; pvb_expr; pvb_attributes; pvb_loc; pvb_constraint }
18191819
{ pvb_pat = pvb_pat'
18201820
; pvb_expr = pvb_expr'
18211821
; pvb_attributes = pvb_attributes'
18221822
; pvb_loc = pvb_loc'
1823+
; pvb_constraint = pvb_constraint'
18231824
} ->
18241825
let pvb_pat = self#pattern pvb_pat pvb_pat' in
18251826
let pvb_expr = self#expression pvb_expr pvb_expr' in
18261827
let pvb_attributes = self#attributes pvb_attributes pvb_attributes' in
18271828
let pvb_loc = self#location pvb_loc pvb_loc' in
1829+
let pvb_constraint =
1830+
self#option self#value_constraint pvb_constraint pvb_constraint'
1831+
in
18281832
self#record
18291833
"value_binding"
18301834
[ "pvb_pat", pvb_pat
18311835
; "pvb_expr", pvb_expr
18321836
; "pvb_attributes", pvb_attributes
18331837
; "pvb_loc", pvb_loc
1838+
; "pvb_constraint", pvb_constraint
18341839
]
18351840

18361841
method module_binding : module_binding -> module_binding -> ('res, string) result =
@@ -1904,4 +1909,78 @@ class virtual ['res] lift2 =
19041909
| _ -> Error "directive_argument_desc"
19051910

19061911
method cases : cases -> cases -> ('res, string) result = self#list self#case
1912+
1913+
method function_param : function_param -> function_param -> ('res, string) result =
1914+
fun { pparam_loc; pparam_desc }
1915+
{ pparam_loc = pparam_loc'; pparam_desc = pparam_desc' } ->
1916+
let pparam_loc = self#location pparam_loc pparam_loc' in
1917+
let pparam_desc = self#function_param_desc pparam_desc pparam_desc' in
1918+
self#record
1919+
"function_param"
1920+
[ "pparam_loc", pparam_loc; "pparam_desc", pparam_desc ]
1921+
1922+
method function_param_desc
1923+
: function_param_desc -> function_param_desc -> ('res, string) result =
1924+
fun x x' ->
1925+
match x, x' with
1926+
| Pparam_val (a, b, c), Pparam_val (a', b', c') ->
1927+
let a = self#arg_label a a' in
1928+
let b = self#option self#expression b b' in
1929+
let c = self#pattern c c' in
1930+
self#constr
1931+
"Pparam_val"
1932+
[ "arg_label", a; "expression option", b; "pattern", c ]
1933+
| Pparam_newtype a, Pparam_newtype a' ->
1934+
let a = self#loc self#string a a' in
1935+
self#constr "Pparam_newtype" [ "string loc", a ]
1936+
| _ -> Error "function_param_desc"
1937+
1938+
method type_constraint : type_constraint -> type_constraint -> ('res, string) result =
1939+
fun x x' ->
1940+
match x, x' with
1941+
| Pconstraint a, Pconstraint a' ->
1942+
let a = self#core_type a a' in
1943+
self#constr "Pconstraint" [ "core_type", a ]
1944+
| Pcoerce (a, b), Pcoerce (a', b') ->
1945+
let a = self#option self#core_type a a' in
1946+
let b = self#core_type b b' in
1947+
self#constr "Pcoerce" [ "core_type option", a; "core_type", b ]
1948+
| _ -> Error "type_constraint"
1949+
1950+
method value_constraint
1951+
: value_constraint -> value_constraint -> ('res, string) result =
1952+
fun x x' ->
1953+
match x, x' with
1954+
| ( Pvc_constraint { locally_abstract_univars; typ }
1955+
, Pvc_constraint
1956+
{ locally_abstract_univars = locally_abstract_univars'; typ = typ' } ) ->
1957+
let locally_abstract_univars =
1958+
self#list
1959+
(self#loc self#string)
1960+
locally_abstract_univars
1961+
locally_abstract_univars'
1962+
in
1963+
let typ = self#core_type typ typ' in
1964+
self#constr
1965+
"Pvc_constraint"
1966+
[ "locally_abstract_univars", locally_abstract_univars; "typ", typ ]
1967+
| ( Pvc_coercion { ground; coercion }
1968+
, Pvc_coercion { ground = ground'; coercion = coercion' } ) ->
1969+
let ground = self#option self#core_type ground ground' in
1970+
let coercion = self#core_type coercion coercion' in
1971+
self#constr "Pvc_coercion" [ "ground", ground; "coercion", coercion ]
1972+
| _ -> Error "value_constraint"
1973+
1974+
method function_body : function_body -> function_body -> ('res, string) result =
1975+
fun x x' ->
1976+
match x, x' with
1977+
| Pfunction_body a, Pfunction_body a' ->
1978+
let a = self#expression a a' in
1979+
self#constr "Pfunction_body" [ "expression", a ]
1980+
| Pfunction_cases (a, b, c), Pfunction_cases (a', b', c') ->
1981+
let a = self#cases a a' in
1982+
let b = self#location b b' in
1983+
let c = self#attributes c c' in
1984+
self#constr "Pfunction_cases" [ "cases", a; "location", b; "attributes", c ]
1985+
| _ -> Error "function_body"
19071986
end

vscode-ocaml-platform.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ depends: [
2525
"promise_jsoo" {>= "0.4.3"}
2626
"jsonoo" {>= "0.3"}
2727
"ocaml-version" {>= "4.0"}
28-
"ppxlib" {>= "0.35" & < "0.36"}
28+
"ppxlib" {>= "0.36"}
2929
"opam-file-format" {>= "2.1.6"}
3030
"ocamlformat" {= "0.27.0" & with-dev-setup}
3131
"ocaml-lsp-server" {with-dev-setup}

0 commit comments

Comments
 (0)