Skip to content
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

Effects: double translation of functions and dynamic switching between direct-style and CPS code #1461

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Runtime: reimplement the runtime of weak and ephemeron (#1707)
* Lib: Modify Typed_array API for compatibility with WebAssembly
* Toplevel: no longer set globals for toplevel initialization
* Effects: add an optional feature of "dynamic switching" between CPS and direct style, resulting in better performance when no effect handler is installed

## Bug fixes
* Runtime: fix parsing of unsigned integers (0u2147483648) (#1633, #1666)
Expand Down
9 changes: 6 additions & 3 deletions compiler/lib/build_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ let create kind =
in
[ "use-js-string", string_of_bool (Config.Flag.use_js_string ())
; "effects", string_of_bool (Config.Flag.effects ())
; "doubletranslate", string_of_bool (Config.Flag.double_translation ())
; "version", version
; "kind", string_of_kind kind
]
Expand Down Expand Up @@ -126,9 +127,10 @@ let merge fname1 info1 fname2 info2 =
match k, v1, v2 with
| "kind", v1, v2 ->
if Option.equal String.equal v1 v2 then v1 else Some (string_of_kind `Unknown)
| ("effects" | "use-js-string" | "version"), Some v1, Some v2
| ("effects" | "doubletranslate" | "use-js-string" | "version"), Some v1, Some v2
when String.equal v1 v2 -> Some v1
| (("effects" | "use-js-string" | "version") as key), v1, v2 ->
| (("effects" | "doubletranslate" | "use-js-string" | "version") as key), v1, v2
->
raise
(Incompatible_build_info { key; first = fname1, v1; second = fname2, v2 })
| _, Some v1, Some v2 when String.equal v1 v2 -> Some v1
Expand All @@ -143,6 +145,7 @@ let configure t =
StringMap.iter
(fun k v ->
match k with
| "use-js-string" | "effects" -> Config.Flag.set k (bool_of_string v)
| "use-js-string" | "effects" | "doubletranslate" ->
Config.Flag.set k (bool_of_string v)
| _ -> ())
t
4 changes: 4 additions & 0 deletions compiler/lib/code.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ module Var : sig

val set : 'a t -> key -> 'a -> unit

val length : 'a t -> int

val make : size -> 'a -> 'a t

val make_set : size -> 'a DataSet.t t
Expand Down Expand Up @@ -227,6 +229,8 @@ end = struct

let set t x v = t.(x) <- v

let length t = Array.length t

let make () v = Array.make (count ()) v

let make_set () = Array.make (count ()) DataSet.Empty
Expand Down
2 changes: 2 additions & 0 deletions compiler/lib/code.mli
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ module Var : sig

val set : 'a t -> key -> 'a -> unit

val length : 'a t -> int

val make : size -> 'a -> 'a t

val make_set : size -> 'a DataSet.t t
Expand Down
2 changes: 2 additions & 0 deletions compiler/lib/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ module Flag = struct

let effects = o ~name:"effects" ~default:false

let double_translation = o ~name:"doubletranslate" ~default:false

let staticeval = o ~name:"staticeval" ~default:true

let share_constant = o ~name:"share" ~default:true
Expand Down
2 changes: 2 additions & 0 deletions compiler/lib/config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ module Flag : sig

val effects : unit -> bool

val double_translation : unit -> bool

val genprim : unit -> bool

val strictmode : unit -> bool
Expand Down
9 changes: 6 additions & 3 deletions compiler/lib/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ let effects ~deadcode_sentinal p =
Deadcode.f p
else p, live_vars
in
p |> Effects.f ~flow_info:info ~live_vars +> map_fst Lambda_lifting.f)
let p, trampolined_calls, in_cps = Effects.f ~flow_info:info ~live_vars p in
let p = if Config.Flag.double_translation () then p else Lambda_lifting.f p in
p, trampolined_calls, in_cps)
Comment on lines +115 to +117
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let p, trampolined_calls, in_cps = Effects.f ~flow_info:info ~live_vars p in
let p = if Config.Flag.double_translation () then p else Lambda_lifting.f p in
p, trampolined_calls, in_cps)
p
|> Effects.f ~flow_info:info ~live_vars
|> map_fst (if Config.Flag.double_translation () then Fun.id else Lambda_lifting.f))

else
( p
, (Code.Var.Set.empty : Effects.trampolined_calls)
, (Code.Var.Set.empty : Effects.in_cps) )
, (Code.Var.Set.empty : Code.Var.Set.t) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
, (Code.Var.Set.empty : Code.Var.Set.t) )
, (Code.Var.Set.empty : Effects.in_cps) )


let exact_calls profile ~deadcode_sentinal p =
if not (Config.Flag.effects ())
Expand Down Expand Up @@ -202,14 +204,15 @@ let generate
~exported_runtime
~wrap_with_fun
~warn_on_unhandled_effect
{ program; variable_uses; trampolined_calls; deadcode_sentinal; in_cps = _ } =
{ program; variable_uses; trampolined_calls; deadcode_sentinal; in_cps } =
if times () then Format.eprintf "Start Generation...@.";
let should_export = should_export wrap_with_fun in
Generate.f
program
~exported_runtime
~live_vars:variable_uses
~trampolined_calls
~in_cps
~should_export
~warn_on_unhandled_effect
~deadcode_sentinal
Expand Down
Loading