@@ -392894,9 +392894,9 @@ let program js =
392894
392894
(scope_pass # program js ) # get_loop_mutable_values
392895
392895
392896
392896
end
392897
- module Js_pass_tailcall_inline : sig
392898
- #1 "js_pass_tailcall_inline .mli"
392899
- (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
392897
+ module Js_pass_get_used : sig
392898
+ #1 "js_pass_get_used .mli"
392899
+ (* Copyright (C) 2020- Authors of BuckleScript
392900
392900
*
392901
392901
* This program is free software: you can redistribute it and/or modify
392902
392902
* it under the terms of the GNU Lesser General Public License as published by
@@ -392922,29 +392922,11 @@ module Js_pass_tailcall_inline : sig
392922
392922
392923
392923
392924
392924
392925
-
392926
-
392927
-
392928
-
392929
-
392930
- (** This pass detect functions used once and if it is used in used
392931
- in the tail position, it will get inlined, this will help
392932
- remove some common use cases like This
392933
- {[
392934
- let length x =
392935
- let rec aux n x =
392936
- match x with
392937
- | [] -> n
392938
- | _ :: rest -> aux (n + 1) rest in
392939
- aux 0 x
392940
- ]}
392941
- *)
392942
-
392943
- val tailcall_inline : J.program -> J.program
392944
-
392925
+ val get_stats:
392926
+ J.program -> J.variable_declaration Hash_ident.t
392945
392927
end = struct
392946
- #1 "js_pass_tailcall_inline .ml"
392947
- (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
392928
+ #1 "js_pass_get_used .ml"
392929
+ (* Copyright (C) 2020- Authors of BuckleScript
392948
392930
*
392949
392931
* This program is free software: you can redistribute it and/or modify
392950
392932
* it under the terms of the GNU Lesser General Public License as published by
@@ -392969,24 +392951,6 @@ end = struct
392969
392951
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
392970
392952
392971
392953
392972
-
392973
-
392974
-
392975
-
392976
- (* When we inline a function call, if we don't do a beta-reduction immediately, there is
392977
- a chance that it is ignored, (we can not assume that each pass is robust enough)
392978
-
392979
- After we do inlining, it makes sense to do another constant folding and propogation
392980
- *)
392981
-
392982
- (* Check: shall we inline functions with while loop? if it is used only once,
392983
- it makes sense to inline it
392984
- *)
392985
-
392986
- module S = Js_stmt_make
392987
- (* module E = Js_exp_make *)
392988
-
392989
-
392990
392954
(** Update ident info use cases, it is a non pure function,
392991
392955
it will annotate [program] with some meta data
392992
392956
TODO: Ident Hash could be improved,
@@ -393003,12 +392967,10 @@ let count_collects () =
393003
392967
393004
392968
val mutable my_export_set : Set_ident.t = Set_ident.empty
393005
392969
393006
-
393007
392970
method add_use id =
393008
392971
Hash_ident.add_or_update stats id 1 ~update:succ
393009
392972
method! program x =
393010
392973
my_export_set <- x.export_set ;
393011
-
393012
392974
super#program x
393013
392975
method! variable_declaration
393014
392976
({ident; value ; property = _ ; ident_info = _} as v)
@@ -393043,6 +393005,101 @@ let count_collects () =
393043
393005
393044
393006
let get_stats (program : J.program) : J.variable_declaration Hash_ident.t
393045
393007
= ((count_collects ()) #program program) #get_stats
393008
+
393009
+ end
393010
+ module Js_pass_tailcall_inline : sig
393011
+ #1 "js_pass_tailcall_inline.mli"
393012
+ (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
393013
+ *
393014
+ * This program is free software: you can redistribute it and/or modify
393015
+ * it under the terms of the GNU Lesser General Public License as published by
393016
+ * the Free Software Foundation, either version 3 of the License, or
393017
+ * (at your option) any later version.
393018
+ *
393019
+ * In addition to the permissions granted to you by the LGPL, you may combine
393020
+ * or link a "work that uses the Library" with a publicly distributed version
393021
+ * of this file to produce a combined library or application, then distribute
393022
+ * that combined work under the terms of your choosing, with no requirement
393023
+ * to comply with the obligations normally placed on you by section 4 of the
393024
+ * LGPL version 3 (or the corresponding section of a later version of the LGPL
393025
+ * should you choose to use a later version).
393026
+ *
393027
+ * This program is distributed in the hope that it will be useful,
393028
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
393029
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
393030
+ * GNU Lesser General Public License for more details.
393031
+ *
393032
+ * You should have received a copy of the GNU Lesser General Public License
393033
+ * along with this program; if not, write to the Free Software
393034
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
393035
+
393036
+
393037
+
393038
+
393039
+
393040
+
393041
+
393042
+
393043
+ (** This pass detect functions used once and if it is used in used
393044
+ in the tail position, it will get inlined, this will help
393045
+ remove some common use cases like This
393046
+ {[
393047
+ let length x =
393048
+ let rec aux n x =
393049
+ match x with
393050
+ | [] -> n
393051
+ | _ :: rest -> aux (n + 1) rest in
393052
+ aux 0 x
393053
+ ]}
393054
+ *)
393055
+
393056
+ val tailcall_inline : J.program -> J.program
393057
+
393058
+ end = struct
393059
+ #1 "js_pass_tailcall_inline.ml"
393060
+ (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
393061
+ *
393062
+ * This program is free software: you can redistribute it and/or modify
393063
+ * it under the terms of the GNU Lesser General Public License as published by
393064
+ * the Free Software Foundation, either version 3 of the License, or
393065
+ * (at your option) any later version.
393066
+ *
393067
+ * In addition to the permissions granted to you by the LGPL, you may combine
393068
+ * or link a "work that uses the Library" with a publicly distributed version
393069
+ * of this file to produce a combined library or application, then distribute
393070
+ * that combined work under the terms of your choosing, with no requirement
393071
+ * to comply with the obligations normally placed on you by section 4 of the
393072
+ * LGPL version 3 (or the corresponding section of a later version of the LGPL
393073
+ * should you choose to use a later version).
393074
+ *
393075
+ * This program is distributed in the hope that it will be useful,
393076
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
393077
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
393078
+ * GNU Lesser General Public License for more details.
393079
+ *
393080
+ * You should have received a copy of the GNU Lesser General Public License
393081
+ * along with this program; if not, write to the Free Software
393082
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
393083
+
393084
+
393085
+
393086
+
393087
+
393088
+
393089
+ (* When we inline a function call, if we don't do a beta-reduction immediately, there is
393090
+ a chance that it is ignored, (we can not assume that each pass is robust enough)
393091
+
393092
+ After we do inlining, it makes sense to do another constant folding and propogation
393093
+ *)
393094
+
393095
+ (* Check: shall we inline functions with while loop? if it is used only once,
393096
+ it makes sense to inline it
393097
+ *)
393098
+
393099
+ module S = Js_stmt_make
393100
+ (* module E = Js_exp_make *)
393101
+
393102
+
393046
393103
393047
393104
393048
393105
(* 1. recursive value ? let rec x = 1 :: x
@@ -393173,7 +393230,7 @@ let subst (export_set : Set_ident.t) stats =
393173
393230
393174
393231
393175
393232
let tailcall_inline (program : J.program) =
393176
- let stats = get_stats program in
393233
+ let stats = Js_pass_get_used. get_stats program in
393177
393234
let export_set = program.export_set in
393178
393235
(subst export_set stats )#program program
393179
393236
0 commit comments