From 64ee24e31962b836b2af45d9733b37f5c09037c7 Mon Sep 17 00:00:00 2001 From: Antonio Nuno Monteiro Date: Sun, 19 Jan 2025 19:03:56 -0800 Subject: [PATCH] runtime(Js.{Map,Set,WeakMap,WeakSet}): port `@mel.send` externals to use `@mel.this` (#1306) --- jscomp/runtime/js_map.ml | 16 ++++++++++------ jscomp/runtime/js_set.ml | 36 +++++++++++++++++++++--------------- jscomp/runtime/js_weakmap.ml | 14 ++++++++++---- jscomp/runtime/js_weakset.ml | 12 +++++++++--- 4 files changed, 50 insertions(+), 28 deletions(-) diff --git a/jscomp/runtime/js_map.ml b/jscomp/runtime/js_map.ml index a6baf3b8a..d19628838 100644 --- a/jscomp/runtime/js_map.ml +++ b/jscomp/runtime/js_map.ml @@ -30,20 +30,24 @@ external make : unit -> ('k, 'v) t = "Map" [@@mel.new] external fromArray : ('k * 'v) array -> ('k, 'v) t = "Map" [@@mel.new] external toArray : ('k, 'v) t -> ('k * 'v) array = "from" [@@mel.scope "Array"] external size : ('k, 'v) t -> int = "size" [@@mel.get] -external has : ('k, 'v) t -> key:'k -> bool = "has" [@@mel.send] +external has : key:'k -> (('k, 'v) t[@mel.this]) -> bool = "has" [@@mel.send] -external get : ('k, 'v) t -> key:'k -> 'v option = "get" +external get : key:'k -> (('k, 'v) t[@mel.this]) -> 'v option = "get" [@@mel.send] [@@mel.return { undefined_to_opt }] -external set : ('k, 'v) t -> key:'k -> value:'v -> ('k, 'v) t = "set" +external set : key:'k -> value:'v -> (('k, 'v) t[@mel.this]) -> ('k, 'v) t + = "set" [@@mel.send] external clear : ('k, 'v) t -> unit = "clear" [@@mel.send] -external delete : ('k, 'v) t -> key:'k -> bool = "delete" [@@mel.send] + +external delete : key:'k -> (('k, 'v) t[@mel.this]) -> bool = "delete" +[@@mel.send] external forEach : - f:(('v -> 'k -> ('k, 'v) t -> unit)[@mel.uncurry]) -> ('k, 'v) t -> unit - = "forEach" + f:(('v -> 'k -> ('k, 'v) t -> unit)[@mel.uncurry]) -> + (('k, 'v) t[@mel.this]) -> + unit = "forEach" [@@mel.send] external keys : ('k, 'v) t -> 'k Js.iterator = "keys" [@@mel.send] diff --git a/jscomp/runtime/js_set.ml b/jscomp/runtime/js_set.ml index 32a1b4145..33c911cfd 100644 --- a/jscomp/runtime/js_set.ml +++ b/jscomp/runtime/js_set.ml @@ -30,29 +30,35 @@ external make : unit -> 'a t = "Set" [@@mel.new] external fromArray : 'a array -> 'a t = "Set" [@@mel.new] external toArray : 'a t -> 'a array = "Array.from" external size : 'a t -> int = "size" [@@mel.get] -external add : value:'a -> 'a t -> 'a t = "add" [@@mel.send] +external add : value:'a -> ('a t[@mel.this]) -> 'a t = "add" [@@mel.send] external clear : 'a t -> unit = "clear" [@@mel.send] -external delete : value:'a -> 'a t -> bool = "delete" [@@mel.send] -external forEach : f:('a -> unit) -> 'a t -> unit = "forEach" [@@mel.send] -external has : value:'a -> 'a t -> bool = "has" [@@mel.send] +external delete : value:'a -> ('a t[@mel.this]) -> bool = "delete" [@@mel.send] + +external forEach : f:('a -> unit) -> ('a t[@mel.this]) -> unit = "forEach" +[@@mel.send] + +external has : value:'a -> ('a t[@mel.this]) -> bool = "has" [@@mel.send] external values : 'a t -> 'a Js.iterator = "values" [@@mel.send] external entries : 'a t -> ('a * 'a) Js.iterator = "entries" [@@mel.send] (* - external difference : other:'a t -> 'a t = "difference" [@@mel.send.pipe: 'a t] + external difference : other:'a t -> ('a t[@mel.this]) -> 'a t = "difference" [@@mel.send] - external intersection : other:'a t -> 'a t = "intersection" - [@@mel.send.pipe: 'a t] + external intersection : other:'a t -> ('a t[@mel.this]) -> 'a t = "intersection" + [@@mel.send] - external isDisjointFrom : other:'a t -> bool = "isDisjointFrom" - [@@mel.send.pipe: 'a t] + external isDisjointFrom : other:'a t -> ('a t[@mel.this]) -> bool = "isDisjointFrom" + [@@mel.send] - external isSubsetOf : other:'a t -> bool = "isSubsetOf" [@@mel.send.pipe: 'a t] + external isSubsetOf : other:'a t -> ('a t[@mel.this]) -> bool = "isSubsetOf" + [@@mel.send] - external isSupersetOf : other:'a t -> bool = "isSupersetOf" - [@@mel.send.pipe: 'a t] + external isSupersetOf : other:'a t -> ('a t[@mel.this]) -> bool = "isSupersetOf" + [@@mel.send] - external symmetricDifference : other:'a t -> 'a t = "symmetricDifference" - [@@mel.send.pipe: 'a t] + external symmetricDifference : other:'a t -> ('a t[@mel.this]) -> 'a t = "symmetricDifference" + [@@mel.send] - external union : other:'a t -> 'a t = "union" [@@mel.send.pipe: 'a t] *) + external union : other:'a t -> ('a t[@mel.this]) -> 'a t = "union" + [@@mel.send] +*) diff --git a/jscomp/runtime/js_weakmap.ml b/jscomp/runtime/js_weakmap.ml index 504ef00fe..214a5c0b1 100644 --- a/jscomp/runtime/js_weakmap.ml +++ b/jscomp/runtime/js_weakmap.ml @@ -27,10 +27,16 @@ type ('k, 'v) t external make : unit -> ('k, 'v) t = "WeakMap" [@@mel.new] -external get : key:'k Js.dict -> ('k, 'v) t -> 'v option = "get" [@@mel.send] -external has : key:'k Js.dict -> ('k, 'v) t -> bool = "has" [@@mel.send] -external set : key:'k Js.dict -> value:'v -> ('k, 'v) t -> ('k, 'v) t = "set" +external get : key:'k Js.dict -> (('k, 'v) t[@mel.this]) -> 'v option = "get" [@@mel.send] -external delete : key:'k Js.dict -> ('k, 'v) t -> bool = "delete" [@@mel.send] +external has : key:'k Js.dict -> (('k, 'v) t[@mel.this]) -> bool = "has" +[@@mel.send] + +external set : + key:'k Js.dict -> value:'v -> (('k, 'v) t[@mel.this]) -> ('k, 'v) t = "set" +[@@mel.send] + +external delete : key:'k Js.dict -> (('k, 'v) t[@mel.this]) -> bool = "delete" +[@@mel.send] diff --git a/jscomp/runtime/js_weakset.ml b/jscomp/runtime/js_weakset.ml index e7ddfc5f7..3fa138168 100644 --- a/jscomp/runtime/js_weakset.ml +++ b/jscomp/runtime/js_weakset.ml @@ -27,6 +27,12 @@ type 'a t external make : unit -> 'a t = "WeakSet" [@@mel.new] -external add : value:'a Js.dict -> 'a t -> 'a t = "add" [@@mel.send] -external delete : value:'a Js.dict -> 'a t -> bool = "delete" [@@mel.send] -external has : value:'a Js.dict -> 'a t -> bool = "has" [@@mel.send] + +external add : value:'a Js.dict -> ('a t[@mel.this]) -> 'a t = "add" +[@@mel.send] + +external delete : value:'a Js.dict -> ('a t[@mel.this]) -> bool = "delete" +[@@mel.send] + +external has : value:'a Js.dict -> ('a t[@mel.this]) -> bool = "has" +[@@mel.send]