Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .ocamlformat
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ dock-collection-brackets=false
margin=90
module-item-spacing=sparse
parse-docstrings=false
version=0.27.0
ocaml-version=4.08.0
version=0.28.1
ocaml-version=4.13.0
8 changes: 4 additions & 4 deletions benchmarks/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ end = struct
Sys.readdir dir
|> Array.to_list
|> List.filter ~f:(fun nm ->
let open Unix in
match stat (dir ^ "/" ^ nm) with
| { st_kind = S_REG | S_LNK; _ } -> true
| _ -> false)
let open Unix in
match stat (dir ^ "/" ^ nm) with
| { st_kind = S_REG | S_LNK; _ } -> true
| _ -> false)
|> (if spec.ext = ""
then fun x -> x
else
Expand Down
15 changes: 7 additions & 8 deletions benchmarks/run.ml
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,13 @@ let _ =
| reports ->
List.map reports ~f:read_report_config
|> List.concat_map ~f:(fun l ->
List.concat_map l ~f:(fun l ->
List.concat_map l ~f:(function
| None -> []
| Some (p1, p2, _measure, _) -> (
match String.split_on_char ~sep:'/' p1 with
| [ "results"; "times"; _host; interpreter ] ->
[ interpreter, p2 ]
| _ -> []))))
List.concat_map l ~f:(fun l ->
List.concat_map l ~f:(function
| None -> []
| Some (p1, p2, _measure, _) -> (
match String.split_on_char ~sep:'/' p1 with
| [ "results"; "times"; _host; interpreter ] -> [ interpreter, p2 ]
| _ -> []))))
|> List.sort_uniq ~cmp:compare
|> fun required ->
true, fun (interp, suite) -> List.mem (interp, Spec.name suite) ~set:required
Expand Down
14 changes: 7 additions & 7 deletions compiler/bin-js_of_ocaml/check_runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ open Js_of_ocaml_compiler
let group_by_snd l =
l
|> List.sort_uniq ~cmp:(fun (n1, l1) (n2, l2) ->
match List.compare ~cmp:String.compare l1 l2 with
| 0 -> String.compare n1 n2
| c -> c)
match List.compare ~cmp:String.compare l1 l2 with
| 0 -> String.compare n1 n2
| c -> c)
|> List.group ~f:(fun (_, g1) (_, g2) -> List.equal ~eq:String.equal g1 g2)

let print_groups output l =
Expand Down Expand Up @@ -131,10 +131,10 @@ let f (runtime_files, bytecode, target_env) =
let extra =
extra
|> List.map ~f:(fun name ->
( (name ^ if Linker.deprecated ~name then " (deprecated)" else "")
, match Linker.origin ~name with
| None -> []
| Some x -> [ x ] ))
( (name ^ if Linker.deprecated ~name then " (deprecated)" else "")
, match Linker.origin ~name with
| None -> []
| Some x -> [ x ] ))
|> group_by_snd
in

Expand Down
4 changes: 2 additions & 2 deletions compiler/bin-js_of_ocaml/js_of_ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ let () =
String.length x > 0
&& (not (Char.equal x.[0] '-'))
&& String.for_all x ~f:(function
| 'a' .. 'z' | 'A' .. 'Z' | '-' -> true
| _ -> false)
| 'a' .. 'z' | 'A' .. 'Z' | '-' -> true
| _ -> false)
in
match Array.to_list argv with
| exe :: maybe_command :: rest ->
Expand Down
4 changes: 2 additions & 2 deletions compiler/bin-wasm_of_ocaml/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ let merge_shape a b =
let sexp_of_shapes s =
StringMap.bindings s
|> List.map ~f:(fun (name, shape) ->
Sexp.List [ Atom name; Atom (Shape.to_string shape) ])
Sexp.List [ Atom name; Atom (Shape.to_string shape) ])

let string_of_shapes s = Sexp.List (sexp_of_shapes s) |> Sexp.to_string

Expand Down Expand Up @@ -476,7 +476,7 @@ let run
tmp_wasm_file
|> (fun file -> Link.Wasm_binary.read_imports ~file)
|> List.filter_map ~f:(fun { Link.Wasm_binary.module_; name; _ } ->
if String.equal module_ "js" then Some name else None)
if String.equal module_ "js" then Some name else None)
|> StringSet.of_list
in
let js_runtime = build_js_runtime ~primitives () in
Expand Down
4 changes: 2 additions & 2 deletions compiler/bin-wasm_of_ocaml/wasm_of_ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ let () =
String.length x > 0
&& (not (Char.equal x.[0] '-'))
&& String.for_all x ~f:(function
| 'a' .. 'z' | 'A' .. 'Z' | '-' -> true
| _ -> false)
| 'a' .. 'z' | 'A' .. 'Z' | '-' -> true
| _ -> false)
in
match Array.to_list argv with
| exe :: maybe_command :: rest ->
Expand Down
53 changes: 25 additions & 28 deletions compiler/lib-wasm/link.ml
Original file line number Diff line number Diff line change
Expand Up @@ -357,25 +357,23 @@ let info_from_sexp info =
|> member "units"
|> Option.value ~default:[]
|> List.map ~f:(fun u ->
let unit_info = u |> Unit_info.from_sexp in
let unit_name =
u |> member "name" |> Option.value ~default:[] |> single string
in
let fragments =
u
|> member "fragments"
|> Option.map ~f:(single string)
|> Option.map ~f:(fun s -> Marshal.from_string (Base64.decode_exn s) 0)
|> Option.value ~default:[]
(*
let unit_info = u |> Unit_info.from_sexp in
let unit_name = u |> member "name" |> Option.value ~default:[] |> single string in
let fragments =
u
|> member "fragments"
|> Option.map ~f:(single string)
|> Option.map ~f:(fun s -> Marshal.from_string (Base64.decode_exn s) 0)
|> Option.value ~default:[]
(*
|> to_option to_assoc
|> Option.value ~default:[]
|> List.map ~f:(fun (nm, e) ->
( nm
, let lex = Parse_js.Lexer.of_string (to_string e) in
Parse_js.parse_expr lex ))*)
in
{ unit_name; unit_info; fragments })
in
{ unit_name; unit_info; fragments })
in
build_info, predefined_exceptions, unit_data

Expand Down Expand Up @@ -591,15 +589,15 @@ let link_to_directory ~files_to_link ~files ~enable_source_maps ~dir =
let lst =
List.tl files
|> List.map ~f:(fun (file, _) ->
if StringSet.mem file files_to_link
then (
let z = Zip.open_in file in
let name' = file |> Filename.basename |> Filename.remove_extension in
let ((name', _) as res) = process_file z ~name:"code" ~name' in
if enable_source_maps then extract_source_map ~dir ~name:name' z;
Zip.close_in z;
Some res)
else None)
if StringSet.mem file files_to_link
then (
let z = Zip.open_in file in
let name' = file |> Filename.basename |> Filename.remove_extension in
let ((name', _) as res) = process_file z ~name:"code" ~name' in
if enable_source_maps then extract_source_map ~dir ~name:name' z;
Zip.close_in z;
Some res)
else None)
|> List.filter_map ~f:(fun x -> x)
in
runtime :: prelude :: List.map ~f:fst lst, (runtime_intf, List.map ~f:snd lst)
Expand Down Expand Up @@ -653,10 +651,10 @@ let load_information files =
( predefined_exceptions
, (runtime, (build_info, []))
:: List.map other_files ~f:(fun file ->
let build_info, _predefined_exceptions, unit_data =
Zip.with_open_in file read_info
in
file, (build_info, unit_data)) )
let build_info, _predefined_exceptions, unit_data =
Zip.with_open_in file read_info
in
file, (build_info, unit_data)) )

let remove_directory path =
try
Expand Down Expand Up @@ -801,8 +799,7 @@ let link ~output_file ~linkall ~enable_source_maps ~files =
let generated_js =
List.concat
@@ List.map files ~f:(fun (_, (_, units)) ->
List.map units ~f:(fun { unit_name; fragments; _ } ->
Some unit_name, fragments))
List.map units ~f:(fun { unit_name; fragments; _ } -> Some unit_name, fragments))
in
let runtime_args =
let js =
Expand Down
6 changes: 3 additions & 3 deletions compiler/lib-wasm/wasm_link.ml
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,9 @@ module Read = struct
{ final = f2; supertype = s2; typ = t2 } =
Bool.(f1 = f2)
&& (match s1, s2 with
| Some _, None | None, Some _ -> false
| None, None -> true
| Some i1, Some i2 -> i1 = i2)
| Some _, None | None, Some _ -> false
| None, None -> true
| Some i1, Some i2 -> i1 = i2)
&& comptype_eq t1 t2

let equal t1 t2 =
Expand Down
21 changes: 11 additions & 10 deletions compiler/lib-wasm/wat_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,13 @@ let value_type_list st name tl =

let func_type st ?param_names { params; result } =
(match param_names with
| None -> value_type_list st "param" params
| Some names ->
List.map2
~f:(fun i typ -> List [ Atom "param"; index st.local_names i; value_type st typ ])
names
params)
| None -> value_type_list st "param" params
| Some names ->
List.map2
~f:(fun i typ ->
List [ Atom "param"; index st.local_names i; value_type st typ ])
names
params)
@ value_type_list st "result" result

let storage_type st typ =
Expand Down Expand Up @@ -234,10 +235,10 @@ let export name =

let type_prefix op nm =
(match op with
| I32 _ -> "i32."
| I64 _ -> "i64."
| F32 _ -> "f32."
| F64 _ -> "f64.")
| I32 _ -> "i32."
| I64 _ -> "i64."
| F32 _ -> "f32."
| F64 _ -> "f64.")
^ nm

let signage op (s : Wasm_ast.signage) =
Expand Down
8 changes: 4 additions & 4 deletions compiler/lib/build_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ let parse s =
|> String.split_on_char ~sep:','
|> List.map ~f:String.trim
|> List.map ~f:(fun s ->
match String.lsplit2 ~on:'=' s with
| None -> s, ""
| Some (k, v) -> k, v)
match String.lsplit2 ~on:'=' s with
| None -> s, ""
| Some (k, v) -> k, v)
|> List.fold_left ~init:StringMap.empty ~f:(fun acc (k, v) ->
StringMap.add k v acc)
StringMap.add k v acc)
in
Some t

Expand Down
6 changes: 3 additions & 3 deletions compiler/lib/driver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,9 @@ let optimize ~shapes ~profile ~keep_flow_data p =
Specialize.switches
+> specialize_js_once_before
+> (match (profile : Profile.t) with
| O1 -> o1
| O2 -> o2
| O3 -> o3)
| O1 -> o1
| O2 -> o2
| O3 -> o3)
+> specialize_js_once_after
+> effects_and_exact_calls ~keep_flow_data ~deadcode_sentinal ~shapes profile
+> map_fst5
Expand Down
10 changes: 5 additions & 5 deletions compiler/lib/effects.ml
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ let jump_closures blocks_to_transform idom : jump_closures =
idom_node
((cname, node)
::
(try Addr.Map.find idom_node jc.closures_of_alloc_site
with Not_found -> []))
(try Addr.Map.find idom_node jc.closures_of_alloc_site
with Not_found -> []))
jc.closures_of_alloc_site
})
idom
Expand Down Expand Up @@ -389,9 +389,9 @@ let allocate_continuation ~st ~alloc_jump_closures ~split_closures src_pc x dire
let direct_pc, args = direct_cont in
if
(match args with
| [] -> true
| [ x' ] -> Var.equal x x'
| _ -> false)
| [] -> true
| [ x' ] -> Var.equal x x'
| _ -> false)
&&
match Addr.Hashtbl.find st.is_continuation direct_pc with
| `Param _ -> true
Expand Down
28 changes: 14 additions & 14 deletions compiler/lib/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1805,10 +1805,10 @@ and translate_instrs_rev (ctx : Ctx.t) loc expr_queue instrs acc_rev muts_map =
let muts_map_l =
Code.Var.Set.elements muts
|> List.map ~f:(fun x ->
( x
, match Code.Var.Map.find_opt x old_muts_map with
| None -> Code.Var.fork x
| Some x' -> x' ))
( x
, match Code.Var.Map.find_opt x old_muts_map with
| None -> Code.Var.fork x
| Some x' -> x' ))
in
let muts_map =
List.fold_left muts_map_l ~init:old_muts_map ~f:(fun acc (x, x') ->
Expand Down Expand Up @@ -1980,7 +1980,7 @@ and compile_block_no_loop st loc queue (pc : Addr.t) ~fall_through scope_stack =
Structure.get_edges st.dom pc
|> Addr.Set.elements
|> List.filter ~f:(fun pc' ->
nbbranch pc' >= 2 || Structure.is_merge_node st.structure pc')
nbbranch pc' >= 2 || Structure.is_merge_node st.structure pc')
|> Structure.sort_in_post_order st.structure
in
let rec loop ~scope_stack ~fall_through l =
Expand Down Expand Up @@ -2350,15 +2350,15 @@ let generate_shared_value ctx =
let strings =
( J.variable_declaration
((match ctx.Ctx.exported_runtime with
| None -> []
| Some (_, { contents = false }) -> []
| Some (v, _) ->
[ ( J.V v
, ( J.dot
(s_var Global_constant.global_object)
(Utf8_string.of_string_exn "jsoo_runtime")
, J.U ) )
])
| None -> []
| Some (_, { contents = false }) -> []
| Some (v, _) ->
[ ( J.V v
, ( J.dot
(s_var Global_constant.global_object)
(Utf8_string.of_string_exn "jsoo_runtime")
, J.U ) )
])
@ List.map
(StringMap.bindings ctx.Ctx.share.Share.vars.Share.byte_strings)
~f:(fun (s, v) -> v, (str_js_byte s, J.U))
Expand Down
4 changes: 2 additions & 2 deletions compiler/lib/generate_closure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ let rec rewrite_closures free_pc blocks body : int * _ * _ list =
List.flatten closures
|> List.sort ~cmp:(fun a b -> compare (pos a) (pos b))
|> List.concat_map ~f:(function
| One { code; _ } -> [ code ]
| Wrapper { code; wrapper; _ } -> [ code; wrapper ])
| One { code; _ } -> [ code ]
| Wrapper { code; wrapper; _ } -> [ code; wrapper ])
in
let free_pc, blocks, rem = rewrite_closures free_pc blocks rem in
free_pc, blocks, closures @ rem
Expand Down
24 changes: 12 additions & 12 deletions compiler/lib/inline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,10 @@ let interesting_parameters ~context info =
*)
let functor_like ~context info =
(match Config.target (), context.profile with
| `Wasm, (O2 | O3) -> true
| `Wasm, O1 -> body_size ~context info <= 15
| `JavaScript, (O1 | O2) -> false
| `JavaScript, O3 -> body_size ~context info <= 15)
| `Wasm, (O2 | O3) -> true
| `Wasm, O1 -> body_size ~context info <= 15
| `JavaScript, (O1 | O2) -> false
| `JavaScript, O3 -> body_size ~context info <= 15)
&& (not info.recursive)
&& (not (contains_loop ~context info))
&& returns_a_block ~context info
Expand Down Expand Up @@ -447,14 +447,14 @@ and should_inline ~context info args =
context.enclosing_function]) since this results in significant
performance improvements. *)
(match Config.target (), Config.effects () with
| `JavaScript, (`Disabled | `Cps) ->
closure_count ~context info = 0
|| Option.is_none context.enclosing_function
|| Option.equal Var.equal info.enclosing_function context.current_function
|| (not (Lazy.force !(context.has_closures)))
&& Option.equal Var.equal info.enclosing_function context.enclosing_function
| `Wasm, _ | `JavaScript, `Double_translation -> true
| `JavaScript, `Jspi -> assert false)
| `JavaScript, (`Disabled | `Cps) ->
closure_count ~context info = 0
|| Option.is_none context.enclosing_function
|| Option.equal Var.equal info.enclosing_function context.current_function
|| (not (Lazy.force !(context.has_closures)))
&& Option.equal Var.equal info.enclosing_function context.enclosing_function
| `Wasm, _ | `JavaScript, `Double_translation -> true
| `JavaScript, `Jspi -> assert false)
&& (functor_like ~context info
|| (context.live_vars.(Var.idx info.f) = 1
&&
Expand Down
Loading