Skip to content

Commit e5fa6e5

Browse files
committed
clean up curry printing
1 parent e26a74f commit e5fa6e5

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

parsing/pprintast.ml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,14 @@ let protect_longident ppf print_longident longprefix txt =
118118
let is_curry_attr attr =
119119
attr.attr_name.txt = Builtin_attributes.curry_attr_name
120120

121-
let filter_curry_attrs attrs =
122-
List.filter (fun attr -> not (is_curry_attr attr)) attrs
123-
124-
let has_non_curry_attr attrs =
125-
List.exists (fun attr -> not (is_curry_attr attr)) attrs
121+
let split_out_curry_attr attrs =
122+
let curry, non_curry = List.partition is_curry_attr attrs in
123+
let is_curry =
124+
match curry with
125+
| [] -> false
126+
| _ :: _ -> true
127+
in
128+
is_curry, non_curry
126129

127130
type space_formatter = (unit, Format.formatter, unit) format
128131

@@ -496,10 +499,9 @@ and name_jkind f (name, jkind) =
496499
(jkind_annotation reset_ctxt) jkind
497500
498501
and core_type ctxt f x =
499-
let filtered_attrs = filter_curry_attrs x.ptyp_attributes in
500-
if filtered_attrs <> [] then begin
502+
if x.ptyp_attributes <> [] then begin
501503
pp f "((%a)%a)" (core_type ctxt) {x with ptyp_attributes=[]}
502-
(attributes ctxt) filtered_attrs
504+
(attributes ctxt) x.ptyp_attributes
503505
end
504506
else match x.ptyp_desc with
505507
| Ptyp_arrow (l, ct1, ct2, m1, m2) ->
@@ -523,8 +525,7 @@ and core_type ctxt f x =
523525
| _ -> pp f "@[<2>%a@]" (core_type1 ctxt) x
524526
525527
and core_type1 ctxt f x =
526-
(* CR zqian: the logic about curry should be pushed into Ptyp_arrow *)
527-
if has_non_curry_attr x.ptyp_attributes then core_type ctxt f x
528+
if x.ptyp_attributes <> [] then core_type ctxt f x
528529
else
529530
match x.ptyp_desc with
530531
| Ptyp_any jkind -> tyvar_loc_option_jkind f (None, jkind)
@@ -626,7 +627,9 @@ and labeled_core_type1 ctxt f (label, ty) =
626627
core_type1 ctxt f ty
627628
628629
and return_type ctxt f (x, m) =
629-
if x.ptyp_attributes <> [] then core_type_with_optional_legacy_modes core_type1 ctxt f (x, m)
630+
let is_curry, ptyp_attributes = split_out_curry_attr x.ptyp_attributes in
631+
let x = {x with ptyp_attributes} in
632+
if is_curry then core_type_with_optional_legacy_modes core_type1 ctxt f (x, m)
630633
else core_type_with_optional_legacy_modes core_type ctxt f (x, m)
631634
632635
and core_type_with_optional_modes ctxt f (ty, modes) =

0 commit comments

Comments
 (0)