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

[Not for merge] Optim effects optional #2

Closed
wants to merge 75 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
7de742a
Upgrade to OCamlformat 0.26.0
Julow Jul 20, 2023
fdbf60c
Update .git-blame-ignore-revs
Julow Jul 20, 2023
fa95589
fixup! Update .git-blame-ignore-revs
hhugo Jul 21, 2023
d276707
CI: stop relying on custom zarith pin (#1490)
hhugo Jul 21, 2023
0df7260
Misc: no backgroud digest (#1491)
hhugo Jul 21, 2023
8cd97dc
Fix caml_js_on_ie (#1493)
vouillon Jul 26, 2023
d4c2f9f
Bug in global flow analysis: add regression test
vouillon Jul 27, 2023
b510cae
Fix global flow analysis
vouillon Jul 26, 2023
f5688f3
CI: reenable background digest
hhugo Aug 1, 2023
98f2296
Compiler: remove DTree.empty
hhugo Aug 2, 2023
f8eef41
Compiler: simplify Dtree.t
hhugo Aug 2, 2023
3ddba6b
Compiler: more debug in compile_decision_tree
hhugo Aug 2, 2023
29c693b
Compiler: refactor control flow compilation
hhugo Jul 25, 2023
0eaf3f7
Compiler: improve dominator tree for try-catch
hhugo Aug 1, 2023
7b6f4bd
Compiler: structure, not need to recompute the whole preds
hhugo Aug 3, 2023
559f0d7
Test: test static evaluation of switches
hhugo Jul 31, 2023
25fbbf7
Compiler: lower level switch
hhugo Jul 27, 2023
2b429e5
Compiler: minify labels
hhugo Aug 3, 2023
779b5a8
Add download attribute to anchor element
slegrand45 Sep 3, 2023
2d765db
Update changelog
slegrand45 Sep 3, 2023
298bf95
Remove spurious newline when outputing uncaught exception
vouillon Sep 14, 2023
170d15e
Dead code elimination of some unused references
vouillon Sep 7, 2023
9386787
Float conversion functions are no longer deprecated
vouillon Jun 2, 2023
f782826
Explicit conversions between Javascript Numbers and OCaml int32 and n…
vouillon Jul 6, 2023
15e8cf9
JavaScript bindings: expose equality functions
vouillon Jun 21, 2023
af7f053
Add type Js.number_t to stand for JavaScript numbers
vouillon Jul 26, 2023
8e14515
Add explicit float conversions
vouillon Jul 26, 2023
96bb9e6
No longer use physical equality to compare JavaScript values
vouillon Jul 26, 2023
d352ae6
Changes
vouillon Jul 25, 2023
35dcf07
Misc: switch to ocaml.5.01 (#1506)
hhugo Sep 26, 2023
10fb95e
Compiler: remove raw crlf in string literal
hhugo Sep 28, 2023
d7ba263
Dynlink: prepare for ocaml 5.2
hhugo Sep 28, 2023
867b72c
Compiler: prepare for 5.2
hhugo Sep 28, 2023
8a88cc4
Runtime: update for ocaml 5.2
hhugo Sep 28, 2023
e1433ee
Tests: make toplevel expect test more robust wrt newlines
hhugo Sep 28, 2023
a6a1c26
Tests: fix stdlib output for 5.1
hhugo Sep 28, 2023
29cc16f
Tests: promote
hhugo Sep 28, 2023
ce48f23
Changes
hhugo Sep 28, 2023
912da9a
driver.ml: Fix call to Effects.f
OlivierNicole Mar 9, 2023
d0c9b3c
effects.ml[i]: Enrich types as needed and add comments
OlivierNicole Mar 9, 2023
587aa14
Mark single_version_closures in cps_branch and cps_last
OlivierNicole Mar 9, 2023
6f22242
effect.js: Add comment about single-versionness of exn handlers
OlivierNicole Mar 9, 2023
5661223
effects.ml: Comment impossible case
OlivierNicole Mar 9, 2023
316a318
Make the CPS transform perform dynamic switching
OlivierNicole Mar 22, 2023
3cb5875
Update runtime files for closure pairs
OlivierNicole Mar 24, 2023
8de46b0
Debug transform, turn pairs into function object with .cps field
OlivierNicole Apr 4, 2023
6f7120e
Effects: Debug jumps in CPS blocks
OlivierNicole Apr 5, 2023
cf4cf0d
Fix typos in comment
OlivierNicole Apr 7, 2023
bad0163
Add caml_cps_closure primitive
OlivierNicole Apr 7, 2023
ce4081a
Fix jump targets and substitution bugs
OlivierNicole Apr 14, 2023
bbcc037
Fix CPS application function and reformat generate.ml
OlivierNicole Apr 21, 2023
1691d4a
Fix remaining bugs in CPS transform and effect handling
OlivierNicole Apr 21, 2023
b8a0fe8
Effects: cleaner and efficient substitutions
OlivierNicole Apr 28, 2023
4ea6868
Rectify some outdated comments
OlivierNicole Apr 28, 2023
8dda7ad
Remove some dead code and debug printing
OlivierNicole Apr 28, 2023
a364c91
Update changelog
OlivierNicole May 17, 2023
2f997a1
Remove leftover debugging change
OlivierNicole May 22, 2023
8b09b2b
Reimplement Array.fold_left_map
OlivierNicole May 22, 2023
ab1f636
Make double translation optional (untested yet)
OlivierNicole Jul 26, 2023
52daac5
Fix doubletranslate flag name
OlivierNicole Aug 25, 2023
f2c5b84
Add linker condition doubletranslate
OlivierNicole Aug 25, 2023
70f84b3
Partly re-apply changes to runtime
OlivierNicole Aug 25, 2023
c51f9bd
Adapt runtime for optional double translation
OlivierNicole Aug 25, 2023
9ce5a95
Fix buggy order in pattern matching
OlivierNicole Sep 6, 2023
c47995f
When not double-translating, mark all functions as single-version
OlivierNicole Sep 6, 2023
406d65d
Add comment and ocamlformat
OlivierNicole Sep 6, 2023
5828438
Fix two bugs in CPS transform and JS generation
OlivierNicole Sep 15, 2023
013275a
ocamlformat
OlivierNicole Sep 15, 2023
891bc6f
Fix two bugs
OlivierNicole Sep 19, 2023
71e4ff0
Stop doing incorrect substitutions when not double translating
OlivierNicole Sep 27, 2023
7fa8aa0
Restore use of caml_callback on toplevel when needed
OlivierNicole Sep 28, 2023
2360daa
Start adding tests for double translation
OlivierNicole Sep 20, 2023
c46c0bc
[Probably overkill] Add functional tests for double translation
OlivierNicole Sep 28, 2023
d3b4189
[PROBABLY INCORRECT] Promote tests to account for variable renamings
OlivierNicole Sep 28, 2023
7beefaf
Remove unused argument
OlivierNicole Sep 28, 2023
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
4 changes: 3 additions & 1 deletion .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# ocamlformat bump
3c98cd3e0c4e1191983b602a8e38a1c92d259891
3c98cd3e0c4e1191983b602a8e38a1c92d259891
# Upgrade to OCamlformat 0.26.0
7de742a776fcdad4b098695617b9e7afab822c82
14 changes: 6 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ jobs:
- 4.11.x
- 4.12.x
- 4.13.x
- 5.0.x
skip-test:
- true
skip-doc:
Expand All @@ -46,17 +47,17 @@ jobs:
skip-test: false
skip-doc: true
- os: ubuntu-latest
ocaml-compiler: 5.0.x
ocaml-compiler: 5.1.x
skip-effects: false
skip-test: false
skip-doc: false
- os: macos-latest
ocaml-compiler: 5.0.x
ocaml-compiler: 5.1.x
skip-effects: true
skip-test: false
skip-doc: true
- os: windows-latest
ocaml-compiler: ocaml.5.0.0,ocaml-option-mingw
ocaml-compiler: ocaml.5.1.0,ocaml-option-mingw
skip-effects: false
skip-test: false
skip-doc: true
Expand Down Expand Up @@ -85,7 +86,7 @@ jobs:
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
opam-repositories: |
dra27: https://github.com/dra27/opam-repository.git#windows-5.0
dra27: https://github.com/hhugo/opam-repository.git#for-jsoo-ci-windows
default: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset
opam: https://github.com/ocaml/opam-repository.git
dune-cache: true
Expand All @@ -97,13 +98,10 @@ jobs:
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
dune-cache: ${{ matrix.os != 'macos-latest' }}
dune-cache: true
opam-depext: ${{ !matrix.skip-test }}
opam-depext-flags: --with-test

- run: opam pin add zarith git+https://github.com/hhugo/Zarith.git#win-fix
if: runner.os == 'Windows'

- run: opam install . --best-effort
if: ${{ matrix.skip-test }}

Expand Down
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ break-separators=before
dock-collection-brackets=false
margin=90
module-item-spacing=sparse
version=0.25.1
version=0.26.0
ocaml-version=4.08.0
15 changes: 15 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Dev (2023-??-??) - ??

## Features/Changes
* Compiler: change control-flow compilation strategy (#1496)
* Lib: add download attribute to anchor element
* Dead code elimination of unused references (#2076)
* Misc: switch CI to OCaml 5.1
* Misc: preliminary support for OCaml 5.2
* Effects: add an optional feature of "dynamic switching" between CPS and direct style, resulting in much better performance when no effect handler is installed

## Bug fixes
* Runtime: fix Dom_html.onIE (#1493)
* Compiler: fix global flow analysis (#1494)
* Runtime: add conversion functions + strict equality for compatibility with Wasm_of_ocaml (#1492)

# 5.4.0 (2023-07-06) - Lille

## Bug fixes
Expand Down
3 changes: 1 addition & 2 deletions compiler/lib-dynlink/js_of_ocaml_compiler_dynlink.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ let () =
Config.Flag.set "use-js-string" (Jsoo_runtime.Sys.Config.use_js_string ());
Config.Flag.set "effects" (Jsoo_runtime.Sys.Config.effects ());
(* this needs to stay synchronized with toplevel.js *)
let toplevel_compile (s : bytes array) (debug : Instruct.debug_event list array) :
let toplevel_compile (s : string) (debug : Instruct.debug_event list array) :
unit -> J.t =
let s = String.concat ~sep:"" (List.map ~f:Bytes.to_string (Array.to_list s)) in
let prims = split_primitives (Symtable.data_primitive_names ()) in
let b = Buffer.create 100 in
let fmt = Pretty_print.to_buffer b in
Expand Down
2 changes: 1 addition & 1 deletion compiler/lib-runtime-files/gen/gen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ let () =
let %s = Js_of_ocaml_compiler.Builtins.register
~name:%S
~content:{frag|%s|frag}
~fragments:(Some {frag|%s|frag})
~fragments:(Some %S)
|}
(to_ident (Filename.chop_extension name))
name
Expand Down
2 changes: 1 addition & 1 deletion compiler/lib/base64.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let unsafe_get_uint8 t off = Char.code (String.unsafe_get t off)
let unsafe_set_uint8 t off v = Bytes.unsafe_set t off (Char.chr v)

external unsafe_set_uint16 : bytes -> int -> int -> unit = "%caml_bytes_set16u"
[@@noalloc]
[@@noalloc]

external unsafe_get_uint16 : string -> int -> int = "%caml_string_get16u" [@@noalloc]

Expand Down
16 changes: 8 additions & 8 deletions compiler/lib/code.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ module Var : sig

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

val length : 'a t -> int

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

val iter : (key -> 'a -> unit) -> 'a t -> unit
Expand Down Expand Up @@ -212,6 +214,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 iter f t =
Expand Down Expand Up @@ -354,7 +358,7 @@ type last =
| Stop
| Branch of cont
| Cond of Var.t * cont * cont
| Switch of Var.t * cont array * cont array
| Switch of Var.t * cont array
| Pushtrap of cont * Var.t * cont * Addr.Set.t
| Poptrap of cont

Expand Down Expand Up @@ -499,10 +503,9 @@ module Print = struct
| Branch c -> Format.fprintf f "branch %a" cont c
| Cond (x, cont1, cont2) ->
Format.fprintf f "if %a then %a else %a" Var.print x cont cont1 cont cont2
| Switch (x, a1, a2) ->
| Switch (x, a1) ->
Format.fprintf f "switch %a {" Var.print x;
Array.iteri a1 ~f:(fun i c -> Format.fprintf f "int %d -> %a; " i cont c);
Array.iteri a2 ~f:(fun i c -> Format.fprintf f "tag %d -> %a; " i cont c);
Format.fprintf f "}"
| Pushtrap (cont1, x, cont2, pcs) ->
Format.fprintf
Expand Down Expand Up @@ -598,9 +601,8 @@ let fold_children blocks pc f accu =
let accu = f pc1 accu in
let accu = f pc2 accu in
accu
| Switch (_, a1, a2) ->
| Switch (_, a1) ->
let accu = Array.fold_right ~init:accu ~f:(fun (pc, _) accu -> f pc accu) a1 in
let accu = Array.fold_right ~init:accu ~f:(fun (pc, _) accu -> f pc accu) a2 in
accu

type 'c fold_blocs = block Addr.Map.t -> Addr.t -> (Addr.t -> 'c -> 'c) -> 'c -> 'c
Expand Down Expand Up @@ -726,9 +728,7 @@ let invariant { blocks; start; _ } =
| Cond (_x, cont1, cont2) ->
check_cont cont1;
check_cont cont2
| Switch (_x, a1, a2) ->
Array.iteri a1 ~f:(fun _ cont -> check_cont cont);
Array.iteri a2 ~f:(fun _ cont -> check_cont cont)
| Switch (_x, a1) -> Array.iteri a1 ~f:(fun _ cont -> check_cont cont)
| Pushtrap (cont1, _x, cont2, _pcs) ->
check_cont cont1;
check_cont cont2
Expand Down
4 changes: 3 additions & 1 deletion compiler/lib/code.mli
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ module Var : sig

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

val length : 'a t -> int

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

val iter : (key -> 'a -> unit) -> 'a t -> unit
Expand Down Expand Up @@ -201,7 +203,7 @@ type last =
| Stop
| Branch of cont
| Cond of Var.t * cont * cont
| Switch of Var.t * cont array * cont array
| Switch of Var.t * cont array
| Pushtrap of cont * Var.t * cont * Addr.Set.t
| Poptrap of cont

Expand Down
2 changes: 2 additions & 0 deletions compiler/lib/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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 @@ -39,6 +39,8 @@ module Flag : sig

val effects : unit -> bool

val double_translation : unit -> bool

val genprim : unit -> bool

val strictmode : unit -> bool
Expand Down
50 changes: 27 additions & 23 deletions compiler/lib/deadcode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ open Code
type def =
| Expr of expr
| Var of Var.t
| Field_update of Var.t

let add_def defs x i =
let idx = Var.idx x in
defs.(idx) <- i :: defs.(idx)

type variable_uses = int array

Expand All @@ -48,11 +53,15 @@ let pure_expr pure_funs e = Pure_fun.pure_expr pure_funs e && Config.Flag.deadco
let rec mark_var st x =
let x = Var.idx x in
st.live.(x) <- st.live.(x) + 1;
if st.live.(x) = 1 then List.iter st.defs.(x) ~f:(fun e -> mark_def st e)
if st.live.(x) = 1 then List.iter st.defs.(x) ~f:(fun e -> mark_def st x e)

and mark_def st d =
and mark_def st x d =
match d with
| Var x -> mark_var st x
| Var y -> mark_var st y
| Field_update y ->
(* A [Set_field (x, _, y)] becomes live *)
st.live.(x) <- st.live.(x) + 1;
mark_var st y
| Expr e -> if pure_expr st.pure_funs e then mark_expr st e

and mark_expr st e =
Expand Down Expand Up @@ -81,9 +90,14 @@ and mark_reachable st pc =
match i with
| Let (_, e) -> if not (pure_expr st.pure_funs e) then mark_expr st e
| Assign _ -> ()
| Set_field (x, _, y) ->
mark_var st x;
mark_var st y
| Set_field (x, _, y) -> (
match st.defs.(Var.idx x) with
| [ Expr (Block _) ] when st.live.(Var.idx x) = 0 ->
(* We will keep this instruction only if x is live *)
add_def st.defs x (Field_update y)
| _ ->
mark_var st x;
mark_var st y)
| Array_set (x, y, z) ->
mark_var st x;
mark_var st y;
Expand All @@ -97,10 +111,9 @@ and mark_reachable st pc =
mark_var st x;
mark_cont_reachable st cont1;
mark_cont_reachable st cont2
| Switch (x, a1, a2) ->
| Switch (x, a1) ->
mark_var st x;
Array.iter a1 ~f:(fun cont -> mark_cont_reachable st cont);
Array.iter a2 ~f:(fun cont -> mark_cont_reachable st cont)
Array.iter a1 ~f:(fun cont -> mark_cont_reachable st cont)
| Pushtrap (cont1, _, cont2, _) ->
mark_cont_reachable st cont1;
mark_cont_reachable st cont2)
Expand All @@ -110,8 +123,8 @@ and mark_reachable st pc =
let live_instr st i =
match i with
| Let (x, e) -> st.live.(Var.idx x) > 0 || not (pure_expr st.pure_funs e)
| Assign (x, _) -> st.live.(Var.idx x) > 0
| Set_field _ | Offset_ref _ | Array_set _ -> true
| Assign (x, _) | Set_field (x, _, _) -> st.live.(Var.idx x) > 0
| Offset_ref _ | Array_set _ -> true

let rec filter_args st pl al =
match pl, al with
Expand All @@ -136,11 +149,8 @@ let filter_live_last blocks st (l, loc) =
| Branch cont -> Branch (filter_cont blocks st cont)
| Cond (x, cont1, cont2) ->
Cond (x, filter_cont blocks st cont1, filter_cont blocks st cont2)
| Switch (x, a1, a2) ->
Switch
( x
, Array.map a1 ~f:(fun cont -> filter_cont blocks st cont)
, Array.map a2 ~f:(fun cont -> filter_cont blocks st cont) )
| Switch (x, a1) ->
Switch (x, Array.map a1 ~f:(fun cont -> filter_cont blocks st cont))
| Pushtrap (cont1, x, cont2, pcs) ->
Pushtrap
( filter_cont blocks st cont1
Expand Down Expand Up @@ -169,10 +179,6 @@ let annot st pc xi =

(****)

let add_def defs x i =
let idx = Var.idx x in
defs.(idx) <- i :: defs.(idx)

let rec add_arg_dep defs params args =
match params, args with
| x :: params, y :: args ->
Expand Down Expand Up @@ -204,9 +210,7 @@ let f ({ blocks; _ } as p : Code.program) =
| Cond (_, cont1, cont2) ->
add_cont_dep blocks defs cont1;
add_cont_dep blocks defs cont2
| Switch (_, a1, a2) ->
Array.iter a1 ~f:(fun cont -> add_cont_dep blocks defs cont);
Array.iter a2 ~f:(fun cont -> add_cont_dep blocks defs cont)
| Switch (_, a1) -> Array.iter a1 ~f:(fun cont -> add_cont_dep blocks defs cont)
| Pushtrap (cont, _, cont_h, _) ->
add_cont_dep blocks defs cont_h;
add_cont_dep blocks defs cont
Expand Down
22 changes: 12 additions & 10 deletions compiler/lib/dgraph.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
*)
open! Stdlib

module Make (N : sig
type t
end)
(NSet : Set.S with type elt = N.t)
(NMap : Map.S with type key = N.t) =
module Make
(N : sig
type t
end)
(NSet : Set.S with type elt = N.t)
(NMap : Map.S with type key = N.t) =
struct
type t =
{ domain : NSet.t
Expand Down Expand Up @@ -175,11 +176,12 @@ module type Tbl = sig
val make : size -> 'a -> 'a t
end

module Make_Imperative (N : sig
type t
end)
(NSet : ISet with type elt = N.t)
(NTbl : Tbl with type key = N.t) =
module Make_Imperative
(N : sig
type t
end)
(NSet : ISet with type elt = N.t)
(NTbl : Tbl with type key = N.t) =
struct
type t =
{ domain : NSet.t
Expand Down
22 changes: 12 additions & 10 deletions compiler/lib/dgraph.mli
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)
module Make (N : sig
type t
end)
(NSet : Set.S with type elt = N.t)
(NMap : Map.S with type key = N.t) : sig
module Make
(N : sig
type t
end)
(NSet : Set.S with type elt = N.t)
(NMap : Map.S with type key = N.t) : sig
type t =
{ domain : NSet.t
; fold_children : 'a. (N.t -> 'a -> 'a) -> N.t -> 'a -> 'a
Expand Down Expand Up @@ -72,11 +73,12 @@ module type Tbl = sig
val make : size -> 'a -> 'a t
end

module Make_Imperative (N : sig
type t
end)
(NSet : ISet with type elt = N.t)
(NTbl : Tbl with type key = N.t) : sig
module Make_Imperative
(N : sig
type t
end)
(NSet : ISet with type elt = N.t)
(NTbl : Tbl with type key = N.t) : sig
type t =
{ domain : NSet.t
; iter_children : (N.t -> unit) -> N.t -> unit
Expand Down
Loading
Loading