Skip to content

Commit b804109

Browse files
committed
AST: test storing arity in function type
1 parent 7a42482 commit b804109

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+145
-89
lines changed

analysis/src/SignatureHelp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ let extractParameters ~signature ~typeStrForParser ~labelPrefixLen =
128128
| {
129129
(* Gotcha: functions with multiple arugments are modelled as a series of single argument functions. *)
130130
Parsetree.ptyp_desc =
131-
Ptyp_arrow (argumentLabel, argumentTypeExpr, nextFunctionExpr);
131+
Ptyp_arrow (argumentLabel, argumentTypeExpr, nextFunctionExpr, _);
132132
ptyp_loc;
133133
} ->
134134
let startOffset =

compiler/frontend/ast_compatible.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ let apply_labels ?(loc = default_loc) ?(attrs = []) fn
9696

9797
let label_arrow ?(loc = default_loc) ?(attrs = []) s a b : core_type =
9898
{
99-
ptyp_desc = Ptyp_arrow (Asttypes.Labelled s, a, b);
99+
ptyp_desc = Ptyp_arrow (Asttypes.Labelled s, a, b, None);
100100
ptyp_loc = loc;
101101
ptyp_attributes = attrs;
102102
}
103103

104104
let opt_arrow ?(loc = default_loc) ?(attrs = []) s a b : core_type =
105105
{
106-
ptyp_desc = Ptyp_arrow (Asttypes.Optional s, a, b);
106+
ptyp_desc = Ptyp_arrow (Asttypes.Optional s, a, b, None);
107107
ptyp_loc = loc;
108108
ptyp_attributes = attrs;
109109
}

compiler/frontend/ast_core_type.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ let make_obj ~loc xs = Typ.object_ ~loc xs Closed
108108
*)
109109
let rec get_uncurry_arity_aux (ty : t) acc =
110110
match ty.ptyp_desc with
111-
| Ptyp_arrow (_, _, new_ty) -> get_uncurry_arity_aux new_ty (succ acc)
111+
| Ptyp_arrow (_, _, new_ty, _) -> get_uncurry_arity_aux new_ty (succ acc)
112112
| Ptyp_poly (_, ty) -> get_uncurry_arity_aux ty acc
113113
| _ -> acc
114114

@@ -119,7 +119,7 @@ let rec get_uncurry_arity_aux (ty : t) acc =
119119
*)
120120
let get_uncurry_arity (ty : t) =
121121
match ty.ptyp_desc with
122-
| Ptyp_arrow (_, _, rest) -> Some (get_uncurry_arity_aux rest 1)
122+
| Ptyp_arrow (_, _, rest, _) -> Some (get_uncurry_arity_aux rest 1)
123123
| _ -> None
124124

125125
let get_curry_arity (ty : t) =
@@ -139,15 +139,15 @@ type param_type = {
139139
let mk_fn_type (new_arg_types_ty : param_type list) (result : t) : t =
140140
Ext_list.fold_right new_arg_types_ty result (fun {label; ty; attr; loc} acc ->
141141
{
142-
ptyp_desc = Ptyp_arrow (label, ty, acc);
142+
ptyp_desc = Ptyp_arrow (label, ty, acc, None);
143143
ptyp_loc = loc;
144144
ptyp_attributes = attr;
145145
})
146146

147147
let list_of_arrow (ty : t) : t * param_type list =
148148
let rec aux (ty : t) acc =
149149
match ty.ptyp_desc with
150-
| Ptyp_arrow (label, t1, t2) ->
150+
| Ptyp_arrow (label, t1, t2, _) ->
151151
aux t2
152152
(({label; ty = t1; attr = ty.ptyp_attributes; loc = ty.ptyp_loc}
153153
: param_type)

compiler/frontend/ast_core_type_class_type.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
6969
| {
7070
ptyp_attributes;
7171
ptyp_desc =
72-
( Ptyp_arrow (label, args, body)
72+
( Ptyp_arrow (label, args, body, _)
7373
| Ptyp_constr
7474
(* function$<...> is re-wrapped around only in case Nothing below *)
7575
( {txt = Lident "function$"},
76-
[{ptyp_desc = Ptyp_arrow (label, args, body)}; _] ) );
76+
[{ptyp_desc = Ptyp_arrow (label, args, body, _)}; _] ) );
7777
(* let it go without regard label names,
7878
it will report error later when the label is not empty
7979
*)

compiler/frontend/bs_ast_mapper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ module T = struct
101101
match desc with
102102
| Ptyp_any -> any ~loc ~attrs ()
103103
| Ptyp_var s -> var ~loc ~attrs s
104-
| Ptyp_arrow (lab, t1, t2) ->
104+
| Ptyp_arrow (lab, t1, t2, _) ->
105105
arrow ~loc ~attrs lab (sub.typ sub t1) (sub.typ sub t2)
106106
| Ptyp_tuple tyl -> tuple ~loc ~attrs (List.map (sub.typ sub) tyl)
107107
| Ptyp_constr (lid, tl) ->

compiler/gentype/TranslateCoreType.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ let rec translate_arrow_type ~config ~type_vars_gen
5252
~no_function_return_dependencies ~type_env ~rev_arg_deps ~rev_args
5353
(core_type : Typedtree.core_type) =
5454
match core_type.ctyp_desc with
55-
| Ttyp_arrow (Nolabel, core_type1, core_type2) ->
55+
| Ttyp_arrow (Nolabel, core_type1, core_type2, _) ->
5656
let {dependencies; type_} =
5757
core_type1 |> fun __x ->
5858
translateCoreType_ ~config ~type_vars_gen ~type_env __x
@@ -62,8 +62,8 @@ let rec translate_arrow_type ~config ~type_vars_gen
6262
|> translate_arrow_type ~config ~type_vars_gen
6363
~no_function_return_dependencies ~type_env ~rev_arg_deps:next_rev_deps
6464
~rev_args:((Nolabel, type_) :: rev_args)
65-
| Ttyp_arrow (((Labelled lbl | Optional lbl) as label), core_type1, core_type2)
66-
-> (
65+
| Ttyp_arrow
66+
(((Labelled lbl | Optional lbl) as label), core_type1, core_type2, _) -> (
6767
let as_label =
6868
match core_type.ctyp_attributes |> Annotation.get_gentype_as_renaming with
6969
| Some s -> s

compiler/ml/ast_helper.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ module Typ = struct
5454

5555
let any ?loc ?attrs () = mk ?loc ?attrs Ptyp_any
5656
let var ?loc ?attrs a = mk ?loc ?attrs (Ptyp_var a)
57-
let arrow ?loc ?attrs a b c = mk ?loc ?attrs (Ptyp_arrow (a, b, c))
57+
let arrow ?loc ?attrs ?arity a b c =
58+
mk ?loc ?attrs (Ptyp_arrow (a, b, c, arity))
5859
let tuple ?loc ?attrs a = mk ?loc ?attrs (Ptyp_tuple a)
5960
let constr ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_constr (a, b))
6061
let object_ ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_object (a, b))
@@ -81,8 +82,8 @@ module Typ = struct
8182
| Ptyp_var x ->
8283
check_variable var_names t.ptyp_loc x;
8384
Ptyp_var x
84-
| Ptyp_arrow (label, core_type, core_type') ->
85-
Ptyp_arrow (label, loop core_type, loop core_type')
85+
| Ptyp_arrow (label, core_type, core_type', a) ->
86+
Ptyp_arrow (label, loop core_type, loop core_type', a)
8687
| Ptyp_tuple lst -> Ptyp_tuple (List.map loop lst)
8788
| Ptyp_constr ({txt = Longident.Lident s}, []) when List.mem s var_names
8889
->

compiler/ml/ast_helper.mli

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ module Typ : sig
5555
val any : ?loc:loc -> ?attrs:attrs -> unit -> core_type
5656
val var : ?loc:loc -> ?attrs:attrs -> string -> core_type
5757
val arrow :
58-
?loc:loc -> ?attrs:attrs -> arg_label -> core_type -> core_type -> core_type
58+
?loc:loc ->
59+
?attrs:attrs ->
60+
?arity:int ->
61+
arg_label ->
62+
core_type ->
63+
core_type ->
64+
core_type
5965
val tuple : ?loc:loc -> ?attrs:attrs -> core_type list -> core_type
6066
val constr : ?loc:loc -> ?attrs:attrs -> lid -> core_type list -> core_type
6167
val object_ :

compiler/ml/ast_iterator.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module T = struct
9696
sub.attributes sub attrs;
9797
match desc with
9898
| Ptyp_any | Ptyp_var _ -> ()
99-
| Ptyp_arrow (_lab, t1, t2) ->
99+
| Ptyp_arrow (_lab, t1, t2, _) ->
100100
sub.typ sub t1;
101101
sub.typ sub t2
102102
| Ptyp_tuple tyl -> List.iter (sub.typ sub) tyl

compiler/ml/ast_mapper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module T = struct
9393
match desc with
9494
| Ptyp_any -> any ~loc ~attrs ()
9595
| Ptyp_var s -> var ~loc ~attrs s
96-
| Ptyp_arrow (lab, t1, t2) ->
96+
| Ptyp_arrow (lab, t1, t2, _) ->
9797
arrow ~loc ~attrs lab (sub.typ sub t1) (sub.typ sub t2)
9898
| Ptyp_tuple tyl -> tuple ~loc ~attrs (List.map (sub.typ sub) tyl)
9999
| Ptyp_constr (lid, tl) ->

0 commit comments

Comments
 (0)