Skip to content

Commit

Permalink
melange-ppx: deprecate [@@mel.val] and suggest its removal (#678)
Browse files Browse the repository at this point in the history
* melange-ppx: deprecate `[@@mel.val]` and suggest its removal

* chore: remove `mel.val` attribute from runtime/stdlib

* chore: add changelog entry

* chore: promote tests
  • Loading branch information
anmonteiro authored Aug 7, 2023
1 parent d3459c8 commit 74d00ed
Show file tree
Hide file tree
Showing 48 changed files with 690 additions and 605 deletions.
4 changes: 4 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Unreleased
[#664](https://github.com/melange-re/melange/pull/664))
- [melange]: Upgrade the OCaml typechecker version to 5.1
([#668](https://github.com/melange-re/melange/pull/668))
- [melange.ppx]: Deprecate `[@@mel.val]` and suggest its removal. This
attribute is redundant and unnecessary
([#675](https://github.com/melange-re/melange/issues/675),
[#678](https://github.com/melange-re/melange/pull/678))

1.0.0 2023-05-31
---------------
Expand Down
14 changes: 7 additions & 7 deletions flake.lock

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

6 changes: 3 additions & 3 deletions jscomp/others/belt_Float.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
Utililites for Float
*)

external isNaN : float -> bool = "isNaN" [@@mel.val]
external isNaN : float -> bool = "isNaN"
external toInt : float -> int = "%intoffloat"
external fromInt : int -> float = "%identity"
external fromString : string -> float = "parseFloat" [@@mel.val]
external fromString : string -> float = "parseFloat"

let fromString i =
match fromString i with i when isNaN i -> None | i -> Some i

external toString : float -> string = "String" [@@mel.val]
external toString : float -> string = "String"
external ( + ) : float -> float -> float = "%addfloat"
external ( - ) : float -> float -> float = "%subfloat"
external ( * ) : float -> float -> float = "%mulfloat"
Expand Down
2 changes: 1 addition & 1 deletion jscomp/others/belt_Float.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
external toInt : float -> int = "%intoffloat"
external fromInt : int -> float = "%identity"
val fromString : string -> float option
external toString : float -> string = "String" [@@mel.val]
external toString : float -> string = "String"
external ( + ) : float -> float -> float = "%addfloat"
external ( - ) : float -> float -> float = "%subfloat"
external ( * ) : float -> float -> float = "%mulfloat"
Expand Down
6 changes: 3 additions & 3 deletions jscomp/others/belt_Int.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
Utililites for Int
*)

external isNaN : int -> bool = "isNaN" [@@mel.val]
external isNaN : int -> bool = "isNaN"
external toFloat : int -> float = "%identity"
external fromFloat : float -> int = "%intoffloat"
external fromString : string -> (_[@mel.as 10]) -> int = "parseInt" [@@mel.val]
external fromString : string -> (_[@mel.as 10]) -> int = "parseInt"

let fromString i =
match fromString i with i when isNaN i -> None | i -> Some i

external toString : int -> string = "String" [@@mel.val]
external toString : int -> string = "String"
external ( + ) : int -> int -> int = "%addint"
external ( - ) : int -> int -> int = "%subint"
external ( * ) : int -> int -> int = "%mulint"
Expand Down
2 changes: 1 addition & 1 deletion jscomp/others/belt_Int.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
external toFloat : int -> float = "%identity"
external fromFloat : float -> int = "%intoffloat"
val fromString : string -> int option
external toString : int -> string = "String" [@@mel.val]
external toString : int -> string = "String"
external ( + ) : int -> int -> int = "%addint"
external ( - ) : int -> int -> int = "%subint"
external ( * ) : int -> int -> int = "%mulint"
Expand Down
8 changes: 4 additions & 4 deletions jscomp/others/dom_storage.ml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
type t = Dom_storage2.t

external getItem : string -> string option = "getItem"
[@@mel.send.pipe: t] [@@mel.return null_to_opt]
[@@mel.send.pipe: t] [@@mel.return null_to_opt]

external setItem : string -> string -> unit = "setItem" [@@mel.send.pipe: t]
external removeItem : string -> unit = "removeItem" [@@mel.send.pipe: t]
external clear : unit = "clear" [@@mel.send.pipe: t]

external key : int -> string option = "key"
[@@mel.send.pipe: t] [@@mel.return null_to_opt]
[@@mel.send.pipe: t] [@@mel.return null_to_opt]

external length : t -> int = "length" [@@mel.get]
external localStorage : t = "localStorage" [@@mel.val]
external sessionStorage : t = "sessionStorage" [@@mel.val]
external localStorage : t = "localStorage"
external sessionStorage : t = "sessionStorage"
8 changes: 4 additions & 4 deletions jscomp/others/dom_storage2.ml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
type t

external getItem : t -> string -> string option = "getItem"
[@@mel.send] [@@mel.return null_to_opt]
[@@mel.send] [@@mel.return null_to_opt]

external setItem : t -> string -> string -> unit = "setItem" [@@mel.send]
external removeItem : t -> string -> unit = "removeItem" [@@mel.send]
external clear : t -> unit = "clear" [@@mel.send]

external key : t -> int -> string option = "key"
[@@mel.send] [@@mel.return null_to_opt]
[@@mel.send] [@@mel.return null_to_opt]

external length : t -> int = "length" [@@mel.get]
external localStorage : t = "localStorage" [@@mel.val]
external sessionStorage : t = "sessionStorage" [@@mel.val]
external localStorage : t = "localStorage"
external sessionStorage : t = "sessionStorage"
10 changes: 5 additions & 5 deletions jscomp/others/node_buffer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@

type t = Node.buffer

external isBuffer : 'a -> bool = "Buffer.isBuffer" [@@mel.val]
external fromString : string -> t = "Buffer.from" [@@mel.val]
external isBuffer : 'a -> bool = "Buffer.isBuffer"
external fromString : string -> t = "Buffer.from"

type encoding =
[ `ascii | `utf8 | `utf16le | `usc2 | `base64 | `latin1 | `binary | `hex ]

external fromStringWithEncoding : string -> encoding -> t = "from"
[@@mel.val] [@@mel.scope "Buffer"]
[@@mel.scope "Buffer"]

external toString : t -> string = "toString" [@@mel.send]

external toStringWithEncoding : t -> encoding -> string = "toString"
[@@mel.send]
[@@mel.send]

external concat : t array -> t = "Buffer.concat" [@@mel.val]
external concat : t array -> t = "Buffer.concat"
31 changes: 15 additions & 16 deletions jscomp/others/node_fs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
*)

external readdirSync : string -> string array = "readdirSync"
[@@mel.module "fs"]
[@@mel.module "fs"]
(** Most fs functions let you omit the callback argument. If you do, a default
callback is used that rethrows errors. To get a trace to the original call
site, set the `NODE_DEBUG` environment variable:
*)

external renameSync : string -> string -> unit = "renameSync"
[@@mel.module "fs"]
[@@mel.module "fs"]

type fd = private int

Expand All @@ -55,10 +55,10 @@ module Watch = struct
?encoding:Js.String.t ->
unit ->
config = ""
[@@mel.obj]
[@@mel.obj]

external watch : string -> ?config:config -> unit -> t = "watch"
[@@mel.module "fs"]
[@@mel.module "fs"]
(** there is no need to accept listener, since we return a [watcher]
back it can register event listener there .
Currently we introduce a type [string_buffer], for the
Expand All @@ -73,7 +73,7 @@ module Watch = struct
| `error of (unit -> unit[@u]) ]
[@mel.string]) ->
t = "on"
[@@mel.send.pipe: t] [@@deprecated "Please use `Node.Fs.on_` instead "]
[@@mel.send.pipe: t] [@@deprecated "Please use `Node.Fs.on_` instead "]

external on_ :
t ->
Expand All @@ -82,21 +82,21 @@ module Watch = struct
| `error of (unit -> unit[@u]) ]
[@mel.string]) ->
t = "on"
[@@mel.send]
[@@mel.send]

external close : t -> unit = "close" [@@mel.send]
end

external ftruncateSync : fd -> int -> unit = "ftruncateSync" [@@mel.module "fs"]

external truncateSync : string -> int -> unit = "truncateSync"
[@@mel.module "fs"]
[@@mel.module "fs"]

external chownSync : string -> uid:int -> gid:int -> unit = "chownSync"
[@@mel.module "fs"]
[@@mel.module "fs"]

external fchownSync : fd -> uid:int -> gid:int -> unit = "fchownSync"
[@@mel.module "fs"]
[@@mel.module "fs"]

external readlinkSync : string -> string = "readlinkSync" [@@mel.module "fs"]
external unlinkSync : string -> unit = "unlinkSync" [@@mel.module "fs"]
Expand All @@ -118,7 +118,7 @@ external openSync :
| `Append_read_fail_if_exists [@mel.as "ax+"] ]
[@mel.string]) ->
unit = "openSync"
[@@mel.module "fs"]
[@@mel.module "fs"]

type encoding =
[ `hex
Expand All @@ -132,18 +132,17 @@ type encoding =
| `utf16le ]

external readFileSync : string -> encoding -> string = "readFileSync"
[@@mel.val] [@@mel.module "fs"]
[@@mel.module "fs"]

external readFileAsUtf8Sync : string -> (_[@mel.as "utf8"]) -> string
= "readFileSync"
[@@mel.val] [@@mel.module "fs"]
[@@mel.module "fs"]

external existsSync : string -> bool = "existsSync"
[@@mel.val] [@@mel.module "fs"]
external existsSync : string -> bool = "existsSync" [@@mel.module "fs"]

external writeFileSync : string -> string -> encoding -> unit = "writeFileSync"
[@@mel.val] [@@mel.module "fs"]
[@@mel.module "fs"]

external writeFileAsUtf8Sync : string -> string -> (_[@mel.as "utf8"]) -> unit
= "writeFileSync"
[@@mel.val] [@@mel.module "fs"]
[@@mel.module "fs"]
1 change: 0 additions & 1 deletion jscomp/others/node_module.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@
(** Node Module API *)

external module_ : < __cache : Node.node_module Js.Dict.t > Js.t = "module"
[@@mel.val]
16 changes: 8 additions & 8 deletions jscomp/runtime/caml_float.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
open Melange_mini_stdlib

(* borrowed from others/js_math.ml *)
external _LOG2E : float = "Math.LOG2E" [@@mel.val]
external _LOG10E : float = "Math.LOG10E" [@@mel.val]
external abs_float : float -> float = "Math.abs" [@@mel.val]
external floor : float -> float = "Math.floor" [@@mel.val]
external exp : float -> float = "exp" [@@mel.val] [@@mel.scope "Math"]
external log : float -> float = "Math.log" [@@mel.val]
external sqrt : float -> float = "sqrt" [@@mel.val] [@@mel.scope "Math"]
external pow_float : base:float -> exp:float -> float = "Math.pow" [@@mel.val]
external _LOG2E : float = "Math.LOG2E"
external _LOG10E : float = "Math.LOG10E"
external abs_float : float -> float = "Math.abs"
external floor : float -> float = "Math.floor"
external exp : float -> float = "exp" [@@mel.scope "Math"]
external log : float -> float = "Math.log"
external sqrt : float -> float = "sqrt" [@@mel.scope "Math"]
external pow_float : base:float -> exp:float -> float = "Math.pow"
external int_of_float : float -> int = "%intoffloat"
external float_of_int : int -> float = "%floatofint"

Expand Down
2 changes: 1 addition & 1 deletion jscomp/runtime/caml_float.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

external floor : float -> float = "Math.floor" [@@mel.val]
external floor : float -> float = "Math.floor"
(** *)

external int_of_float : float -> int = "%intoffloat"
Expand Down
12 changes: 6 additions & 6 deletions jscomp/runtime/caml_float_extern.ml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
external _NaN : float = "NaN" [@@mel.val]
external isNaN : float -> bool = "isNaN" [@@mel.val]
external isFinite : float -> bool = "isFinite" [@@mel.val]
external _NaN : float = "NaN"
external isNaN : float -> bool = "isNaN"
external isFinite : float -> bool = "isFinite"

external toExponentialWithPrecision : float -> digits:int -> string
= "toExponential"
[@@mel.send]
[@@mel.send]

external toFixed : float -> string = "toFixed" [@@mel.send]

external toFixedWithPrecision : float -> digits:int -> string = "toFixed"
[@@mel.send]
[@@mel.send]

external fromString : string -> float = "Number" [@@mel.val]
external fromString : string -> float = "Number"
12 changes: 6 additions & 6 deletions jscomp/runtime/caml_int64.ml
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ let rec of_float (x : float) : t =
~lo:(Caml_nativeint_extern.of_float (mod_float x two_ptr_32_dbl))
~hi:(Caml_nativeint_extern.of_float (x /. two_ptr_32_dbl))

external log2 : float = "LN2" [@@mel.val] [@@mel.scope "Math"]
external log : float -> float = "log" [@@mel.val] [@@mel.scope "Math"]
external ceil : float -> float = "ceil" [@@mel.val] [@@mel.scope "Math"]
external floor : float -> float = "floor" [@@mel.val] [@@mel.scope "Math"]
(* external maxFloat : float -> float -> float = "Math.max" [@@mel.val] *)
external log2 : float = "LN2" [@@mel.scope "Math"]
external log : float -> float = "log" [@@mel.scope "Math"]
external ceil : float -> float = "ceil" [@@mel.scope "Math"]
external floor : float -> float = "floor" [@@mel.scope "Math"]
(* external maxFloat : float -> float -> float = "Math.max" *)

(* either top 11 bits are all 0 or all 1
when it is all 1, we need exclude -2^53
Expand All @@ -237,7 +237,7 @@ let isSafeInteger { hi; lo } =
top11Bits = 0
|| (top11Bits = -1 && Pervasives.not (lo = 0 && hi = 0xff_e0_00_00))

external string_of_float : float -> string = "String" [@@mel.val]
external string_of_float : float -> string = "String"

let rec to_string (self : int64) =
let ({ hi = self_hi; _ } as self) = unsafe_of_int64 self in
Expand Down
2 changes: 1 addition & 1 deletion jscomp/runtime/caml_nativeint_extern.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ external shift_right_logical : int -> int -> int = "nativeint_lsr"
external mul : int -> int -> int = "nativeint_mul"
external to_float : int -> float = "%identity"
external of_float : float -> int = "caml_int_of_float"
external to_string : int -> string = "String" [@@mel.val]
external to_string : int -> string = "String"
6 changes: 3 additions & 3 deletions jscomp/runtime/caml_obj.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ open Melange_mini_stdlib
type t = Obj.t

module O = struct
external isArray : 'a -> bool = "Array.isArray" [@@mel.val]
external isArray : 'a -> bool = "Array.isArray"

type key = string

Expand All @@ -38,7 +38,7 @@ module O = struct
|}]

external hasOwnProperty : t -> key -> bool = "call"
[@@mel.scope "Object", "prototype", "hasOwnProperty"] [@@mel.val]
[@@mel.scope "Object", "prototype", "hasOwnProperty"]
(**
JS objects are not guaranteed to have `Object` in their prototype
chain so calling `some_obj.hasOwnProperty(key)` can sometimes throw
Expand Down Expand Up @@ -369,7 +369,7 @@ let caml_equal_nullable (x : Obj.t) (y : Obj.t Js_internal.nullable) =

let isNumberOrBigInt a =
Js_internal.typeof a = "number" || Js_internal.typeof a = "bigint"
[@@inline]
[@@inline]

let canNumericCompare a b = isNumberOrBigInt a && isNumberOrBigInt b [@@inline]

Expand Down
Loading

0 comments on commit 74d00ed

Please sign in to comment.