Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
landmarks library.")
(depends
(ocaml (>= 4.08))
(ppxlib (>= 0.22))
(ppxlib (>= 0.36))
(landmarks (= 1.5))
)
)
2 changes: 1 addition & 1 deletion landmarks-ppx.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bug-reports: "https://github.com/LexiFi/landmarks/issues"
depends: [
"dune" {>= "3.16"}
"ocaml" {>= "4.08"}
"ppxlib" {>= "0.22"}
"ppxlib" {>= "0.36"}
"landmarks" {= "1.5"}
"odoc" {with-doc}
]
Expand Down
40 changes: 25 additions & 15 deletions ppx/mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,36 @@ let wrap_landmark ctx landmark loc expr =

let rec arity {pexp_desc; _} =
match pexp_desc with
| Pexp_fun (a, _, _, e) -> a :: arity e
| Pexp_function cases ->
let max_list l1 l2 =
if List.length l1 < List.length l2 then
l1
else
l2
in
Nolabel :: (List.fold_left
(fun acc {pc_rhs; _} -> max_list (arity pc_rhs) acc)
[] cases)
| Pexp_function (param_list, _, body) ->
let body_arity =
match body with
| Pfunction_body e -> arity e
| Pfunction_cases (cases, _, _) ->
let max_list l1 l2 =
if List.length l1 < List.length l2 then
l1
else
l2
in
Nolabel :: (List.fold_left
(fun acc {pc_rhs; _} -> max_list (arity pc_rhs) acc)
[] cases)
in
List.fold_right (fun param acc ->
match param.pparam_desc with
| Pparam_val (arg_label, _, _) -> arg_label :: acc
| Pparam_newtype _ -> acc
) param_list body_arity
| Pexp_newtype (_, e) -> arity e
| Pexp_constraint (e, _) -> arity e
| Pexp_poly (e, _) -> arity e
| _ -> []

let rec wrap_landmark_method ctx landmark loc ({pexp_desc; _} as expr) =
match pexp_desc with
| Pexp_fun (label, def, pat, e) ->
{ expr with pexp_desc = Pexp_fun (label, def, pat, wrap_landmark_method ctx landmark loc e)}
| Pexp_function (param_list, tc_opt, Pfunction_body e) ->
{ expr with pexp_desc = Pexp_function (param_list, tc_opt,
Pfunction_body (wrap_landmark_method ctx landmark loc e)) }
| Pexp_poly (e, typ) ->
{ expr with pexp_desc = Pexp_poly (wrap_landmark_method ctx landmark loc e, typ)}
| _ -> wrap_landmark ctx landmark loc expr
Expand Down Expand Up @@ -256,10 +266,10 @@ let translate_value_bindings ctx value_binding auto vbs =
in
let vbs = List.map (function
| (vb, None) -> value_binding vb
| {pvb_pat; pvb_loc; pvb_expr; _}, Some (arity, _, name, loc, attrs) ->
| {pvb_pat; pvb_loc; pvb_expr; pvb_constraint; _}, Some (arity, _, name, loc, attrs) ->
(* Remove landmark attribute: *)
let vb =
Vb.mk ~attrs ~loc:pvb_loc pvb_pat pvb_expr
Vb.mk ~attrs ~loc:pvb_loc ?value_constraint:pvb_constraint pvb_pat pvb_expr
|> value_binding
in
if arity = [] then
Expand Down