@@ -94741,7 +94741,10 @@ let subst_helper (subst : subst_tbl) query lam =
9474194741 let new_l = simplif l
9474294742 and new_consts = List.map (fun (n, e) -> (n, simplif e)) sw.sw_consts
9474394743 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
9474594748 Lam.switch
9474694749 new_l
9474794750 {
@@ -94752,7 +94755,7 @@ let subst_helper (subst : subst_tbl) query lam =
9475294755 | Lstringswitch(l,sw,d) ->
9475394756 Lam.stringswitch
9475494757 (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 )
9475694759 | Ltrywith (l1, v, l2) ->
9475794760 Lam.try_ (simplif l1) v (simplif l2)
9475894761 | Lifthenelse (l1, l2, l3) ->
@@ -95007,46 +95010,49 @@ let collect_occurs lam : occ_tbl =
9500795010
9500895011
9500995012end
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+
9502495047
95025- (**
95026- This pass would do beta reduction, and dead code elimination (adapted from compiler's built-in [Simplif] module )
9502795048
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.
9503595049
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.
9503995050
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.
9504295051
95043- [bv] is used to help caculate [occ] it is not useful outside
9504495052
95045- *)
95046- val simplify_lets : Lam.t -> Lam.t
9504795053
9504895054end = struct
95049- #1 "lam_pass_lets_dce .ml"
95055+ #1 "lam_pass_eliminate_ref .ml"
9505095056(***********************************************************************)
9505195057(* *)
9505295058(* OCaml *)
@@ -95061,7 +95067,7 @@ end = struct
9506195067(* Adapted for Javascript backend : Hongbo Zhang, *)
9506295068
9506395069
95064- open Asttypes
95070+
9506595071
9506695072exception Real_reference
9506795073
@@ -95127,12 +95133,17 @@ let rec eliminate_ref id (lam : Lam.t) =
9512795133 sw_blocks =
9512895134 List.map (fun (n, e) -> (n, eliminate_ref id e)) sw.sw_blocks;
9512995135 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+ }
9513195140 | Lstringswitch(e, sw, default) ->
9513295141 Lam.stringswitch
9513395142 (eliminate_ref id e)
9513495143 (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))
9513695147 | Lstaticraise (i,args) ->
9513795148 Lam.staticraise i (List.map (eliminate_ref id) args)
9513895149 | Lstaticcatch(e1, i, e2) ->
@@ -95162,6 +95173,61 @@ let rec eliminate_ref id (lam : Lam.t) =
9516295173
9516395174
9516495175
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+
9516595231let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam =
9516695232 let subst : Lam.t Ident_hashtbl.t = Ident_hashtbl.create 32 in
9516795233 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 =
9518395249 begin
9518495250 try (** TODO: record all references variables *)
9518595251 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 ->
9518895255 Lam_util.refine_let
9518995256 ~kind v (Lam.prim ~primitive ~args:[slinit] loc)
9519095257 slbody
@@ -95344,15 +95411,19 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam =
9534495411 let new_l = simplif l
9534595412 and new_consts = List.map (fun (n, e) -> (n, simplif e)) sw.sw_consts
9534695413 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
9534895419 Lam.switch
9534995420 new_l
9535095421 {sw with sw_consts = new_consts ; sw_blocks = new_blocks;
9535195422 sw_failaction = new_fail}
9535295423 | Lstringswitch (l,sw,d) ->
9535395424 Lam.stringswitch
9535495425 (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) )
9535695427 | Lstaticraise (i,ls) ->
9535795428 Lam.staticraise i (List.map simplif ls)
9535895429 | Lstaticcatch(l1, (i,args), l2) ->
0 commit comments