Skip to content

Commit a734547

Browse files
committed
Compiler: lift some helper to toplevel
1 parent a725b1e commit a734547

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

compiler/lib/generate.ml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,10 @@ type queue_elt =
535535
; deps : Code.Var.Set.t
536536
}
537537

538+
let[@tail_mod_cons] rec clean_queue x = function
539+
| [] -> []
540+
| ((v, _) as hd) :: rem -> if Code.Var.equal v x then rem else hd :: clean_queue x rem
541+
538542
let access_queue ~live queue x =
539543
let idx = Var.idx x in
540544
if idx < Array.length live && Array.unsafe_get live idx = 1
@@ -543,12 +547,7 @@ let access_queue ~live queue x =
543547
List.find_map queue ~f:(fun (x', elt) ->
544548
if Code.Var.equal x x' then Some elt else None)
545549
with
546-
| Some elt ->
547-
let[@tail_mod_cons] rec clean x = function
548-
| [] -> []
549-
| ((v, _) as hd) :: rem -> if Code.Var.equal v x then rem else hd :: clean x rem
550-
in
551-
((elt.prop, elt.deps), elt.ce, elt.loc), clean x queue
550+
| Some elt -> ((elt.prop, elt.deps), elt.ce, elt.loc), clean_queue x queue
552551
| None -> ((fst const_p, Code.Var.Set.singleton x), var x, None), queue
553552
else ((fst const_p, Code.Var.Set.singleton x), var x, None), queue
554553

@@ -1329,6 +1328,16 @@ let remove_unused_tail_args ctx exact trampolined args =
13291328
else args
13301329
else args
13311330

1331+
let keep_name x =
1332+
match Code.Var.get_name x with
1333+
| None -> false
1334+
| Some "" -> false
1335+
| Some s ->
1336+
(* "switcher" is emitted by the OCaml compiler when compiling
1337+
pattern matching, it does not help much to keep it in the
1338+
generated js, let's drop it *)
1339+
(not (generated_name s)) && not (String.starts_with s ~prefix:"jsoo_")
1340+
13321341
let rec translate_expr ctx loc x e level : (_ * J.statement_list) Expr_builder.t =
13331342
let open Expr_builder in
13341343
match e with
@@ -1603,16 +1612,6 @@ and translate_instr ctx expr_queue loc instr =
16031612
return [ J.Expression_statement (J.EBin (J.Eq, J.EVar (J.V x), cy)), loc ])
16041613
| Let (x, e) -> (
16051614
let e' = translate_expr ctx loc x e 0 in
1606-
let keep_name x =
1607-
match Code.Var.get_name x with
1608-
| None -> false
1609-
| Some "" -> false
1610-
| Some s ->
1611-
(* "switcher" is emitted by the OCaml compiler when compiling
1612-
pattern matching, it does not help much to keep it in the
1613-
generated js, let's drop it *)
1614-
(not (generated_name s)) && not (String.starts_with s ~prefix:"jsoo_")
1615-
in
16161615
match ctx.Ctx.live.(Var.idx x), e with
16171616
| 0, _ ->
16181617
(* deadcode is off *)

0 commit comments

Comments
 (0)