From 2ab941662eda6a51998cb403f7151ddd1de196ba Mon Sep 17 00:00:00 2001 From: Spotandjake Date: Tue, 1 Sep 2026 20:26:33 -0400 Subject: [PATCH] feat!: Upgrade to Binaryen v132 Full Diff: https://github.com/WebAssembly/binaryen/compare/version_131...version_132 API Additions: * Module.Features.acquire_release_atomics * Expression.String.make * Passes.make_shared_objects Changes not made: * BinaryenMemoryOrderRelaxed was not added as we do not yet implement the atomics api NOTE: This is blocked on libbinaryen v131 releasing --- binaryen.opam | 2 +- esy.lock/index.json | 12 ++++++------ package.json | 2 +- src/expression.c | 11 +++++++++++ src/expression.js | 8 ++++++++ src/expression.ml | 5 +++++ src/expression.mli | 5 +++++ src/module.js | 2 +- src/module.ml | 9 +++++++-- src/module.mli | 3 ++- src/module_feature.c | 10 ++++++++-- src/module_feature.js | 12 +++++++++--- src/passes.ml | 3 +++ src/passes.mli | 3 +++ 14 files changed, 70 insertions(+), 17 deletions(-) diff --git a/binaryen.opam b/binaryen.opam index b7473b0a..29dbe1c6 100644 --- a/binaryen.opam +++ b/binaryen.opam @@ -16,6 +16,6 @@ depends: [ "dune" {>= "3.0.0"} "dune-configurator" {>= "3.0.0"} "js_of_ocaml-compiler" {>= "6.4.0" < "7.0.0"} - "libbinaryen" {>= "131.0.0" < "132.0.0"} + "libbinaryen" {>= "132.0.0" < "133.0.0"} ] x-maintenance-intent: ["0.(latest)"] diff --git a/esy.lock/index.json b/esy.lock/index.json index 90bf22da..b52a8549 100644 --- a/esy.lock/index.json +++ b/esy.lock/index.json @@ -1,5 +1,5 @@ { - "checksum": "cb86c36eb2efb63fbf47f7c5ea9f87b9", + "checksum": "1aeef89459a404e11b8d626c6bb90c12", "root": "@grain/binaryen.ml@link-dev:./package.json", "node": { "ocaml@5.3.0@d41d8cd9": { @@ -1934,14 +1934,14 @@ [ "windows", "x86_64" ] ] }, - "@grain/libbinaryen@131.0.0@d41d8cd9": { - "id": "@grain/libbinaryen@131.0.0@d41d8cd9", + "@grain/libbinaryen@132.0.0@d41d8cd9": { + "id": "@grain/libbinaryen@132.0.0@d41d8cd9", "name": "@grain/libbinaryen", - "version": "131.0.0", + "version": "132.0.0", "source": { "type": "install", "source": [ - "archive:https://registry.npmjs.org/@grain/libbinaryen/-/libbinaryen-131.0.0.tgz#sha1:a1fb1fd1c0b87fcc277e19835220ec450f199605" + "archive:https://registry.npmjs.org/@grain/libbinaryen/-/libbinaryen-132.0.0.tgz#sha1:6190c5ff61db997474fd8d0fbdb25c76fa65b4a1" ] }, "overrides": [], @@ -1974,7 +1974,7 @@ "ocaml@5.3.0@d41d8cd9", "@opam/dune-configurator@opam:3.24.2@7928eaef", "@opam/dune@opam:3.24.2@dc9091c2", - "@grain/libbinaryen@131.0.0@d41d8cd9" + "@grain/libbinaryen@132.0.0@d41d8cd9" ], "devDependencies": [ "@opam/ocamlformat@opam:0.29.0@966c16ee", diff --git a/package.json b/package.json index d40fa228..39da91fe 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ }, "dependencies": { "ocaml": ">= 4.14.0 < 6.0.0", - "@grain/libbinaryen": ">= 131.0.0 < 132.0.0", + "@grain/libbinaryen": ">= 132.0.0 < 133.0.0", "@opam/dune": ">= 3.0.0", "@opam/dune-configurator": ">= 3.0.0" }, diff --git a/src/expression.c b/src/expression.c index 7f0f25cf..16237c84 100644 --- a/src/expression.c +++ b/src/expression.c @@ -2228,6 +2228,17 @@ caml_binaryen_array_init_elem__bytecode(value * argv) { return caml_binaryen_array_init_elem(argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]); } +// Strings + +CAMLprim value +caml_binaryen_string_const(value _module, value _val) { + CAMLparam2(_module, _val); + BinaryenModuleRef module = BinaryenModuleRef_val(_module); + char* val = Safe_String_val(_val); + BinaryenExpressionRef exp = BinaryenStringConst(module, val); + CAMLreturn(alloc_BinaryenExpressionRef(exp)); +} + // Exception handling operations CAMLprim value caml_binaryen_try(value _module, value _name, value _body, value _catchTags, value _catchBodies, value _delegateTarget) { diff --git a/src/expression.js b/src/expression.js index b581c47d..d9b3d5ae 100644 --- a/src/expression.js +++ b/src/expression.js @@ -1939,6 +1939,14 @@ function caml_binaryen_array_copy__bytecode() { ); } +// Strings + +//Provides: caml_binaryen_string_const +//Requires: caml_jsstring_of_string +function caml_binaryen_string_const(wasm_mod, value) { + return wasm_mod.string.const(caml_jsstring_of_string(value)); +} + // Exception handling operations //Provides: caml_binaryen_try diff --git a/src/expression.ml b/src/expression.ml index 9780b83b..db7807b3 100644 --- a/src/expression.ml +++ b/src/expression.ml @@ -938,6 +938,11 @@ module Array = struct (** Module, seg, ref, index, offset, size *) end +module String = struct + external make : Module.t -> string -> t = "caml_binaryen_string_const" + (** Module, value *) +end + (** Bindings for `try_table` instruction. *) module Try = struct external make : diff --git a/src/expression.mli b/src/expression.mli index 775cb27d..bd647ac7 100644 --- a/src/expression.mli +++ b/src/expression.mli @@ -422,6 +422,11 @@ module Array : sig (** Module, seg, ref, index, offset, size *) end +module String : sig + val make : Module.t -> string -> t + (** Module, value *) +end + (** Bindings for `try` instruction. *) module Try : sig val make : diff --git a/src/module.js b/src/module.js index 00aa8bb7..527c0a06 100644 --- a/src/module.js +++ b/src/module.js @@ -105,7 +105,7 @@ function caml_binaryen_module_read(bytes) { //Requires: caml_uint8_array_of_bytes function caml_binaryen_module_read_with_features(bytes, features) { var data = caml_uint8_array_of_bytes(bytes); - return Binaryen.readBinaryWithFeatures(data, features); + return Binaryen.readBinary(data, features); } //Provides: caml_binaryen_module_interpret diff --git a/src/module.ml b/src/module.ml index e2fb4449..3517b147 100644 --- a/src/module.ml +++ b/src/module.ml @@ -98,9 +98,10 @@ module Feature = struct let call_indirect_overlong = call_indirect_overlong () - external relaxed_atomics : unit -> t = "caml_binaryen_feature_relaxed_atomics" + external acquire_release_atomics : unit -> t + = "caml_binaryen_feature_acquire_release_atomics" - let relaxed_atomics = relaxed_atomics () + let acquire_release_atomics = acquire_release_atomics () external multibyte : unit -> t = "caml_binaryen_feature_multibyte" @@ -119,6 +120,10 @@ module Feature = struct let compact_imports = compact_imports () + external relaxed_atomics : unit -> t = "caml_binaryen_feature_relaxed_atomics" + + let relaxed_atomics = relaxed_atomics () + external all : unit -> t = "caml_binaryen_feature_all" let all = all () diff --git a/src/module.mli b/src/module.mli index f0754142..75f133fe 100644 --- a/src/module.mli +++ b/src/module.mli @@ -25,11 +25,12 @@ module Feature : sig val fp16 : t val bulk_memory_opt : t val call_indirect_overlong : t - val relaxed_atomics : t + val acquire_release_atomics : t val multibyte : t val custom_page_sizes : t val wide_arithmetic : t val compact_imports : t + val relaxed_atomics : t val all : t end diff --git a/src/module_feature.c b/src/module_feature.c index 45d72f7f..80d013a7 100644 --- a/src/module_feature.c +++ b/src/module_feature.c @@ -156,9 +156,9 @@ caml_binaryen_feature_call_indirect_overlong(value unit) { } CAMLprim value -caml_binaryen_feature_relaxed_atomics(value unit) { +caml_binaryen_feature_acquire_release_atomics(value unit) { CAMLparam1(unit); - CAMLreturn(Val_int(BinaryenFeatureRelaxedAtomics())); + CAMLreturn(Val_int(BinaryenFeatureAcquireReleaseAtomics())); } CAMLprim value @@ -185,6 +185,12 @@ caml_binaryen_feature_compact_imports(value unit) { CAMLreturn(Val_int(BinaryenFeatureCompactImports())); } +CAMLprim value +caml_binaryen_feature_relaxed_atomics(value unit) { + CAMLparam1(unit); + CAMLreturn(Val_int(BinaryenFeatureRelaxedAtomics())); +} + CAMLprim value caml_binaryen_feature_all(value unit) { CAMLparam1(unit); diff --git a/src/module_feature.js b/src/module_feature.js index b74501f3..d81512d6 100644 --- a/src/module_feature.js +++ b/src/module_feature.js @@ -140,10 +140,10 @@ function caml_binaryen_feature_call_indirect_overlong() { return Binaryen.Features.BulkMemoryOpt; } -//Provides: caml_binaryen_feature_relaxed_atomics +//Provides: caml_binaryen_feature_acquire_release_atomics //Requires: Binaryen -function caml_binaryen_feature_relaxed_atomics() { - return Binaryen.Features.RelaxedAtomics; +function caml_binaryen_feature_acquire_release_atomics() { + return Binaryen.Features.AcquireReleaseAtomics; } //Provides: caml_binaryen_feature_multibyte @@ -170,6 +170,12 @@ function caml_binaryen_feature_compact_imports() { return Binaryen.Features.CompactImports; } +//Provides: caml_binaryen_feature_relaxed_atomics +//Requires: Binaryen +function caml_binaryen_feature_relaxed_atomics() { + return Binaryen.Features.RelaxedAtomics; +} + //Provides: caml_binaryen_feature_all //Requires: Binaryen function caml_binaryen_feature_all() { diff --git a/src/passes.ml b/src/passes.ml index 9ad2cb70..08783e45 100644 --- a/src/passes.ml +++ b/src/passes.ml @@ -194,6 +194,9 @@ let licm = "licm" (** attempt to merge segments to fit within web limits *) let limit_segments = "limit-segments" +(** Make structs and arrays shared and functions unshared *) +let make_shared_objects = "make-shared-objects" + (** mark js called functions (using configureAll) as doing so *) let mark_js_called = "mark-js-called" diff --git a/src/passes.mli b/src/passes.mli index c85e539c..52ff4706 100644 --- a/src/passes.mli +++ b/src/passes.mli @@ -191,6 +191,9 @@ val licm : t val limit_segments : t (** attempt to merge segments to fit within web limits *) +val make_shared_objects : t +(** Make structs and arrays shared and functions unshared *) + val mark_js_called : t (** mark js called functions (using configureAll) as doing so *)