Skip to content

Commit 7b64a79

Browse files
committed
WIP
1 parent e4de011 commit 7b64a79

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

compiler/lib/inline.ml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ let rec block_size ~recurse ~env p { branch; body; _ } =
108108
body
109109
+
110110
match branch with
111-
| Cond _ -> 2
111+
| Cond _ | Raise _ -> 2
112112
| Switch (_, a1) -> Array.length a1
113113
| _ -> 0
114114

@@ -143,7 +143,7 @@ let count_init_code info =
143143
List.fold_left
144144
~f:(fun n i ->
145145
match i with
146-
| Let (_, (Closure _ | Field _ | Constant _ | Block _)) -> n + 1
146+
| Let (_, (Closure _ | Field (_, _, Non_float) | Constant _ | Block _)) -> n + 1
147147
| _ -> n)
148148
~init:0
149149
body)
@@ -246,19 +246,19 @@ let rec small_function ~live_vars ~env p ~enclosing_function info args =
246246
and should_inline ~live_vars ~env p ~enclosing_function info args =
247247
(* Don't inline function containing closures in JavaScript, except
248248
in an enclosing scope, since this can results in memory leaks *)
249-
(match Config.target () with
250-
| `Wasm -> true
251-
| `JavaScript -> (
252-
match enclosing_function with
253-
| Some f -> Var.Set.mem f info.scopes || closure_count info ~env p = 0
254-
| None -> true))
255-
&& ((live_vars.(Var.idx info.f) = 1 && body_size info ~env p < 150)
256-
|| functor_like ~env p info
257-
|| (body_size info ~env p <= 1 && closure_count info ~env p = 0)
258-
|| small_function ~live_vars ~env p ~enclosing_function info args
259-
&&
260-
(* Avoid inlining loops at toplevel *)
261-
not (Option.is_none enclosing_function && contains_loop info p))
249+
functor_like ~env p info
250+
|| (match Config.target () with
251+
| `Wasm -> true
252+
| `JavaScript -> (
253+
match enclosing_function with
254+
| Some f -> Var.Set.mem f info.scopes || closure_count info ~env p = 0
255+
| None -> true))
256+
&& ((live_vars.(Var.idx info.f) = 1 && body_size info ~env p < 100)
257+
|| (body_size info ~env p <= 1 && closure_count info ~env p = 0)
258+
|| small_function ~live_vars ~env p ~enclosing_function info args
259+
&&
260+
(* Avoid inlining loops at toplevel *)
261+
not (Option.is_none enclosing_function && contains_loop info p))
262262

263263
(****)
264264

compiler/lib/js_traverse.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,7 @@ class simpl =
17111711
match e2, e1 with
17121712
| ENum n, _ when Num.is_neg n -> EBin (Plus, e1, ENum (Num.neg n))
17131713
| (ENum _ as x), ENum zero when is_zero zero -> x
1714+
(* | ENum zero, (ENum _ as x) when is_zero zero -> x*)
17141715
| _ -> e)
17151716
| EFun
17161717
(None, (({ generator = false; async = true | false }, _, body, _) as fun_decl))

0 commit comments

Comments
 (0)