Skip to content

Commit

Permalink
chore: port [@bs.*] attributes to [@mel.*] in runtime tests (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Sep 12, 2023
1 parent 4fa380a commit a017353
Show file tree
Hide file tree
Showing 190 changed files with 4,359 additions and 4,392 deletions.
30 changes: 15 additions & 15 deletions jscomp/test/arity_deopt.ml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
let suites : Mt.pair_suites ref = ref []
let test_id = ref 0
let eq loc x y =
incr test_id ;
suites :=
let eq loc x y =
incr test_id ;
suites :=
(loc ^" id " ^ (string_of_int !test_id), (fun _ -> Mt.Eq(x,y))) :: !suites


(* let f = fun x y *)

(* let [@bs] f x y = .. *)
(* let [@u] f x y = .. *)


(* let! f x y = *)
Expand All @@ -25,26 +25,26 @@ let eq loc x y =
(* return (x + y + z ) *)


let f0 = fun [@bs] x y -> fun z -> x + y + z
let f0 = fun [@u] x y -> fun z -> x + y + z
(* catch up. In OCaml we can not tell the difference from below
{[
let f = fun [@bs] x y z -> x + y + z
let f = fun [@u] x y z -> x + y + z
]}
*)
let f1 = fun x -> fun [@bs] y z -> x + y + z
let f1 = fun x -> fun [@u] y z -> x + y + z

let f2 = fun [@bs] x y -> let a = x in fun z -> a + y + z
let f2 = fun [@u] x y -> let a = x in fun z -> a + y + z

let f3 = fun x -> let a = x in fun [@bs] y z -> a + y + z
(* be careful! When you start optimize functions of [@bs], its call site invariant
let f3 = fun x -> let a = x in fun [@u] y z -> a + y + z
(* be careful! When you start optimize functions of [@u], its call site invariant
(Ml_app) will not hold any more.
So the best is never shrink functons which could change arity
*)
let () =
begin
eq __LOC__ 6 @@ f0 1 2 3 [@bs] ;
eq __LOC__ 6 @@ (f1 1 ) 2 3 [@bs];
eq __LOC__ 6 @@ ((f2 1 2 [@bs]) 3);
eq __LOC__ 6 @@ (f3 1 ) 2 3 [@bs]
begin
eq __LOC__ 6 @@ f0 1 2 3 [@u] ;
eq __LOC__ 6 @@ (f1 1 ) 2 3 [@u];
eq __LOC__ 6 @@ ((f2 1 2 [@u]) 3);
eq __LOC__ 6 @@ (f3 1 ) 2 3 [@u]
end
let () = Mt.from_pair_suites __MODULE__ !suites
8 changes: 4 additions & 4 deletions jscomp/test/arity_ml.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[@@@warning "A-61-42-40-70"]
let o = object [@bs]
let o = object [@u]
method hi x y = x + y
end
(* Error (warning 61): This primitive declaration uses type Js_OO.Callback.arity3, which is unannotated and
Expand All @@ -26,11 +26,11 @@ or [@@unboxed]. *)

(* let h u =
let m = u##hi in
m 1 2 [@bs]
m 1 2 [@u]
;; h (object [@bs] method hi x y =x + y end )
;; h (object [@u] method hi x y =x + y end )
Error: This expression has type < hi : (int -> int -> int [@bs.meth]) > Js.t
but an expression was expected of type
< hi : (int -> int -> 'a [@bs]); .. > Js.t
< hi : (int -> int -> 'a [@u]); .. > Js.t
Types for method hi are incompatible *)
2 changes: 1 addition & 1 deletion jscomp/test/ast_abstract_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let idb v =

let () = idb D0; idb D1; idb D2 ; idb D3
type c =
| D0 [@bs.as 3]
| D0 [@mel.as 3]
| D1
| D2
| D3
Expand Down
6 changes: 3 additions & 3 deletions jscomp/test/ast_js_mapper_poly_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let eq loc x y =
type u =
[ `D
| `C
| `f [@bs.as "x"]
| `f [@mel.as "x"]
]
[@@deriving jsConverter]

Expand All @@ -31,7 +31,7 @@ let () =

type v =
| A0
| A1 [@bs.as 3]
| A1 [@mel.as 3]
| A2
| A3
[@@deriving jsConverter]
Expand Down Expand Up @@ -70,7 +70,7 @@ let () =

(** TODO: add newType support *)
type v2 =
| C0 [@bs.as 2 ]
| C0 [@mel.as 2 ]
| C1
| C2
| C3
Expand Down
6 changes: 3 additions & 3 deletions jscomp/test/ast_js_mapper_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ let vx = tFromJs [%obj{ xx = 3; yy = "2"; zz = 1,2; cc = 3}]
(* type u =
[ `D
| `C
| `f [@bs.as "x"]
| `f [@mel.as "x"]
]
[@@bs.deriving jsConverter] *)
[@@deriving jsConverter] *)

let rec searchAux i (xs : (int * _) array) (k : int) =
let (a,b) = Array.unsafe_get xs i in
Expand All @@ -31,7 +31,7 @@ let searchForSureExists xs k =

type a =
| A0
| A1 [@bs.as 3]
| A1 [@mel.as 3]
| A2
| A3
and b =
Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/ast_mapper_defensive_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type a =
| A2
and b =
| B0
| B1 [@bs.as 3]
| B1 [@mel.as 3]
| B2
and c = [
| `c0
Expand Down
38 changes: 19 additions & 19 deletions jscomp/test/attr_test.ml
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@

let u = fun [@bs] x y -> x + y
let u = fun [@u] x y -> x + y

let h = u 1 2 [@bs]
let h = u 1 2 [@u]

type u = < v : int ; y : int >
type ('a,'b) xx =
(< case : (int -> (int -> 'a [@bs]) [@bs]); .. > as 'b)
type ('a,'b) xx_uncurry =
type u = < v : int ; y : int >
type ('a,'b) xx =
(< case : (int -> (int -> 'a [@u]) [@u]); .. > as 'b)
type ('a,'b) xx_uncurry =
(< case : int -> (int -> 'a ); .. > ) as 'b

type yy_uncurry = < x : int >
type yy = < x : int >
type yy_uncurry = < x : int >
type yy = < x : int >
type number = float

class type date =
class type date =
object
method toDateString : unit -> string
method getTime : unit -> number
method setMilliseconds : number -> number
method toDateString : unit -> string
method getTime : unit -> number
method setMilliseconds : number -> number
method setSeconds : number -> number
method setSeconds__2 : number -> number -> number
method setUTCFullYear__3 : number -> number -> number -> number
method toUTCString : unit -> string
method toISOString : unit -> string
method toJSON__ : unit -> string
method toJSON__ : unit -> string
method toJSON__1 : 'a -> string
end


let max2 : float -> float -> float [@bs] =
fun [@bs] x y -> x +. y
let max2 : float -> float -> float [@u] =
fun [@u] x y -> x +. y

let hh = max2 1. 2. [@bs]
let hh = max2 1. 2. [@u]

external des : string -> (unit -> unit [@bs.uncurry]) -> unit = "des" [@@bs.val]
external des : string -> (unit -> unit [@mel.uncurry]) -> unit = "des"

let f x =
des x (fun () -> Js.log "hei")
let f x =
des x (fun () -> Js.log "hei")
20 changes: 10 additions & 10 deletions jscomp/test/bang_primitive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ external log : 'a -> unit = "#console.log"
external log2 : 'a -> unit = "#console.log"
let f x =
let f x =
log x;
log2 x
log2 x
*)


external xx : 'a -> string = "#anything_to_string"
external xx : 'a -> string = "#anything_to_string"

external lt : 'a -> 'a -> bool = "#unsafe_lt"
external le : 'a -> 'a -> bool = "#unsafe_le"
Expand All @@ -35,14 +35,14 @@ external append : 'a array -> 'a array -> 'a array = "#array_append"
let f x y = append x y
*)

external of_small_int_array :
(_ [@bs.as {json|null|json}] ) ->
int array -> string =
"String.fromCharCode.apply"
[@@bs.val]
external of_small_int_array :
(_ [@bs.as {json|null|json}] ) ->
int array -> string =
"String.fromCharCode.apply"



let f x y =

let f x y =
of_small_int_array x, 0

18 changes: 9 additions & 9 deletions jscomp/test/bench.ml
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
let map f a =
let l = Array.length a in
if l = 0 then [||] else begin
let r = Array.make l (f(Array.unsafe_get a 0) [@bs]) in
let r = Array.make l (f(Array.unsafe_get a 0) [@u]) in
for i = 1 to l - 1 do
Array.unsafe_set r i (f(Array.unsafe_get a i) [@bs])
Array.unsafe_set r i (f(Array.unsafe_get a i) [@u])
done;
r
end

let map (type u ) (type v ) (f : u -> v) (a : u array)
: v array = map (fun [@bs] x -> f x ) a
: v array = map (fun [@u] x -> f x ) a

let init l f =
if l = 0 then [||] else
if l < 0 then invalid_arg "Array.init"
(* See #6575. We could also check for maximum array size, but this depends
on whether we create a float array or a regular one... *)
else
let res = Array.make l (f 0 [@bs]) in
let res = Array.make l (f 0 [@u]) in
for i = 1 to pred l do
Array.unsafe_set res i (f i [@bs])
Array.unsafe_set res i (f i [@u])
done;
res

let init l f = init l (fun [@bs] x -> f x)
let init l f = init l (fun [@u] x -> f x)

let fold_left f x a =
let r = ref x in
for i = 0 to Array.length a - 1 do
r := f !r (Array.unsafe_get a i) [@bs]
r := f !r (Array.unsafe_get a i) [@u]
done;
!r

let fold_left f x a = fold_left (fun [@bs] x y -> f x y ) x a
let fold_left f x a = fold_left (fun [@u] x y -> f x y ) x a


let f2 =
fun () ->
fun () ->
let arr = init 3_000_000 (fun i -> float_of_int i) in
let b = map (fun i -> i +. i -. 1. ) arr in
let v = fold_left (+.) 0. b in
Expand Down
20 changes: 10 additions & 10 deletions jscomp/test/bs_abstract_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let v = linked_list ~hd:3 ~tl:Js.null

;; tlSet v (Js.Null.return v)

type[@warning "-unused-type-declaration"] t = int -> int -> bool [@bs]
type[@warning "-unused-type-declaration"] t = int -> int -> bool [@u]
and x = {
k : t;
y : string
Expand All @@ -23,7 +23,7 @@ and x = {
let x0 k = x ~k ~y:"xx"
let x1 k = x ~k ~y:"xx"

let f = x ~k:(fun[@bs] x y -> x = y) ~y:"x"
let f = x ~k:(fun[@u] x y -> x = y) ~y:"x"

type u = {
x : int ;
Expand All @@ -38,16 +38,16 @@ let uf2 u = u |. y1Get 1 2

type u1 = {
x : int;
yyyy : (int -> int [@bs]);
yyyy1 : (int -> int -> int [@bs]);
yyyy2 : (int -> int) option [@bs.optional]
yyyy : (int -> int [@u]);
yyyy1 : (int -> int -> int [@u]);
yyyy2 : (int -> int) option [@mel.optional]
} [@@deriving abstract]

let uff f =
(f |. yyyyGet) 1 [@bs]
(f |. yyyyGet) 1 [@u]

let uff2 f =
(f |. yyyy1Get) 1 2 [@bs]
(f |. yyyy1Get) 1 2 [@u]

let uff3 f =
match f |. yyyy2Get with
Expand All @@ -58,9 +58,9 @@ let uff3 f =

type u3 = {
x : int;
yyyy : (int -> int [@bs]);
yyyy1 : (int -> int -> int [@bs]);
yyyy2 : (int -> int) option [@bs.optional]
yyyy : (int -> int [@u]);
yyyy1 : (int -> int -> int [@u]);
yyyy2 : (int -> int) option [@mel.optional]
} [@@deriving abstract { light} ]


Expand Down
2 changes: 1 addition & 1 deletion jscomp/test/bs_abstract_test.mli
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mutable tl : 'a linked_list Js.null



type t = int -> int -> bool [@bs]
type t = int -> int -> bool [@u]
and x = private {
k : t;
y : string
Expand Down
Loading

0 comments on commit a017353

Please sign in to comment.