Skip to content

Commit 0c9fd50

Browse files
committed
better names
1 parent 9e7ea22 commit 0c9fd50

File tree

9 files changed

+88
-80
lines changed

9 files changed

+88
-80
lines changed

jscomp/core/js_cmj_format.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type cmj_value = {
4141
type effect = string option
4242

4343

44-
let single_na = Single NA
44+
let single_na = Single Arity_na
4545
(** we don't force people to use package *)
4646
type cmj_case = Ext_namespace.file_kind
4747

jscomp/core/lam_arity.ml

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@
2424

2525

2626
type t =
27-
| Determin of bool * int list * bool
28-
(**
29-
when the first argument is true, it is for sure
30-
the last one means it can take any params later,
31-
for an exception: it is (Determin (true,[], true))
32-
1. approximation sound but not complete
33-
34-
*)
35-
| NA
27+
| Arity_info of bool * int list * bool
28+
(**
29+
when the first argument is true, it is for sure
30+
the last one means it can take any params later,
31+
for an exception: it is (Determin (true,[], true))
32+
1. approximation sound but not complete
33+
34+
*)
35+
| Arity_na
3636

3737
let pp = Format.fprintf
3838

3939
let print (fmt : Format.formatter) (x : t) =
4040
match x with
41-
| NA -> pp fmt "?"
42-
| Determin (b,ls,tail) ->
41+
| Arity_na -> pp fmt "?"
42+
| Arity_info (b,ls,tail) ->
4343
begin
4444
pp fmt "@[";
4545
(if not b
@@ -53,9 +53,20 @@ let print (fmt : Format.formatter) (x : t) =
5353
then pp fmt "@ *";
5454
pp fmt "]@]";
5555
end
56-
57-
let print_arities_tbl
56+
57+
let print_arities_tbl
5858
(fmt : Format.formatter)
5959
(arities_tbl : (Ident.t, t ref) Hashtbl.t) =
6060
Hashtbl.fold (fun (i:Ident.t) (v : t ref) _ ->
6161
pp Format.err_formatter "@[%s -> %a@]@."i.name print !v ) arities_tbl ()
62+
63+
64+
65+
66+
67+
let merge
68+
(n : int )
69+
(x : t) : t =
70+
match x with
71+
| Arity_na -> Arity_info (false, [n], false)
72+
| Arity_info (b,xs,tail) -> Arity_info (b, n :: xs, tail)

jscomp/core/lam_arity.mli

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@
2424

2525

2626
type t =
27-
| Determin of bool * int list * bool
27+
| Arity_info of bool * int list * bool
2828
(**
2929
when the first argument is true, it is for sure
3030
the last one means it can take any params later,
3131
for an exception: it is (Determin (true,[], true))
3232
1. approximation sound but not complete
3333
3434
*)
35-
| NA
35+
| Arity_na
3636

3737
val print : Format.formatter -> t -> unit
3838

3939
val print_arities_tbl :
4040
Format.formatter ->
4141
(Ident.t, t ref) Hashtbl.t ->
4242
unit
43+
44+
val merge : int -> t -> t

jscomp/core/lam_coercion.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,9 @@ let handle_exports (meta : Lam_stats.t)
136136
*)
137137
let newid = Ident.rename original_export_id in
138138
(match Lam_stats_util.get_arity meta lam with
139-
| NA
140-
| Determin(_,[],_) ->
141-
()
142-
| Determin _ as v ->
139+
| Arity_na
140+
| Arity_info(_,[],_) -> ()
141+
| Arity_info _ as v ->
143142
Ident_hashtbl.add meta.ident_tbl newid
144143
(FunctionId{
145144
arity = v; lambda = lam;

jscomp/core/lam_compile.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ and compile_external_field_apply
181181
match arity, len with
182182
| _, 0 ->
183183
acc (** All arguments consumed so far *)
184-
| Determin (a, x :: rest, b), len ->
184+
| Arity_info (a, x :: rest, b), len ->
185185
let x =
186186
if x = 0
187187
then 1
@@ -191,7 +191,7 @@ and compile_external_field_apply
191191
let first_part, continue = Ext_list.split_at x args in
192192
aux
193193
(E.call ~info:{arity=Full; call_info = Call_ml} acc first_part)
194-
(Determin (a, rest, b))
194+
(Arity_info (a, rest, b))
195195
continue (len - x)
196196
else (* GPR #1423 *)
197197
if List.for_all Js_analyzer.is_okay_to_duplicate args then
@@ -204,10 +204,10 @@ and compile_external_field_apply
204204
(* alpha conversion now? --
205205
Since we did an alpha conversion before so it is not here
206206
*)
207-
| Determin (a, [], b ), _ ->
207+
| Arity_info (a, [], b ), _ ->
208208
(* can not happen, unless it's an exception ? *)
209209
E.call ~info:Js_call_info.dummy acc args
210-
| NA, _ ->
210+
| Arity_na, _ ->
211211
E.call ~info:Js_call_info.dummy acc args
212212
in
213213
Js_output.output_of_block_and_expression
@@ -218,7 +218,7 @@ and compile_external_field_apply
218218
(
219219
aux
220220
(E.ml_var_dot id name)
221-
(match arity with Single x -> x | Submodule _ -> NA)
221+
(match arity with Single x -> x | Submodule _ -> Arity_na)
222222
args (List.length args ))
223223

224224

jscomp/core/lam_pass_alpha_conversion.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ let alpha_conversion (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
3838
-> (* detect functor application *)
3939
begin
4040
match Lam_stats_util.get_arity meta l1 with
41-
| NA ->
41+
| Arity_na ->
4242
Lam.apply (simpl l1) (Ext_list.map simpl ll) loc status
43-
| Determin (b, args, tail) ->
43+
| Arity_info (b, args, tail) ->
4444
let len = List.length ll in
4545
let rec take args =
4646
match args with
@@ -77,7 +77,7 @@ let alpha_conversion (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
7777
; loc } ->
7878

7979
begin match Lam_stats_util.get_arity meta arg with
80-
| Determin (b, x::_, tail)
80+
| Arity_info (b, x::_, tail)
8181
->
8282
let arg = simpl arg in
8383
Lam_eta_conversion.unsafe_adjust_to_arity loc

jscomp/core/lam_stats_export.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let values_of_export
4949
| Some (ImmutableBlock(elems,_)) ->
5050
Submodule(elems |> Array.map (fun (x : Lam_id_kind.element) ->
5151
match x with
52-
| NA -> Lam_arity.NA
52+
| NA -> Lam_arity.Arity_na
5353
| SimpleForm lam -> Lam_stats_util.get_arity meta lam)
5454
)
5555
| Some _

jscomp/core/lam_stats_util.ml

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
26-
let merge
27-
(n : int )
28-
(x : Lam_arity.t) : Lam_arity.t =
29-
match x with
30-
| NA -> Determin(false, [n], false)
31-
| Determin (b,xs,tail) -> Determin (b, n :: xs, tail)
32-
3325

3426
let arity_of_var (meta : Lam_stats.t) (v : Ident.t) =
3527
(** for functional parameter, if it is a high order function,
@@ -42,7 +34,7 @@ let arity_of_var (meta : Lam_stats.t) (v : Ident.t) =
4234
| None ->
4335
(* Format.fprintf Format.err_formatter *)
4436
(* "@[%s %a is not function/functor@]@." meta.filename Ident.print v ; *)
45-
(NA : Lam_arity.t)
37+
Arity_na
4638

4739
end
4840

@@ -56,7 +48,7 @@ let rec get_arity
5648
(lam : Lam.t) :
5749
Lam_arity.t =
5850
match lam with
59-
| Lconst _ -> Determin (true,[], false)
51+
| Lconst _ -> Arity_info (true,[], false)
6052
| Lvar v -> arity_of_var meta v
6153
| Llet(_,_,_, l ) -> get_arity meta l
6254

@@ -70,22 +62,22 @@ let rec get_arity
7062
args = [ Lglobal_module id ]; _} ->
7163
begin match (Lam_compile_env.cached_find_ml_id_pos id n meta.env).arity with
7264
| Single x -> x
73-
| Submodule _ -> NA
65+
| Submodule _ -> Arity_na
7466
end
7567
| Lprim {primitive = Pfield (m,_);
7668
args = [ Lprim{primitive = Pfield(n,_);
7769
args = [ Lglobal_module id]} ]
7870
; _} ->
7971
begin match (Lam_compile_env.cached_find_ml_id_pos id n meta.env).arity with
8072
| Submodule subs -> subs.(m)
81-
| Single _ -> NA
73+
| Single _ -> Arity_na
8274
end
8375

84-
| Lprim {primitive = Pfield _; _} -> NA (** TODO *)
85-
| Lprim {primitive = Praise ; _} -> Determin(true,[], true)
86-
| Lprim {primitive = Pccall _; _} -> Determin(false, [], false)
76+
| Lprim {primitive = Pfield _; _} -> Arity_na (** TODO *)
77+
| Lprim {primitive = Praise ; _} -> Arity_info (true,[], true)
78+
| Lprim {primitive = Pccall _; _} -> Arity_info (false, [], false)
8779
| Lglobal_module _ (* TODO: fix me never going to happen assert false *)
88-
| Lprim _ -> Determin(true,[] ,false)
80+
| Lprim _ -> Arity_info (true,[] ,false)
8981
(* shall we handle primitive in a direct way,
9082
since we know all the information
9183
Invariant: all primitive application is fully applied,
@@ -106,22 +98,22 @@ let rec get_arity
10698
| Lapply{fn = app; args; _ } -> (* detect functor application *)
10799
let fn = get_arity meta app in
108100
begin match fn with
109-
| NA -> NA
110-
| Determin (b, xs, tail ) ->
101+
| Arity_na -> Arity_na
102+
| Arity_info (b, xs, tail ) ->
111103
let rec take (xs : _ list) arg_length =
112104
match xs with
113105
| (x) :: xs ->
114-
if arg_length = x then Lam_arity.Determin (b, xs, tail)
106+
if arg_length = x then Lam_arity.Arity_info (b, xs, tail)
115107
else if arg_length > x then
116108
take xs (arg_length - x)
117-
else Determin (b,
109+
else Arity_info (b,
118110
(x - arg_length ) :: xs ,
119111
tail)
120112
| [] ->
121-
if tail then Determin(b, [], tail)
113+
if tail then Arity_info (b, [], tail)
122114
else if not b then
123-
NA
124-
else NA
115+
Arity_na
116+
else Arity_na
125117
(* Actually, you can not have truly deministic arities
126118
for example [fun x -> x ]
127119
*)
@@ -132,7 +124,7 @@ let rec get_arity
132124
take xs (List.length args)
133125
end
134126
| Lfunction {arity; function_kind; params; body = l} ->
135-
merge arity (get_arity meta l)
127+
Lam_arity.merge arity (get_arity meta l)
136128
| Lswitch(l, {sw_failaction;
137129
sw_consts;
138130
sw_blocks;
@@ -149,31 +141,31 @@ let rec get_arity
149141
| None -> all_lambdas meta (Ext_list.map snd sw )
150142
| Some v -> all_lambdas meta (v:: Ext_list.map snd sw)
151143
end
152-
| Lstaticraise _ -> NA (* since it will not be in tail position *)
144+
| Lstaticraise _ -> Arity_na (* since it will not be in tail position *)
153145
| Lstaticcatch(_, _, handler) -> get_arity meta handler
154146
| Ltrywith(l1, _, l2) ->
155147
all_lambdas meta [l1;l2]
156148
| Lifthenelse(l1, l2, l3) ->
157149
all_lambdas meta [l2;l3]
158150
| Lsequence(_, l2) -> get_arity meta l2
159-
| Lsend(u, m, o, ll, v) -> NA
160-
| Lifused(v, l) -> NA
151+
| Lsend(u, m, o, ll, v) -> Arity_na
152+
| Lifused(v, l) -> Arity_na
161153
| Lwhile _
162154
| Lfor _
163-
| Lassign _ -> Determin(true,[], false)
155+
| Lassign _ -> Arity_info (true,[], false)
164156

165157
and all_lambdas meta (xs : Lam.t list) =
166158
match xs with
167159
| y :: ys ->
168160
let arity = get_arity meta y in
169161
List.fold_left (fun exist (v : Lam.t) ->
170162
match (exist : Lam_arity.t) with
171-
| NA -> NA
172-
| Determin (b, xs, tail) ->
163+
| Arity_na -> Arity_na
164+
| Arity_info (b, xs, tail) ->
173165
begin
174166
match get_arity meta v with
175-
| NA -> NA
176-
| Determin (u,ys,tail2) ->
167+
| Arity_na -> Arity_na
168+
| Arity_info (u,ys,tail2) ->
177169
let rec aux (b,acc) xs ys =
178170
match xs,ys with
179171
| [], [] -> (b, List.rev acc, tail && tail2)
@@ -184,7 +176,7 @@ and all_lambdas meta (xs : Lam.t list) =
184176
| x::xs, y::ys when x = y -> aux (b, (y :: acc)) xs ys
185177
| _, _ -> (false, List.rev acc, false) in
186178
let (b,acc, tail3) = aux ( u &&b, []) xs ys in
187-
Determin (b,acc, tail3)
179+
Arity_info (b,acc, tail3)
188180
end
189181
) arity ys
190182
| _ -> assert false

0 commit comments

Comments
 (0)