@@ -94741,7 +94741,10 @@ let subst_helper (subst : subst_tbl) query lam =
94741
94741
let new_l = simplif l
94742
94742
and new_consts = List.map (fun (n, e) -> (n, simplif e)) sw.sw_consts
94743
94743
and new_blocks = List.map (fun (n, e) -> (n, simplif e)) sw.sw_blocks
94744
- and new_fail = Misc.may_map simplif sw.sw_failaction in
94744
+ and new_fail =
94745
+ begin match sw.sw_failaction with
94746
+ | None -> None
94747
+ | Some x -> Some (simplif x) end in
94745
94748
Lam.switch
94746
94749
new_l
94747
94750
{
@@ -94752,7 +94755,7 @@ let subst_helper (subst : subst_tbl) query lam =
94752
94755
| Lstringswitch(l,sw,d) ->
94753
94756
Lam.stringswitch
94754
94757
(simplif l) (List.map (fun (s,l) -> s,simplif l) sw)
94755
- (Misc.may_map simplif d)
94758
+ (begin match d with None -> None | Some d -> Some ( simplif d) end )
94756
94759
| Ltrywith (l1, v, l2) ->
94757
94760
Lam.try_ (simplif l1) v (simplif l2)
94758
94761
| Lifthenelse (l1, l2, l3) ->
@@ -95007,46 +95010,49 @@ let collect_occurs lam : occ_tbl =
95007
95010
95008
95011
95009
95012
end
95010
- module Lam_pass_lets_dce : sig
95011
- #1 "lam_pass_lets_dce.mli"
95012
- (***********************************************************************)
95013
- (* *)
95014
- (* OCaml *)
95015
- (* *)
95016
- (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
95017
- (* *)
95018
- (* Copyright 1996 Institut National de Recherche en Informatique et *)
95019
- (* en Automatique. All rights reserved. This file is distributed *)
95020
- (* under the terms of the Q Public License version 1.0. *)
95021
- (* *)
95022
- (***********************************************************************)
95023
- (* Adapted for Javascript backend: Hongbo Zhang *)
95013
+ module Lam_pass_eliminate_ref : sig
95014
+ #1 "lam_pass_eliminate_ref.mli"
95015
+ (* Copyright (C) 2015-2016 Bloomberg Finance L.P.
95016
+ *
95017
+ * This program is free software: you can redistribute it and/or modify
95018
+ * it under the terms of the GNU Lesser General Public License as published by
95019
+ * the Free Software Foundation, either version 3 of the License, or
95020
+ * (at your option) any later version.
95021
+ *
95022
+ * In addition to the permissions granted to you by the LGPL, you may combine
95023
+ * or link a "work that uses the Library" with a publicly distributed version
95024
+ * of this file to produce a combined library or application, then distribute
95025
+ * that combined work under the terms of your choosing, with no requirement
95026
+ * to comply with the obligations normally placed on you by section 4 of the
95027
+ * LGPL version 3 (or the corresponding section of a later version of the LGPL
95028
+ * should you choose to use a later version).
95029
+ *
95030
+ * This program is distributed in the hope that it will be useful,
95031
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
95032
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95033
+ * GNU Lesser General Public License for more details.
95034
+ *
95035
+ * You should have received a copy of the GNU Lesser General Public License
95036
+ * along with this program; if not, write to the Free Software
95037
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
95038
+
95039
+
95040
+ exception Real_reference
95041
+
95042
+ val eliminate_ref :
95043
+ Ident.t ->
95044
+ Lam.t ->
95045
+ Lam.t
95046
+
95024
95047
95025
- (**
95026
- This pass would do beta reduction, and dead code elimination (adapted from compiler's built-in [Simplif] module )
95027
95048
95028
- 1. beta reduction -> Llet (Strict )
95029
-
95030
- 2. The global table [occ] associates to each let-bound identifier
95031
- the number of its uses (as a reference):
95032
- - 0 if never used
95033
- - 1 if used exactly once in and *not under a lambda or within a loop
95034
- - > 1 if used several times or under a lambda or within a loop.
95035
95049
95036
- The local table [bv] associates to each locally-let-bound variable
95037
- its reference count, as above. [bv] is enriched at let bindings
95038
- but emptied when crossing lambdas and loops.
95039
95050
95040
- For this pass, when it' used under a lambda or within a loop, we don't do anything,
95041
- in theory, we can still do something if it's pure but we are conservative here.
95042
95051
95043
- [bv] is used to help caculate [occ] it is not useful outside
95044
95052
95045
- *)
95046
- val simplify_lets : Lam.t -> Lam.t
95047
95053
95048
95054
end = struct
95049
- #1 "lam_pass_lets_dce .ml"
95055
+ #1 "lam_pass_eliminate_ref .ml"
95050
95056
(***********************************************************************)
95051
95057
(* *)
95052
95058
(* OCaml *)
@@ -95061,7 +95067,7 @@ end = struct
95061
95067
(* Adapted for Javascript backend : Hongbo Zhang, *)
95062
95068
95063
95069
95064
- open Asttypes
95070
+
95065
95071
95066
95072
exception Real_reference
95067
95073
@@ -95127,12 +95133,17 @@ let rec eliminate_ref id (lam : Lam.t) =
95127
95133
sw_blocks =
95128
95134
List.map (fun (n, e) -> (n, eliminate_ref id e)) sw.sw_blocks;
95129
95135
sw_failaction =
95130
- Misc.may_map (eliminate_ref id) sw.sw_failaction; }
95136
+ match sw.sw_failaction with
95137
+ | None -> None
95138
+ | Some x -> Some (eliminate_ref id x)
95139
+ }
95131
95140
| Lstringswitch(e, sw, default) ->
95132
95141
Lam.stringswitch
95133
95142
(eliminate_ref id e)
95134
95143
(List.map (fun (s, e) -> (s, eliminate_ref id e)) sw)
95135
- (Misc.may_map (eliminate_ref id) default)
95144
+ (match default with
95145
+ | None -> None
95146
+ | Some x -> Some (eliminate_ref id x))
95136
95147
| Lstaticraise (i,args) ->
95137
95148
Lam.staticraise i (List.map (eliminate_ref id) args)
95138
95149
| Lstaticcatch(e1, i, e2) ->
@@ -95162,6 +95173,61 @@ let rec eliminate_ref id (lam : Lam.t) =
95162
95173
95163
95174
95164
95175
95176
+ end
95177
+ module Lam_pass_lets_dce : sig
95178
+ #1 "lam_pass_lets_dce.mli"
95179
+ (***********************************************************************)
95180
+ (* *)
95181
+ (* OCaml *)
95182
+ (* *)
95183
+ (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
95184
+ (* *)
95185
+ (* Copyright 1996 Institut National de Recherche en Informatique et *)
95186
+ (* en Automatique. All rights reserved. This file is distributed *)
95187
+ (* under the terms of the Q Public License version 1.0. *)
95188
+ (* *)
95189
+ (***********************************************************************)
95190
+ (* Adapted for Javascript backend: Hongbo Zhang *)
95191
+
95192
+ (**
95193
+ This pass would do beta reduction, and dead code elimination (adapted from compiler's built-in [Simplif] module )
95194
+
95195
+ 1. beta reduction -> Llet (Strict )
95196
+
95197
+ 2. The global table [occ] associates to each let-bound identifier
95198
+ the number of its uses (as a reference):
95199
+ - 0 if never used
95200
+ - 1 if used exactly once in and *not under a lambda or within a loop
95201
+ - > 1 if used several times or under a lambda or within a loop.
95202
+
95203
+ The local table [bv] associates to each locally-let-bound variable
95204
+ its reference count, as above. [bv] is enriched at let bindings
95205
+ but emptied when crossing lambdas and loops.
95206
+
95207
+ For this pass, when it' used under a lambda or within a loop, we don't do anything,
95208
+ in theory, we can still do something if it's pure but we are conservative here.
95209
+
95210
+ [bv] is used to help caculate [occ] it is not useful outside
95211
+
95212
+ *)
95213
+ val simplify_lets : Lam.t -> Lam.t
95214
+
95215
+ end = struct
95216
+ #1 "lam_pass_lets_dce.ml"
95217
+ (***********************************************************************)
95218
+ (* *)
95219
+ (* OCaml *)
95220
+ (* *)
95221
+ (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
95222
+ (* *)
95223
+ (* Copyright 1996 Institut National de Recherche en Informatique et *)
95224
+ (* en Automatique. All rights reserved. This file is distributed *)
95225
+ (* under the terms of the Q Public License version 1.0. *)
95226
+ (* *)
95227
+ (***********************************************************************)
95228
+ (* Adapted for Javascript backend : Hongbo Zhang, *)
95229
+
95230
+
95165
95231
let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam =
95166
95232
let subst : Lam.t Ident_hashtbl.t = Ident_hashtbl.create 32 in
95167
95233
let string_table : string Ident_hashtbl.t = Ident_hashtbl.create 32 in
@@ -95183,8 +95249,9 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam =
95183
95249
begin
95184
95250
try (** TODO: record all references variables *)
95185
95251
Lam_util.refine_let
95186
- ~kind:Variable v slinit (eliminate_ref v slbody)
95187
- with Real_reference ->
95252
+ ~kind:Variable v slinit
95253
+ (Lam_pass_eliminate_ref.eliminate_ref v slbody)
95254
+ with Lam_pass_eliminate_ref.Real_reference ->
95188
95255
Lam_util.refine_let
95189
95256
~kind v (Lam.prim ~primitive ~args:[slinit] loc)
95190
95257
slbody
@@ -95344,15 +95411,19 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam =
95344
95411
let new_l = simplif l
95345
95412
and new_consts = List.map (fun (n, e) -> (n, simplif e)) sw.sw_consts
95346
95413
and new_blocks = List.map (fun (n, e) -> (n, simplif e)) sw.sw_blocks
95347
- and new_fail = Misc.may_map simplif sw.sw_failaction in
95414
+ and new_fail =
95415
+ match sw.sw_failaction with
95416
+ | None -> None
95417
+ | Some x -> Some (simplif x)
95418
+ in
95348
95419
Lam.switch
95349
95420
new_l
95350
95421
{sw with sw_consts = new_consts ; sw_blocks = new_blocks;
95351
95422
sw_failaction = new_fail}
95352
95423
| Lstringswitch (l,sw,d) ->
95353
95424
Lam.stringswitch
95354
95425
(simplif l) (List.map (fun (s,l) -> s,simplif l) sw)
95355
- (Misc.may_map simplif d)
95426
+ (match d with None -> None | Some d -> Some ( simplif d) )
95356
95427
| Lstaticraise (i,ls) ->
95357
95428
Lam.staticraise i (List.map simplif ls)
95358
95429
| Lstaticcatch(l1, (i,args), l2) ->
0 commit comments