Skip to content

Commit

Permalink
feat!: Upgrade to libbinaryen v112 (#188)
Browse files Browse the repository at this point in the history
chore!: Rename `dataref` to `structref`
chore!: Rename `data` to `struct_` in `Heap_type`
chore!: Remove `equirecursive` in `Type_system`
feat: Add new Binaryen ops
fix!: Properly resolve ops externals to their type
feat!: Replace `Expression.Ref.is` with `Expression.Ref.is_null`
chore!: Remove Ops that no longer exist in Binaryen
chore: Update expected test output
feat: Add i31 expressions
feat: Add new optimization passes
  • Loading branch information
phated committed Sep 3, 2023
1 parent a39f908 commit 46c97c2
Show file tree
Hide file tree
Showing 36 changed files with 726 additions and 540 deletions.
2 changes: 1 addition & 1 deletion binaryen.opam
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ depends: [
"dune" {>= "3.0.0"}
"dune-configurator" {>= "3.0.0"}
"js_of_ocaml-compiler" {>= "4.1.0" < "6.0.0"}
"libbinaryen" {>= "111.0.0" < "112.0.0"}
"libbinaryen" {>= "112.0.0" < "113.0.0"}
]
382 changes: 191 additions & 191 deletions esy.lock/index.json

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions esy.lock/opam/dyn.3.9.0/opam → esy.lock/opam/dyn.3.9.1/opam

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions esy.lock/opam/xdg.3.9.0/opam → esy.lock/opam/xdg.3.9.1/opam

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "Apache-2.0",
"dependencies": {
"ocaml": ">= 4.12.0",
"@grain/libbinaryen": ">= 111.0.0 < 112.0.0",
"@grain/libbinaryen": ">= 112.0.0 < 113.0.0",
"@opam/dune": ">= 3.0.0",
"@opam/dune-configurator": ">= 3.0.0"
},
Expand Down
30 changes: 24 additions & 6 deletions src/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,25 @@ caml_binaryen_pop(value _module, value _ty) {
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}

CAMLprim value
caml_binaryen_i31_new(value _module, value _val) {
CAMLparam2(_module, _val);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef val = BinaryenExpressionRef_val(_val);
BinaryenExpressionRef exp = BinaryenI31New(module, val);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}

CAMLprim value
caml_binaryen_i31_get(value _module, value _val, value _signed) {
CAMLparam3(_module, _val, _signed);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenExpressionRef val = BinaryenExpressionRef_val(_val);
bool isSigned = Bool_val(_signed);
BinaryenExpressionRef exp = BinaryenI31Get(module, val, isSigned);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}

CAMLprim value
caml_binaryen_expression_id_invalid(value unit) {
CAMLparam1(unit);
Expand Down Expand Up @@ -653,9 +672,9 @@ caml_binaryen_expression_id_ref_null(value unit) {
CAMLreturn(Val_int(BinaryenRefNullId()));
}
CAMLprim value
caml_binaryen_expression_id_ref_is(value unit) {
caml_binaryen_expression_id_ref_is_null(value unit) {
CAMLparam1(unit);
CAMLreturn(Val_int(BinaryenRefIsId()));
CAMLreturn(Val_int(BinaryenRefIsNullId()));
}
CAMLprim value
caml_binaryen_expression_id_ref_as(value unit) {
Expand Down Expand Up @@ -1827,12 +1846,11 @@ caml_binaryen_ref_null(value _module, value _ty) {
}

CAMLprim value
caml_binaryen_ref_is(value _module, value _op, value _value) {
CAMLparam3(_module, _op, _value);
caml_binaryen_ref_is_null(value _module, value _value) {
CAMLparam2(_module, _value);
BinaryenModuleRef module = BinaryenModuleRef_val(_module);
BinaryenOp op = BinaryenOp_val(_op);
BinaryenExpressionRef val = BinaryenExpressionRef_val(_value);
BinaryenExpressionRef exp = BinaryenRefIs(module, op, val);
BinaryenExpressionRef exp = BinaryenRefIsNull(module, val);
CAMLreturn(alloc_BinaryenExpressionRef(exp));
}

Expand Down
26 changes: 20 additions & 6 deletions src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,20 @@ function caml_binaryen_pop(wasm_mod, typ) {
return Binaryen._BinaryenPop(wasm_mod, typ);
}

//Provides: caml_binaryen_i31_new
function caml_binaryen_i31_new(wasm_mod, typ) {
return wasm_mod.i31.new(typ);
}

//Provides: caml_binaryen_i31_get
function caml_binaryen_i31_get(wasm_mod, typ, signed) {
if (signed) {
return wasm_mod.i31.get_s(typ);
} else {
return wasm_mod.i31.get_u(typ);
}
}

//Provides: caml_binaryen_expression_id_invalid
//Requires: Binaryen
function caml_binaryen_expression_id_invalid() {
Expand Down Expand Up @@ -752,10 +766,10 @@ function caml_binaryen_expression_id_pop() {
function caml_binaryen_expression_id_ref_null() {
return Binaryen.RefNullId;
}
//Provides: caml_binaryen_expression_id_ref_is
//Provides: caml_binaryen_expression_id_ref_is_null
//Requires: Binaryen
function caml_binaryen_expression_id_ref_is() {
return Binaryen.RefIsId;
function caml_binaryen_expression_id_ref_is_null() {
return Binaryen.RefIsNullId;
}
//Provides: caml_binaryen_expression_id_ref_as
//Requires: Binaryen
Expand Down Expand Up @@ -1664,10 +1678,10 @@ function caml_binaryen_ref_null(wasm_mod, typ) {
return wasm_mod.ref.null(typ);
}

//Provides: caml_binaryen_ref_is
//Provides: caml_binaryen_ref_is_null
//Requires: Binaryen
function caml_binaryen_ref_is(wasm_mod, op, value) {
return Binaryen._BinaryenRefIs(wasm_mod, op, value);
function caml_binaryen_ref_is_null(wasm_mod, value) {
return Binaryen.ExpressionIds.RefIsNull(wasm_mod, value);
}

//Provides: caml_binaryen_ref_as
Expand Down
19 changes: 14 additions & 5 deletions src/expression.ml
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,10 @@ external id_ref_null : unit -> int = "caml_binaryen_expression_id_ref_null"

let id_ref_null = id_ref_null ()

external id_ref_is : unit -> int = "caml_binaryen_expression_id_ref_is"
external id_ref_is_null : unit -> int
= "caml_binaryen_expression_id_ref_is_null"

let id_ref_is = id_ref_is ()
let id_ref_is_null = id_ref_is_null ()

external id_ref_func : unit -> int = "caml_binaryen_expression_id_ref_func"

Expand Down Expand Up @@ -385,7 +386,7 @@ let get_kind expr =
| n when n = id_unreachable -> Unreachable
| n when n = id_pop -> Pop
| n when n = id_ref_null -> RefNull
| n when n = id_ref_is -> RefIs
| n when n = id_ref_is_null -> RefIs
| n when n = id_ref_func -> RefFunc
| n when n = id_ref_eq -> RefEq
| n when n = id_try -> Try
Expand Down Expand Up @@ -799,6 +800,14 @@ module Pop = struct
(** Module, type *)
end

module I31 = struct
external make : Module.t -> t -> t = "caml_binaryen_i31_new"
(** Module, value *)

external get : Module.t -> t -> bool -> t = "caml_binaryen_i31_get"
(** Module, i31, is_signed *)
end

module Null = struct
external make : unit -> t = "caml_binaryen_null_expression"
(** A null reference. *)
Expand All @@ -808,8 +817,8 @@ module Ref = struct
external null : Module.t -> Type.t -> t = "caml_binaryen_ref_null"
(** Module, type *)

external is : Module.t -> Op.t -> t -> t = "caml_binaryen_ref_is"
(** Module, op, value *)
external is_null : Module.t -> t -> t = "caml_binaryen_ref_is_null"
(** Module, value *)

external as_ : Module.t -> Op.t -> t -> t = "caml_binaryen_ref_as"
(** Module, op, value *)
Expand Down
12 changes: 10 additions & 2 deletions src/expression.mli
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ module Pop : sig
val make : Module.t -> Type.t -> t
end

module I31 : sig
val make : Module.t -> t -> t
(** Module, value *)

val get : Module.t -> t -> bool -> t
(** Module, i31, is_signed *)
end

module Null : sig
val make : unit -> t
end
Expand All @@ -329,8 +337,8 @@ module Ref : sig
val null : Module.t -> Type.t -> t
(** Module, type *)

val is : Module.t -> Op.t -> t -> t
(** Module, op, value *)
val is_null : Module.t -> t -> t
(** Module, value *)

val as_ : Module.t -> Op.t -> t -> t
(** Module, op, value *)
Expand Down
4 changes: 2 additions & 2 deletions src/heap_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ caml_binaryen_heap_type_i31(value unit) {
}

CAMLprim value
caml_binaryen_heap_type_data(value unit) {
caml_binaryen_heap_type_struct(value unit) {
CAMLparam1(unit);
BinaryenHeapType ty = BinaryenHeapTypeData();
BinaryenHeapType ty = BinaryenHeapTypeStruct();
CAMLreturn(alloc_BinaryenHeapType(ty));
}

Expand Down
6 changes: 3 additions & 3 deletions src/heap_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ function caml_binaryen_heap_type_i31() {
return Binaryen._BinaryenHeapTypeI31();
}

//Provides: caml_binaryen_heap_type_data
//Provides: caml_binaryen_heap_type_struct
//Requires: Binaryen
function caml_binaryen_heap_type_data() {
return Binaryen._BinaryenHeapTypeData();
function caml_binaryen_heap_type_struct() {
return Binaryen._BinaryenHeapTypeStruct();
}

//Provides: caml_binaryen_heap_type_array
Expand Down
2 changes: 1 addition & 1 deletion src/heap_type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ external func : unit -> t = "caml_binaryen_heap_type_func"
external any : unit -> t = "caml_binaryen_heap_type_any"
external eq : unit -> t = "caml_binaryen_heap_type_eq"
external i31 : unit -> t = "caml_binaryen_heap_type_i31"
external data : unit -> t = "caml_binaryen_heap_type_data"
external struct_ : unit -> t = "caml_binaryen_heap_type_struct"
external array : unit -> t = "caml_binaryen_heap_type_array"
external string : unit -> t = "caml_binaryen_heap_type_string"
external stringview_wtf8 : unit -> t = "caml_binaryen_heap_type_stringview_wtf8"
Expand Down
2 changes: 1 addition & 1 deletion src/heap_type.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ val func : unit -> t
val any : unit -> t
val eq : unit -> t
val i31 : unit -> t
val data : unit -> t
val struct_ : unit -> t
val array : unit -> t
val string : unit -> t
val stringview_wtf8 : unit -> t
Expand Down
Loading

0 comments on commit 46c97c2

Please sign in to comment.