Skip to content

Commit 734dceb

Browse files
authored
Merge pull request #96 from ocaml-wasm/targetint
Get latest changes from js_of_ocaml
2 parents ef0be34 + bcc399f commit 734dceb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1236
-616
lines changed

.github/workflows/build.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ jobs:
3737
skip-effects: true
3838
skip-test: false
3939
skip-doc: true
40+
- os: ubuntu-latest
41+
ocaml-compiler: "ocaml-variants.4.14.2+options,ocaml-option-32bit"
42+
skip-effects: true
43+
skip-test: false
44+
skip-doc: true
4045
- os: macos-latest
4146
ocaml-compiler: "4.14"
4247
skip-effects: true
@@ -73,6 +78,19 @@ jobs:
7378
git config --global core.eol lf
7479
git config --global core.ignorecase false
7580
81+
# EJGA: Note that I tried to fix this upstream as depext is
82+
# getting much better, but no luck yet, c.f:
83+
# https://github.com/ocaml/opam-repository/pull/26626
84+
- name: Install apt 32-bit dependencies
85+
if: matrix.ocaml-compiler == 'ocaml-variants.4.14.2+options,ocaml-option-32bit'
86+
run: |
87+
sudo apt-get install aptitude
88+
sudo dpkg --add-architecture i386
89+
sudo aptitude -o Acquire::Retries=30 update -q
90+
# Note we also install the 64-bit versions here as opam will
91+
# try to install them anyways, so we save an apt-roundtrip.
92+
sudo aptitude -o Acquire::Retries=30 install gcc-multilib g++-multilib pkg-config libgmp-dev libgmp-dev:i386 libx11-dev:i386 -y
93+
7694
- name: Checkout tree
7795
uses: actions/checkout@v4
7896

CHANGES.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@
66
* Misc: yojson is no longer optional
77
* Misc: reduce the diff with the wasm_of_ocaml fork
88
* Compiler: speedup global_flow/global_deadcode pass on large bytecode
9+
* Compiler: improved global dead code elimination (#2206)
910
* Compiler: speedup json parsing, relying on Yojson.Raw (#1640)
1011
* Compiler: Decode sourcemap mappings only when necessary (#1664)
1112
* Compiler: make indirect call using sequence instead of using the call method
1213
[f.call(null, args)] becomes [(0,f)(args)]
1314
* Compiler: mark [TextEncoder] as reserved
15+
* Compiler: add support for the Wasm backend in parts of the pipeline, in
16+
prevision for the merge of wasm_of_ocaml
17+
* Compiler: introduce a Targetint module
18+
that follows the semantic of the backend (js or wasm)
19+
* Compiler: warn on joo_global_object
1420
* Runtime: change Sys.os_type on windows (Cygwin -> Win32)
1521
* Runtime: backtraces are really expensive, they need to be be explicitly
1622
requested at compile time (--enable with-js-error) or at startup (OCAMLRUNPARAM=b=1)
1723
* Runtime: allow dynlink of precompiled js with separate compilation (#1676)
1824
* Lib: Modify Typed_array API for compatibility with WebAssembly
19-
* Compiler: improved global dead code elimination (#2206)
20-
* Compiler: add support for the Wasm backend in parts of the pipeline, in
21-
prevision for the merge of wasm_of_ocaml
2225

2326

2427
## Bug fixes

benchmarks/sources/ml/splay.ml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,24 @@ let rec generatePayloadTree depth tag =
186186

187187
let random =
188188
let seed = ref 49734321 in
189+
let mask_32bit =
190+
match Sys.int_size with
191+
| 31 | 32 -> -1
192+
| _ -> int_of_string "0xffffffff"
193+
in
194+
let l_0xc761c23c = int_of_string "0xc761c23c" in
195+
let l_0xd3a2646c = int_of_string "0xd3a2646c" in
196+
let l_0xfd7046c5 = int_of_string "0xfd7046c5" in
197+
let l_0xb55a4f09 = int_of_string "0xb55a4f09" in
189198
fun () ->
190199
(* // Robert Jenkins' 32 bit integer hash function. *)
191200
let s = !seed in
192-
let s = (s + 0x7ed55d16 + (s lsl 12)) land 0xffffffff in
193-
let s = s lxor 0xc761c23c lxor (s lsr 19) in
201+
let s = (s + 0x7ed55d16 + (s lsl 12)) land mask_32bit in
202+
let s = s lxor l_0xc761c23c lxor (s lsr 19) in
194203
let s = s + 0x165667b1 + (s lsl 5) in
195-
let s = (s + 0xd3a2646c) lxor (s lsl 9) in
196-
let s = (s + 0xfd7046c5 + (s lsl 3)) land 0xffffffff in
197-
let s = s lxor 0xb55a4f09 lxor (s lsr 16) in
204+
let s = (s + l_0xd3a2646c) lxor (s lsl 9) in
205+
let s = (s + l_0xfd7046c5 + (s lsl 3)) land mask_32bit in
206+
let s = s lxor l_0xb55a4f09 lxor (s lsr 16) in
198207
seed := s;
199208
float (s land 0xfffffff) /. float 0x10000000
200209

compiler/bin-js_of_ocaml/build_fs.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function jsoo_create_file_extern(name,content){
6161
}
6262
|}
6363
in
64+
Config.set_target `JavaScript;
6465
let fragments = Linker.Fragment.parse_string code in
6566
Linker.load_fragments ~target_env:Isomorphic ~filename:"<dummy>" fragments;
6667
Linker.check_deps ();

compiler/bin-js_of_ocaml/js_of_ocaml.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ let () =
109109
comp;
110110
exit 1
111111
| Failure s ->
112+
let backtrace = Printexc.get_backtrace () in
112113
Format.eprintf "%s: Error: %s@." Sys.argv.(0) s;
114+
prerr_string backtrace;
113115
exit 1
114116
| exc ->
115117
let backtrace = Printexc.get_backtrace () in

compiler/bin-wasm_of_ocaml/link.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ let options =
7979
Term.ret t
8080

8181
let f { common; output_file; files; linkall; enable_source_maps; mklib } =
82+
Js_of_ocaml_compiler.Config.set_target `Wasm;
8283
Jsoo_cmdline.Arg.eval common;
8384
Wa_link.link ~output_file ~linkall ~mklib ~enable_source_maps ~files
8485

compiler/lib/code.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ type constant =
327327
| NativeString of Native_string.t
328328
| Float of float
329329
| Float_array of float array
330-
| Int of Int32.t
330+
| Int of Targetint.t
331331
| Int32 of Int32.t
332332
| Int64 of Int64.t
333333
| NativeInt of Int32.t (* Native int are 32bit on all known backend *)
@@ -352,7 +352,8 @@ module Constant = struct
352352
| Some s, Some c -> same := Some (s && c)
353353
done;
354354
!same
355-
| Int a, Int b | Int32 a, Int32 b -> Some (Int32.equal a b)
355+
| Int a, Int b -> Some (Targetint.equal a b)
356+
| Int32 a, Int32 b -> Some (Int32.equal a b)
356357
| Int64 a, Int64 b -> Some (Int64.equal a b)
357358
| NativeInt a, NativeInt b -> Some (Int32.equal a b)
358359
| Float_array a, Float_array b -> Some (Array.equal Float.ieee_equal a b)
@@ -497,7 +498,7 @@ module Print = struct
497498
Format.fprintf f "%.12g" a.(i)
498499
done;
499500
Format.fprintf f "|]"
500-
| Int i -> Format.fprintf f "%ld" i
501+
| Int i -> Format.fprintf f "%s" (Targetint.to_string i)
501502
| Int32 i -> Format.fprintf f "%ldl" i
502503
| Int64 i -> Format.fprintf f "%LdL" i
503504
| NativeInt i -> Format.fprintf f "%ldn" i

compiler/lib/code.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ type constant =
173173
| NativeString of Native_string.t
174174
| Float of float
175175
| Float_array of float array
176-
| Int of Int32.t
176+
| Int of Targetint.t
177177
| Int32 of Int32.t (** Only produced when compiling to WebAssembly. *)
178178
| Int64 of Int64.t
179179
| NativeInt of Int32.t (** Only produced when compiling to WebAssembly. *)

compiler/lib/config.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,7 @@ let target () =
191191
| (`JavaScript | `Wasm) as t -> t
192192

193193
let set_target (t : [ `JavaScript | `Wasm ]) =
194+
(match t with
195+
| `JavaScript -> Targetint.set_num_bits 32
196+
| `Wasm -> Targetint.set_num_bits 31);
194197
target_ := (t :> [ `JavaScript | `Wasm | `None ])

compiler/lib/effects.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ let cps_branch ~st ~src (pc, args) loc =
300300
(* We are jumping to a block that is also used as a continuation.
301301
We pass it a dummy argument. *)
302302
let x = Var.fresh () in
303-
[ x ], [ Let (x, Constant (Int 0l)), noloc ]
303+
[ x ], [ Let (x, Constant (Int Targetint.zero)), noloc ]
304304
else args, []
305305
in
306306
(* We check the stack depth only for backward edges (so, at
@@ -402,7 +402,9 @@ let cps_last ~st ~alloc_jump_closures pc ((last, last_loc) : last * loc) ~k :
402402
( x'
403403
, Prim
404404
( Extern "caml_maybe_attach_backtrace"
405-
, [ Pv x; Pc (Int (if force then 1l else 0l)) ] ) )
405+
, [ Pv x
406+
; Pc (Int (if force then Targetint.one else Targetint.zero))
407+
] ) )
406408
, noloc )
407409
]
408410
in
@@ -483,7 +485,8 @@ let cps_instr ~st (instr : instr) : instr =
483485
| Pc (Int a) ->
484486
Let
485487
( x
486-
, Prim (Extern "caml_alloc_dummy_function", [ size; Pc (Int (Int32.succ a)) ])
488+
, Prim
489+
(Extern "caml_alloc_dummy_function", [ size; Pc (Int (Targetint.succ a)) ])
487490
)
488491
| _ -> assert false)
489492
| Let (x, Apply { f; args; _ }) when not (Var.Set.mem x st.cps_needed) ->
@@ -562,7 +565,7 @@ let cps_block ~st ~k pc block =
562565
[ arg; k' ]
563566
loc)
564567
| Prim (Extern "%perform", [ Pv effect_ ]) ->
565-
perform_effect ~effect_ ~continuation:(Pc (Int 0l)) loc
568+
perform_effect ~effect_ ~continuation:(Pc (Int Targetint.zero)) loc
566569
| Prim (Extern "%reperform", [ Pv effect_; continuation ]) ->
567570
perform_effect ~effect_ ~continuation loc
568571
| _ -> None

0 commit comments

Comments
 (0)