Skip to content

Do more aggressive lambda lifting #1886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion compiler/lib/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,33 @@ let link_and_pack ?(standalone = true) ?(wrap_with_fun = `Iife) ?(link = `No) p
|> pack ~wrap_with_fun ~standalone
|> check_js

let all_functions p =
let open Code in
fold_closures
p
(fun name _ _ _ acc ->
match name with
| Some name -> Var.Set.add name acc
| None -> acc)
Var.Set.empty

let effects_or_lambda_lift ~deadcode_sentinal p =
(* If effects are disabled, we lambda-lift aggressively. While not necessary, it results
in a substantial gain in performance for Javascript. *)
match Config.(target (), effects ()) with
| `JavaScript, `Disabled ->
let to_lift = all_functions p in
let p, _ = Lambda_lifting_simple.f ~to_lift p in
( p
, (Code.Var.Set.empty : Effects.trampolined_calls)
, (Code.Var.Set.empty : Effects.in_cps) )
| _, (`Cps | `Double_translation) -> effects ~deadcode_sentinal p
| `Wasm, (`Disabled | `Jspi) ->
( p
, (Code.Var.Set.empty : Effects.trampolined_calls)
, (Code.Var.Set.empty : Effects.in_cps) )
| `JavaScript, `Jspi -> assert false

let optimize ~profile p =
let deadcode_sentinal =
(* If deadcode is disabled, this field is just fresh variable *)
Expand All @@ -687,7 +714,7 @@ let optimize ~profile p =
| O3 -> o3)
+> specialize_js_once_after
+> exact_calls ~deadcode_sentinal profile
+> effects ~deadcode_sentinal
+> effects_or_lambda_lift ~deadcode_sentinal
+> map_fst
(match Config.target (), Config.effects () with
| `JavaScript, `Disabled -> Generate_closure.f
Expand Down
Loading