@grain/binaryen.ml 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. binaryen-archive/CHANGELOG.md +30 -0
  2. binaryen-archive/binaryen.opam +2 -2
  3. binaryen-archive/esy.lock/index.json +392 -293
  4. binaryen-archive/esy.lock/opam/base.v0.17.3/opam +4 -2
  5. binaryen-archive/esy.lock/opam/{chrome-trace.3.20.2 → chrome-trace.3.21.1}/opam +5 -5
  6. binaryen-archive/esy.lock/opam/{dune-build-info.3.20.2 → dune-build-info.3.21.1}/opam +5 -5
  7. binaryen-archive/esy.lock/opam/{dune-configurator.3.20.2 → dune-configurator.3.21.1}/opam +5 -5
  8. binaryen-archive/esy.lock/opam/{dune-rpc.3.20.2 → dune-rpc.3.21.1}/opam +5 -5
  9. binaryen-archive/esy.lock/opam/{dune.3.20.2 → dune.3.21.1}/opam +6 -5
  10. binaryen-archive/esy.lock/opam/{dyn.3.20.2 → dyn.3.21.1}/opam +6 -6
  11. binaryen-archive/esy.lock/opam/fs-io.3.21.1/opam +41 -0
  12. binaryen-archive/esy.lock/opam/{menhir.20250912 → menhir.20260209}/opam +6 -4
  13. binaryen-archive/esy.lock/opam/{menhirCST.20250912 → menhirCST.20260209}/opam +4 -3
  14. binaryen-archive/esy.lock/opam/menhirGLR.20260209/opam +30 -0
  15. binaryen-archive/esy.lock/opam/{menhirLib.20250912 → menhirLib.20260209}/opam +5 -4
  16. binaryen-archive/esy.lock/opam/{menhirSdk.20250912 → menhirSdk.20260209}/opam +5 -4
  17. binaryen-archive/esy.lock/opam/ocaml_intrinsics_kernel.v0.17.1/opam +2 -0
  18. binaryen-archive/esy.lock/opam/{ocamlc-loc.3.20.2 → ocamlc-loc.3.21.1}/opam +6 -6
  19. binaryen-archive/esy.lock/opam/ocamlfind.1.9.8/opam +1 -1
  20. binaryen-archive/esy.lock/opam/{ordering.3.20.2 → ordering.3.21.1}/opam +6 -6
  21. binaryen-archive/esy.lock/opam/ppx_yojson_conv_lib.v0.17.0/opam +2 -0
  22. binaryen-archive/esy.lock/opam/sexplib0.v0.17.0/opam +2 -0
  23. binaryen-archive/esy.lock/opam/stdio.v0.17.0/opam +3 -1
  24. binaryen-archive/esy.lock/opam/{stdune.3.20.2 → stdune.3.21.1}/opam +9 -7
  25. binaryen-archive/esy.lock/opam/top-closure.3.21.1/opam +40 -0
  26. binaryen-archive/esy.lock/opam/{xdg.3.20.2 → xdg.3.21.1}/opam +5 -5
  27. binaryen-archive/package.json +2 -2
  28. binaryen-archive/src/dune +2 -0
  29. binaryen-archive/src/export.c +10 -0
  30. binaryen-archive/src/export.js +13 -0
  31. binaryen-archive/src/export.ml +4 -0
  32. binaryen-archive/src/export.mli +1 -0
  33. binaryen-archive/src/expression.c +291 -0
  34. binaryen-archive/src/expression.js +182 -0
  35. binaryen-archive/src/expression.ml +118 -0
  36. binaryen-archive/src/expression.mli +87 -0
  37. binaryen-archive/src/function.c +8 -0
  38. binaryen-archive/src/function.js +5 -0
  39. binaryen-archive/src/function.ml +1 -0
  40. binaryen-archive/src/function.mli +1 -0
  41. binaryen-archive/src/import.c +32 -0
  42. binaryen-archive/src/import.js +47 -0
  43. binaryen-archive/src/import.ml +12 -0
  44. binaryen-archive/src/import.mli +5 -0
  45. binaryen-archive/src/module.js +2 -2
  46. binaryen-archive/src/ocaml_helpers.c +8 -0
  47. binaryen-archive/src/ocaml_helpers.h +4 -0
  48. binaryen-archive/src/passes.ml +95 -21
  49. binaryen-archive/src/passes.mli +91 -21
  50. binaryen-archive/src/tag.c +61 -0
  51. binaryen-archive/src/tag.js +43 -0
  52. binaryen-archive/src/tag.ml +11 -0
  53. binaryen-archive/src/tag.mli +8 -0
  54. binaryen-archive/src/type.js +4 -7
  55. binaryen-archive/test/test.expected +158 -31
  56. binaryen-archive/test/test.ml +95 -2
@@ -37,12 +37,18 @@ val const_hoisting : t
37
37
  val cfp : t
38
38
  (** propagate constant struct field values *)
39
39
 
40
+ val cfp_reftest : t
41
+ (** propagate constant struct field values, using ref.test *)
42
+
40
43
  val dce : t
41
44
  (** removes unreachable code *)
42
45
 
43
46
  val dealign : t
44
47
  (** forces all loads and stores to have alignment 1 *)
45
48
 
49
+ val propagate_debug_locs : t
50
+ (** propagate debug location from parents or previous siblings to child nodes *)
51
+
46
52
  val denan : t
47
53
  (** instrument the wasm to convert NaNs into 0 at runtime *)
48
54
 
@@ -67,6 +73,9 @@ val duplicate_function_elimination : t
67
73
  val emit_target_features : t
68
74
  (** emit the target features section in the output *)
69
75
 
76
+ val enclose_world : t
77
+ (** modify the wasm (destructively) for closed-world *)
78
+
70
79
  val extract_function : t
71
80
  (** leaves just one function (useful for debugging) *)
72
81
 
@@ -94,9 +103,6 @@ val generate_i64_dyncalls : t
94
103
  val generate_global_effects : t
95
104
  (** generate global effect info (helps later passes) *)
96
105
 
97
- val generate_stack_ir : t
98
- (** generate Stack IR *)
99
-
100
106
  val global_refining : t
101
107
  (** refine the types of globals *)
102
108
 
@@ -110,15 +116,27 @@ val gufa : t
110
116
  (** Grand Unified Flow Analysis: optimize the entire program using information
111
117
  about what content can actually appear in each location *)
112
118
 
119
+ val gufa_cast_all : t
120
+ (** GUFA plus add casts for all inferences *)
121
+
113
122
  val gufa_optimizing : t
114
123
  (** GUFA plus local optimizations in functions we modified *)
115
124
 
125
+ val optimize_j2cl : t
126
+ (** optimizes J2CL specific constructs. *)
127
+
128
+ val merge_j2cl_itables : t
129
+ (** Merges itable structures into vtables to make types more compact *)
130
+
116
131
  val type_refining : t
117
132
  (** apply more specific subtypes to type fields where possible *)
118
133
 
119
134
  val heap2local : t
120
135
  (** replace GC allocations with locals *)
121
136
 
137
+ val heap_store_optimization : t
138
+ (** optimize heap (GC) stores *)
139
+
122
140
  val inline_main : t
123
141
  (** inline __original_main into main *)
124
142
 
@@ -137,9 +155,8 @@ val jspi : t
137
155
  val legalize_js_interface : t
138
156
  (** legalizes i64 types on the import/export boundary *)
139
157
 
140
- val legalize_js_interface_minimally : t
141
- (** legalizes i64 types on the import/export boundary in a minimal manner, only
142
- on things only JS will call *)
158
+ val legalize_and_prune_js_interface : t
159
+ (** legalizes the import/export boundary and prunes when needed *)
143
160
 
144
161
  val local_cse : t
145
162
  (** common subexpression elimination inside basic blocks *)
@@ -153,6 +170,9 @@ val log_execution : t
153
170
  val i64_to_i32_lowering : t
154
171
  (** lower all uses of i64s to use i32s instead *)
155
172
 
173
+ val trace_calls : t
174
+ (** instrument the build with code to intercept specific function calls *)
175
+
156
176
  val instrument_locals : t
157
177
  (** instrument the build with code to intercept all loads and stores *)
158
178
 
@@ -168,6 +188,13 @@ val limit_segments : t
168
188
  val memory64_lowering : t
169
189
  (** lower loads and stores to a 64-bit memory to instead use a 32-bit one *)
170
190
 
191
+ val table64_lowering : t
192
+ (** alias for memory64-lowering *)
193
+
194
+ val llvm_memory_copy_fill_lowering : t
195
+ (** Lower memory.copy and memory.fill to wasm mvp and disable the bulk-memory
196
+ feature. *)
197
+
171
198
  val memory_packing : t
172
199
  (** packs memory into separate segments, skipping zeros *)
173
200
 
@@ -195,12 +222,8 @@ val minify_imports_and_exports_and_modules : t
195
222
  (** minifies both import and export names, and emits a mapping to the minified
196
223
  ones, and minifies the modules as well *)
197
224
 
198
- val mod_asyncify_always_and_only_unwind : t
199
- (** apply the assumption that asyncify imports always unwind, and we never
200
- rewind *)
201
-
202
- val mod_asyncify_never_unwind : t
203
- (** apply the assumption that asyncify never unwinds *)
225
+ val minimize_rec_groups : t
226
+ (** Split types into minimal recursion groups *)
204
227
 
205
228
  val monomorphize : t
206
229
  (** creates specialized versions of functions *)
@@ -221,6 +244,19 @@ val nm : t
221
244
  val name_types : t
222
245
  (** (re)name all heap types *)
223
246
 
247
+ val no_inline : t
248
+ (** mark functions as no-inline *)
249
+
250
+ val no_full_inline : t
251
+ (** mark functions as no-inline (for full inlining only) *)
252
+
253
+ val no_partial_inline : t
254
+ (** mark functions as no-inline (for partial inlining only) *)
255
+
256
+ val llvm_nontrapping_fptoint_lowering : t
257
+ (** lower nontrapping float-to-int operations to wasm mvp and disable the
258
+ nontrapping fptoint feature *)
259
+
224
260
  val once_reduction : t
225
261
  (** reduces calls to code that only runs once *)
226
262
 
@@ -237,9 +273,6 @@ val optimize_casts : t
237
273
  val optimize_instructions : t
238
274
  (** optimizes instruction combinations *)
239
275
 
240
- val optimize_stack_ir : t
241
- (** optimize Stack IR *)
242
-
243
276
  val pick_load_signs : t
244
277
  (** pick load signs based on their uses *)
245
278
 
@@ -280,15 +313,15 @@ val print_function_map : t
280
313
  val symbolmap : t
281
314
  (** alias for print_function_map *)
282
315
 
283
- val print_stack_ir : t
284
- (** print out Stack IR (useful for internal debugging) *)
285
-
286
316
  val remove_non_js_ops : t
287
317
  (** removes operations incompatible with js *)
288
318
 
289
319
  val remove_imports : t
290
320
  (** removes imports and replaces them with nops *)
291
321
 
322
+ val remove_memory_init : t
323
+ (** removes memory initialization *)
324
+
292
325
  val remove_memory : t
293
326
  (** removes memory segments *)
294
327
 
@@ -307,18 +340,21 @@ val remove_unused_names : t
307
340
  val remove_unused_types : t
308
341
  (** remove unused private GC types *)
309
342
 
343
+ val reorder_functions_by_name : t
344
+ (** sorts functions by name (useful for debugging) *)
345
+
310
346
  val reorder_functions : t
311
347
  (** sorts functions by access frequency *)
312
348
 
313
349
  val reorder_globals : t
314
350
  (** sorts globals by access frequency *)
315
351
 
316
- val reorder_globals_always : t
317
- (** sorts globals by access frequency (even if there are few) *)
318
-
319
352
  val reorder_locals : t
320
353
  (** sorts locals by access frequency *)
321
354
 
355
+ val reorder_types: t
356
+ (** sorts private types by access frequency *)
357
+
322
358
  val rereloop : t
323
359
  (** re-optimize control flow using the relooper algorithm *)
324
360
 
@@ -334,6 +370,9 @@ val safe_heap : t
334
370
  val set_globals : t
335
371
  (** sets specified globals to specified values *)
336
372
 
373
+ val separate_data_segments : t
374
+ (** write data segments to a file and strip them from the module *)
375
+
337
376
  val signature_pruning : t
338
377
  (** remove params from function signature types where possible *)
339
378
 
@@ -384,6 +423,22 @@ val ssa : t
384
423
  val ssa_nomerge : t
385
424
  (** ssa-ify variables so that they have a single assignment, ignoring merges *)
386
425
 
426
+ val string_gathering : t
427
+ (** gathers wasm strings to globals *)
428
+
429
+ val string_lifting : t
430
+ (** lift string imports to wasm strings *)
431
+
432
+ val string_lowering : t
433
+ (** lowers wasm strings and operations to imports *)
434
+
435
+ val string_lowering_magic_imports : t
436
+ (** same as string-lowering, but encodes well-formed strings as magic imports *)
437
+
438
+ val string_lowering_magic_imports_assert : t
439
+ (** same as string-lowering-magic-imports, but raise a fatal error if there are
440
+ invalid strings *)
441
+
387
442
  val strip : t
388
443
  (** deprecated; same as strip-debug *)
389
444
 
@@ -405,18 +460,33 @@ val strip_eh : t
405
460
  val strip_target_features : t
406
461
  (** strip the wasm target features section *)
407
462
 
463
+ val translate_to_exnref : t
464
+ (** translate old Phase 3 EH instructions to new ones with exnref *)
465
+
408
466
  val trap_mode_clamp : t
409
467
  (** replace trapping operations with clamping semantics *)
410
468
 
411
469
  val trap_mode_js : t
412
470
  (** replace trapping operations with js semantics *)
413
471
 
472
+ val tuple_optimization : t
473
+ (** optimize trivial tuples away *)
474
+
475
+ val type_finalizing : t
476
+ (** mark all leaf types as final *)
477
+
414
478
  val type_merging : t
415
479
  (** merge types to their supertypes where possible *)
416
480
 
417
481
  val type_ssa : t
418
482
  (** create new nominal types to help other optimizations *)
419
483
 
484
+ val type_unfinalizing : t
485
+ (** mark all types as non-final (open) *)
486
+
487
+ val unsubtyping : t
488
+ (** removes removes unnecessary subtyping relationships *)
489
+
420
490
  val untee : t
421
491
  (** removes local.tees, replacing them with sets and gets *)
422
492
 
@@ -0,0 +1,61 @@
1
+ #define CAML_NAME_SPACE
2
+ #include <caml/mlvalues.h>
3
+ #include <caml/fail.h>
4
+ #include <caml/memory.h>
5
+ #include <caml/alloc.h>
6
+
7
+ #include "binaryen-c.h"
8
+ #include "ocaml_helpers.h"
9
+
10
+ CAMLprim value
11
+ caml_binaryen_add_tag(value _module, value _name, value _params, value _results) {
12
+ CAMLparam4(_module, _name, _params, _results);
13
+ BinaryenModuleRef module = BinaryenModuleRef_val(_module);
14
+ char* name = Safe_String_val(_name);
15
+ BinaryenType params = BinaryenType_val(_params);
16
+ BinaryenType results = BinaryenType_val(_results);
17
+ BinaryenTagRef tag = BinaryenAddTag(module, name, params, results);
18
+ CAMLreturn(alloc_BinaryenTagRef(tag));
19
+ }
20
+
21
+ CAMLprim value
22
+ caml_binaryen_get_tag(value _module, value _name) {
23
+ CAMLparam2(_module, _name);
24
+ BinaryenModuleRef module = BinaryenModuleRef_val(_module);
25
+ char* name = Safe_String_val(_name);
26
+ BinaryenTagRef tag = BinaryenGetTag(module, name);
27
+ CAMLreturn(alloc_BinaryenTagRef(tag));
28
+ }
29
+
30
+ CAMLprim value
31
+ caml_binaryen_remove_tag(value _module, value _name) {
32
+ CAMLparam2(_module, _name);
33
+ BinaryenModuleRef module = BinaryenModuleRef_val(_module);
34
+ char* name = Safe_String_val(_name);
35
+ BinaryenRemoveTag(module, name);
36
+ CAMLreturn(Val_unit);
37
+ }
38
+
39
+ CAMLprim value
40
+ caml_binaryen_tag_get_name(value _tag) {
41
+ CAMLparam1(_tag);
42
+ BinaryenTagRef tag = BinaryenTagRef_val(_tag);
43
+ const char* name = BinaryenTagGetName(tag);
44
+ CAMLreturn(caml_copy_string(name));
45
+ }
46
+
47
+ CAMLprim value
48
+ caml_binaryen_tag_get_params(value _tag) {
49
+ CAMLparam1(_tag);
50
+ BinaryenTagRef tag = BinaryenTagRef_val(_tag);
51
+ BinaryenType ty = BinaryenTagGetParams(tag);
52
+ CAMLreturn(alloc_BinaryenType(ty));
53
+ }
54
+
55
+ CAMLprim value
56
+ caml_binaryen_tag_get_results(value _tag) {
57
+ CAMLparam1(_tag);
58
+ BinaryenTagRef tag = BinaryenTagRef_val(_tag);
59
+ BinaryenType ty = BinaryenTagGetResults(tag);
60
+ CAMLreturn(alloc_BinaryenType(ty));
61
+ }
@@ -0,0 +1,43 @@
1
+ //Provides: caml_binaryen_add_tag
2
+ //Requires: caml_jsstring_of_string
3
+ function caml_binaryen_add_tag(wasm_mod, name, params, results) {
4
+ return wasm_mod.addTag(
5
+ caml_jsstring_of_string(name),
6
+ params,
7
+ results,
8
+ );
9
+ }
10
+
11
+ //Provides: caml_binaryen_get_tag
12
+ //Requires: caml_jsstring_of_string
13
+ function caml_binaryen_get_tag(wasm_mod, name) {
14
+ return wasm_mod.getTag(caml_jsstring_of_string(name));
15
+ }
16
+
17
+ //Provides: caml_binaryen_remove_tag
18
+ //Requires: caml_jsstring_of_string
19
+ function caml_binaryen_remove_tag(wasm_mod, name) {
20
+ return wasm_mod.removeTag(caml_jsstring_of_string(name));
21
+ }
22
+
23
+ //Provides: caml_binaryen_tag_get_name
24
+ //Requires: Binaryen
25
+ //Requires: caml_string_of_jsstring
26
+ function caml_binaryen_tag_get_name(tag) {
27
+ var tag_info = Binaryen.getTagInfo(tag);
28
+ return caml_string_of_jsstring(tag_info.name);
29
+ }
30
+
31
+ //Provides: caml_binaryen_tag_get_params
32
+ //Requires: Binaryen
33
+ function caml_binaryen_tag_get_params(tag) {
34
+ var tag_info = Binaryen.getTagInfo(tag);
35
+ return tag_info.params;
36
+ }
37
+
38
+ //Provides: caml_binaryen_tag_get_results
39
+ //Requires: Binaryen
40
+ function caml_binaryen_tag_get_results(tag) {
41
+ var tag_info = Binaryen.getTagInfo(tag);
42
+ return tag_info.results;
43
+ }
@@ -0,0 +1,11 @@
1
+ type t
2
+
3
+ external add_tag : Module.t -> string -> Type.t -> Type.t -> t
4
+ = "caml_binaryen_add_tag"
5
+ (** Module, name, params, result *)
6
+
7
+ external get_tag : Module.t -> string -> t = "caml_binaryen_get_tag"
8
+ external remove_tag : Module.t -> string -> unit = "caml_binaryen_remove_tag"
9
+ external get_name : t -> string = "caml_binaryen_tag_get_name"
10
+ external get_params : t -> Type.t = "caml_binaryen_tag_get_params"
11
+ external get_results : t -> Type.t = "caml_binaryen_tag_get_results"
@@ -0,0 +1,8 @@
1
+ type t
2
+
3
+ val add_tag : Module.t -> string -> Type.t -> Type.t -> t
4
+ val get_tag : Module.t -> string -> t
5
+ val remove_tag : Module.t -> string -> unit
6
+ val get_name : t -> string
7
+ val get_params : t -> Type.t
8
+ val get_results : t -> Type.t
@@ -67,7 +67,7 @@ function caml_binaryen_type_structref() {
67
67
  //Provides: caml_binaryen_type_arrayref
68
68
  //Requires: Binaryen
69
69
  function caml_binaryen_type_arrayref() {
70
- // TODO: Binaryen v111 didn't expose this directly
70
+ // TODO: Binaryen v125 doesn't expose this directly
71
71
  return Binaryen._BinaryenTypeArrayref();
72
72
  }
73
73
 
@@ -80,22 +80,19 @@ function caml_binaryen_type_stringref() {
80
80
  //Provides: caml_binaryen_type_nullref
81
81
  //Requires: Binaryen
82
82
  function caml_binaryen_type_nullref() {
83
- // TODO: Binaryen v111 didn't expose this directly
84
- return Binaryen._BinaryenTypeNullref();
83
+ return Binaryen.nullref;
85
84
  }
86
85
 
87
86
  //Provides: caml_binaryen_type_null_externref
88
87
  //Requires: Binaryen
89
88
  function caml_binaryen_type_null_externref() {
90
- // TODO: Binaryen v111 didn't expose this directly
91
- return Binaryen._BinaryenTypeNullExternref();
89
+ return Binaryen.nullexternref;
92
90
  }
93
91
 
94
92
  //Provides: caml_binaryen_type_null_funcref
95
93
  //Requires: Binaryen
96
94
  function caml_binaryen_type_null_funcref() {
97
- // TODO: Binaryen v111 didn't expose this directly
98
- return Binaryen._BinaryenTypeNullFuncref();
95
+ return Binaryen.nullfuncref;
99
96
  }
100
97
 
101
98
  //Provides: caml_binaryen_type_unreachable