Skip to content

Commit 6866580

Browse files
authored
Merge pull request #2740 from BuckleScript/clean_arity
clean arity handling
2 parents 94f5939 + 28bd7e9 commit 6866580

26 files changed

+867
-853
lines changed

jscomp/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ CORE_SRCS= js_runtime_modules \
298298
lam_group \
299299
lam_pass_deep_flatten\
300300
js_stmt_make js_pass_flatten\
301-
js_pass_tailcall_inline js_of_lam_variant js_pass_flatten_and_mark_dead js_ast_util lam_dce lam_group_pass lam_compile_env lam_stats_util\
301+
js_pass_tailcall_inline js_of_lam_variant js_pass_flatten_and_mark_dead js_ast_util lam_dce lam_group_pass lam_compile_env lam_arity_analysis\
302302
lam_stats_export lam_pass_alpha_conversion lam_pass_collect\
303303
js_dump_lit\
304304
js_dump_string\

jscomp/all.depend

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ core/lam_dce.cmi : core/lam_group.cmi
387387
core/lam_compile_env.cmi : core/ocaml_types.cmi core/lam_module_ident.cmi \
388388
core/lam.cmi core/js_packages_info.cmi core/js_cmj_format.cmi \
389389
syntax/external_ffi_types.cmi
390-
core/lam_stats_util.cmi : core/lam_stats.cmi core/lam_arity.cmi core/lam.cmi
390+
core/lam_arity_analysis.cmi : core/lam_stats.cmi core/lam_arity.cmi \
391+
core/lam.cmi
391392
core/lam_stats_export.cmi : core/lam_stats.cmi core/lam_module_ident.cmi \
392393
core/lam.cmi core/js_cmj_format.cmi ext/ident_map.cmi
393394
core/lam_pass_alpha_conversion.cmi : core/lam_stats.cmi core/lam.cmi
@@ -565,24 +566,24 @@ core/lam_compile_env.cmx : ext/string_map.cmx core/ocaml_types.cmx \
565566
core/js_stmt_make.cmx core/js_exp_make.cmx common/js_config.cmx \
566567
core/js_cmj_load.cmx core/js_cmj_format.cmx syntax/external_ffi_types.cmx \
567568
ext/ext_string.cmx ext/ext_modulename.cmx core/lam_compile_env.cmi
568-
core/lam_stats_util.cmx : core/lam_stats.cmx core/lam_compile_env.cmx \
569+
core/lam_arity_analysis.cmx : core/lam_stats.cmx core/lam_compile_env.cmx \
569570
core/lam_arity.cmx core/lam.cmx ext/ident_hashtbl.cmx ext/ext_list.cmx \
570-
core/lam_stats_util.cmi
571-
core/lam_stats_export.cmx : ext/string_map.cmx core/lam_stats_util.cmx \
572-
core/lam_stats.cmx core/lam_module_ident.cmx core/lam_inline_util.cmx \
573-
core/lam_id_kind.cmx core/lam_compile_env.cmx core/lam_closure.cmx \
571+
core/lam_arity_analysis.cmi
572+
core/lam_stats_export.cmx : ext/string_map.cmx core/lam_stats.cmx \
573+
core/lam_module_ident.cmx core/lam_inline_util.cmx core/lam_id_kind.cmx \
574+
core/lam_compile_env.cmx core/lam_closure.cmx core/lam_arity_analysis.cmx \
574575
core/lam_arity.cmx core/lam_analysis.cmx core/lam.cmx \
575-
core/js_packages_state.cmx common/js_config.cmx core/js_cmj_format.cmx \
576-
ext/ident_set.cmx ext/ident_map.cmx ext/ident_hashtbl.cmx \
577-
ext/ext_string.cmx ext/ext_pervasives.cmx ext/ext_path.cmx \
578-
ext/ext_option.cmx common/ext_log.cmx ext/ext_list.cmx ext/ext_ident.cmx \
579-
ext/ext_array.cmx core/lam_stats_export.cmi
580-
core/lam_pass_alpha_conversion.cmx : core/lam_stats_util.cmx \
581-
core/lam_stats.cmx core/lam_eta_conversion.cmx core/lam.cmx \
582-
ext/ext_list.cmx core/lam_pass_alpha_conversion.cmi
583-
core/lam_pass_collect.cmx : core/lam_util.cmx core/lam_stats_util.cmx \
584-
core/lam_stats.cmx core/lam_arity.cmx core/lam.cmx ext/ident_set.cmx \
585-
ext/ident_hashtbl.cmx core/lam_pass_collect.cmi
576+
core/js_packages_state.cmx core/js_cmj_format.cmx ext/ident_set.cmx \
577+
ext/ident_map.cmx ext/ident_hashtbl.cmx ext/ext_option.cmx \
578+
common/ext_log.cmx ext/ext_list.cmx ext/ext_array.cmx \
579+
core/lam_stats_export.cmi
580+
core/lam_pass_alpha_conversion.cmx : core/lam_stats.cmx \
581+
core/lam_eta_conversion.cmx core/lam_arity_analysis.cmx \
582+
core/lam_arity.cmx core/lam.cmx ext/ext_list.cmx \
583+
core/lam_pass_alpha_conversion.cmi
584+
core/lam_pass_collect.cmx : core/lam_util.cmx core/lam_stats.cmx \
585+
core/lam_arity_analysis.cmx core/lam_arity.cmx core/lam.cmx \
586+
ext/ident_set.cmx ext/ident_hashtbl.cmx core/lam_pass_collect.cmi
586587
core/js_dump_lit.cmx : ext/literals.cmx ext/ext_string.cmx
587588
core/js_dump_string.cmx : ext/ext_pp.cmx core/js_dump_string.cmi
588589
core/js_dump_property.cmx : core/js_dump_string.cmx core/js_dump_lit.cmx \
@@ -682,10 +683,10 @@ core/lam_pass_remove_alias.cmx : core/lam_util.cmx core/lam_stats.cmx \
682683
ext/ident_set.cmx ext/ident_hashtbl.cmx ext/ext_list.cmx \
683684
core/lam_pass_remove_alias.cmi
684685
core/lam_coercion.cmx : ext/string_hash_set.cmx core/lam_util.cmx \
685-
core/lam_stats_util.cmx core/lam_stats.cmx core/lam_group.cmx \
686-
core/lam_dce.cmx core/lam.cmx ext/ident_set.cmx ext/ident_map.cmx \
687-
ext/ident_hashtbl.cmx ext/ext_list.cmx depends/bs_exception.cmx \
688-
core/lam_coercion.cmi
686+
core/lam_stats.cmx core/lam_group.cmx core/lam_dce.cmx \
687+
core/lam_arity_analysis.cmx core/lam_arity.cmx core/lam.cmx \
688+
ext/ident_set.cmx ext/ident_map.cmx ext/ident_hashtbl.cmx \
689+
ext/ext_list.cmx depends/bs_exception.cmx core/lam_coercion.cmi
689690
core/lam_compile_main.cmx : ext/literals.cmx core/lam_util.cmx \
690691
core/lam_stats_export.cmx core/lam_stats.cmx \
691692
core/lam_pass_remove_alias.cmx core/lam_pass_lets_dce.cmx \

jscomp/common/js_config.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ let (//) = Filename.concat
6565

6666
(* let get_packages_info () = !packages_info *)
6767

68-
let default_gen_tds = ref false
6968
let no_builtin_ppx_ml = ref false
7069
let no_builtin_ppx_mli = ref false
7170

jscomp/common/js_config.mli

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ val get_diagnose : unit -> bool
5757
val set_diagnose : bool -> unit
5858

5959

60-
(** generate tds option *)
61-
val default_gen_tds : bool ref
62-
6360
(** options for builtin ppx *)
6461
val no_builtin_ppx_ml : bool ref
6562
val no_builtin_ppx_mli : bool ref

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 Lam_arity.na
4545
(** we don't force people to use package *)
4646
type cmj_case = Ext_namespace.file_kind
4747

jscomp/core/js_main.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,6 @@ let buckle_script_flags : (string * Arg.spec * string) list =
192192
Arg.Set Js_config.cross_module_inline,
193193
"enable cross module inlining(experimental), default(false)")
194194
::
195-
("-bs-gen-tds",
196-
Arg.Set Js_config.default_gen_tds,
197-
" set will generate `.d.ts` file for typescript (experimental)")
198-
::
199195
("-bs-diagnose",
200196
Arg.Set Js_config.diagnose,
201197
" More verbose output")

jscomp/core/lam_arity.ml

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,96 @@
2424

2525

2626
type t =
27-
| Determin of bool * (int * Ident.t list option) 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 int list * bool
28+
(**
29+
the last one means it can take any params later,
30+
for an exception: it is (Determin (true,[], true))
31+
1. approximation sound but not complete
32+
33+
*)
34+
| Arity_na
3635

3736
let pp = Format.fprintf
3837

3938
let print (fmt : Format.formatter) (x : t) =
4039
match x with
41-
| NA -> pp fmt "?"
42-
| Determin (b,ls,tail) ->
40+
| Arity_na -> pp fmt "?"
41+
| Arity_info (ls,tail) ->
4342
begin
4443
pp fmt "@[";
45-
(if not b
46-
then
47-
pp fmt "~");
4844
pp fmt "[";
4945
Format.pp_print_list ~pp_sep:(fun fmt () -> pp fmt ",")
50-
(fun fmt (x,_) -> Format.pp_print_int fmt x)
46+
(fun fmt x -> Format.pp_print_int fmt x)
5147
fmt ls ;
5248
if tail
5349
then pp fmt "@ *";
5450
pp fmt "]@]";
5551
end
56-
57-
let print_arities_tbl
52+
53+
let print_arities_tbl
5854
(fmt : Format.formatter)
5955
(arities_tbl : (Ident.t, t ref) Hashtbl.t) =
6056
Hashtbl.fold (fun (i:Ident.t) (v : t ref) _ ->
6157
pp Format.err_formatter "@[%s -> %a@]@."i.name print !v ) arities_tbl ()
58+
59+
60+
61+
62+
63+
let merge
64+
(n : int )
65+
(x : t) : t =
66+
match x with
67+
| Arity_na -> Arity_info ( [n], false)
68+
| Arity_info (xs,tail) -> Arity_info ( n :: xs, tail)
69+
70+
71+
let non_function_arity_info =
72+
Arity_info ([], false)
73+
74+
let raise_arity_info =
75+
Arity_info ([],true)
76+
77+
let na = Arity_na
78+
79+
let info args b1 =
80+
Arity_info ( args, b1)
81+
82+
83+
let first_arity_na ( x : t ) =
84+
match x with
85+
| Arity_na
86+
| Arity_info ( [], _) -> true
87+
| _ -> false
88+
89+
let get_first_arity (x : t) =
90+
match x with
91+
| Arity_na
92+
| Arity_info ( [], _) -> None
93+
| Arity_info ( x::_, _) -> Some x
94+
95+
let extract_arity ( x : t) =
96+
match x with
97+
| Arity_na -> []
98+
| Arity_info(xs,_) -> xs
99+
100+
(* let update_arity (x : t) xs = *)
101+
102+
let rec
103+
merge_arities_aux
104+
(acc : int list)
105+
(xs : int list) (ys : int list) (tail : bool) (tail2 : bool) =
106+
match xs,ys with
107+
| [], [] ->
108+
info (List.rev acc) (tail && tail2)
109+
| [], y::ys when tail ->
110+
merge_arities_aux (y::acc) [] ys tail tail2
111+
| x::xs, [] when tail2 ->
112+
merge_arities_aux (x::acc) [] xs tail tail2
113+
| x::xs, y::ys when x = y ->
114+
merge_arities_aux (y :: acc) xs ys tail tail2
115+
| _, _ ->
116+
info (List.rev acc) false
117+
118+
let merge_arities xs ys t t2 =
119+
merge_arities_aux [] xs ys t t2

jscomp/core/lam_arity.mli

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,41 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525

26-
type t =
27-
| Determin of bool * (int * Ident.t list option) list * bool
26+
type t = private
27+
| Arity_info of 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,
31-
for an exception: it is (Determin (true,[], true))
32-
1. approximation sound but not complete
33-
31+
for an exception: it is (Arity_info([], true))
32+
approximation sound but not complete
3433
*)
35-
| NA
34+
| Arity_na
3635

3736
val print : Format.formatter -> t -> unit
3837

3938
val print_arities_tbl :
4039
Format.formatter ->
4140
(Ident.t, t ref) Hashtbl.t ->
4241
unit
42+
43+
val merge : int -> t -> t
44+
45+
val non_function_arity_info : t
46+
47+
val raise_arity_info : t
48+
49+
val na : t
50+
val info : int list -> bool -> t
51+
52+
val first_arity_na : t -> bool
53+
val get_first_arity : t -> int option
54+
55+
(** when [NA] return empty list*)
56+
val extract_arity : t -> int list
57+
58+
val merge_arities :
59+
int list ->
60+
int list ->
61+
bool ->
62+
bool ->
63+
t

0 commit comments

Comments
 (0)