Skip to content

Commit

Permalink
Fix arity of inner functions.
Browse files Browse the repository at this point in the history
The parser gives arity to inner functions while it should only give it to the toplevel for a nested function.
E.g. (x,y) => x+y should give toplevel arity 2, and no inner arity 1
  • Loading branch information
cristianoc committed Dec 12, 2024
1 parent 3ca735a commit 2423ad0
Show file tree
Hide file tree
Showing 29 changed files with 149 additions and 193 deletions.
4 changes: 2 additions & 2 deletions compiler/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1596,8 +1596,8 @@ and parse_es6_arrow_expression ?(arrow_attrs = []) ?(arrow_start_pos = None)
{attrs; label = lbl; expr = default_expr; pat; pos = start_pos} ->
let loc = mk_loc start_pos end_pos in
let fun_expr =
Ast_helper.Exp.fun_ ~loc ~attrs ~arity:(Some arity) lbl default_expr
pat expr
Ast_helper.Exp.fun_ ~loc ~attrs ~arity:None lbl default_expr pat
expr
in
if term_param_num = 1 then
( term_param_num - 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
;;(Object.keys providers).reduce
(Function$
(fun [arity:2]elements ->
fun [arity:1]providerId -> ((let x = 1 in let b = 2 in x + b)
[@res.braces ])))
fun providerId -> ((let x = 1 in let b = 2 in x + b)[@res.braces ])))
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@
let findThreadByIdLinearScan =
Function$
(fun [arity:2]~threads:((threads)[@res.namedArgLoc ]) ->
fun [arity:1]~id:((id)[@res.namedArgLoc ]) ->
fun ~id:((id)[@res.namedArgLoc ]) ->
((Js.Array2.findi ThreadsModel.threads
(Function$
(fun [arity:2]thread ->
fun [arity:1]i ->
fun i ->
((let thisId =
match thread with
| ServerData.OneToOne
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@

consecutive expressions on a line must be separated by ';' or a newline

let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> a + 3)
let f = Function$ (fun [arity:2]a -> fun b -> a + 3)
;;b
let f =
Function$ (fun [arity:2]g -> fun [arity:1]h -> ((a + 3; b)[@res.braces ]))
let f = Function$ (fun [arity:2]g -> fun h -> ((a + 3; b)[@res.braces ]))
let () = ((sideEffect1 (); sideEffect2 ())[@res.braces ])
let () = ((let open Foo in let exception End in x ())[@res.braces ])
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
let x = { }
let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> { })
let f = Function$ (fun [arity:2]a -> fun b -> { })
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@

A labeled parameter starts with a `~`. Did you mean: `~x`?

let f =
Function$
(fun [arity:3]x -> fun [arity:2]?(y= 2) -> fun [arity:1]z -> (x + y) + z)
let f = Function$ (fun [arity:3]x -> fun ?(y= 2) -> fun z -> (x + y) + z)
let g =
Function$
(fun [arity:3]~x:((x)[@res.namedArgLoc ]) ->
fun [arity:2]?y:(((y)[@res.namedArgLoc ])= 2) ->
fun [arity:1]~z:((z)[@res.namedArgLoc ]) -> (x + y) + z)
fun ?y:(((y)[@res.namedArgLoc ])= 2) ->
fun ~z:((z)[@res.namedArgLoc ]) -> (x + y) + z)
type nonrec f = (x:int -> y:int -> int, [ `Has_arity2 ]) function$
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module ClientSet =
let cmp =
Function$
(fun [arity:2]a ->
fun [arity:1]b ->
fun b ->
((compare
(a |.u Client.getUniqueId)
(b |.u Client.getUniqueId))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[@@@uncurried ]
let foo = Function$ (fun [arity:2]x -> fun [arity:1]y -> x + y)
let foo = Function$ (fun [arity:2]x -> fun y -> x + y)
let z = foo 3 4
let bar = Function$ (fun [arity:2]x -> fun [arity:1]y -> x + y)
let bar = Function$ (fun [arity:2]x -> fun y -> x + y)
let b = bar 3 4
let w = 3 |.u (foo 4)
let a = 3 |.u (foo 4)
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ let uFun = Function$ (fun [arity:1]x -> 3)
let mixFun =
Function$
(fun [arity:3]a ->
fun [arity:2]b ->
fun [arity:1]c ->
fun b ->
fun c ->
Function$
(fun [arity:3]d ->
fun [arity:2]e ->
fun [arity:1]f ->
Function$ (fun [arity:2]g -> fun [arity:1]h -> 4)))
fun e -> fun f -> Function$ (fun [arity:2]g -> fun h -> 4)))
let bracesFun =
Function$ (fun [arity:1]x -> Function$ (fun [arity:1]y -> x + y))
let cFun2 = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3)
let uFun2 = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3)
let cFun2 = Function$ (fun [arity:2]x -> fun y -> 3)
let uFun2 = Function$ (fun [arity:2]x -> fun y -> 3)
type nonrec cTyp = (string -> int, [ `Has_arity1 ]) function$
type nonrec uTyp = (string -> int, [ `Has_arity1 ]) function$
type nonrec mixTyp =
Expand Down Expand Up @@ -77,19 +75,19 @@ let _ = Function$ ((fun [arity:1]x -> 34)[@res.async ][@att ])
let _ = preserveAttr (Function$ ((fun [arity:1]x -> 34)[@att ]))
let _ = preserveAttr (Function$ ((fun [arity:1]x -> 34)[@res.async ][@att ]))
let t0 (type a) (type b) =
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
let t1 (type a) (type b) =
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
let t2 (type a) (type b) =
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
let t3 (type a) (type b) =
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
let t4 (type a) (type b) =
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
let t5 (type a) (type b) =
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
let t6 (type a) (type b) =
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
type nonrec arrowPath1 = (int -> string, [ `Has_arity1 ]) function$
type nonrec arrowPath2 = (I.t -> string, [ `Has_arity1 ]) function$
type nonrec arrowPath3 = (int -> string, [ `Has_arity1 ]) function$
Expand All @@ -109,18 +107,18 @@ let mixFun =
(fun [arity:1]a ->
Function$
(fun [arity:2]b ->
fun [arity:1]c ->
fun c ->
Function$
(fun [arity:3]d ->
fun [arity:2]e ->
fun [arity:1]f ->
fun e ->
fun f ->
Function$
(fun [arity:1]g -> Function$ (fun [arity:1]h -> 4)))))
let bracesFun =
Function$ (fun [arity:1]x -> Function$ (fun [arity:1]y -> x + y))
let cFun2 = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3)
let uFun2 = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3)
let cFun2Dots = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3)
let cFun2 = Function$ (fun [arity:2]x -> fun y -> 3)
let uFun2 = Function$ (fun [arity:2]x -> fun y -> 3)
let cFun2Dots = Function$ (fun [arity:2]x -> fun y -> 3)
type nonrec cTyp = (string -> int, [ `Has_arity1 ]) function$
type nonrec uTyp = (string -> int, [ `Has_arity1 ]) function$
type nonrec mixTyp =
Expand Down Expand Up @@ -184,13 +182,13 @@ let _ = Function$ ((fun [arity:1]x -> 34)[@res.async ][@att ])
let _ = preserveAttr (Function$ ((fun [arity:1]x -> 34)[@att ]))
let _ = preserveAttr (Function$ ((fun [arity:1]x -> 34)[@res.async ][@att ]))
let t0 (type a) (type b) =
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
let t1 (type a) (type b) =
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
let t2 (type a) (type b) =
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
let t3 (type a) (type b) =
Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l)
Function$ (fun [arity:2](l : a list) -> fun (x : a) -> x :: l)
type nonrec arrowPath1 = (int -> string, [ `Has_arity1 ]) function$
type nonrec arrowPath2 = (I.t -> string, [ `Has_arity1 ]) function$
type nonrec arrowPath3 = (int -> string, [ `Has_arity1 ]) function$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
;;foo (Function$ (fun [arity:1]_ -> bla))
(Function$ (fun [arity:1]_ -> blaz))
;;List.map (Function$ (fun [arity:1]x -> x + 1)) myList
;;List.reduce
(Function$ (fun [arity:2]acc -> fun [arity:1]curr -> acc + curr)) 0
;;List.reduce (Function$ (fun [arity:2]acc -> fun curr -> acc + curr)) 0
myList
let unitUncurried = apply ()
;;call ~a:(((((a)[@res.namedArgLoc ]) : int))[@res.namedArgLoc ])
Original file line number Diff line number Diff line change
Expand Up @@ -3,99 +3,85 @@ let f = Function$ (fun [arity:1]_ -> Js.log {js|test|js})
let f = Function$ (fun [arity:1]() -> Js.log {js|unit|js})
let f = Function$ (fun [arity:1](Reducer (inst, comp)) -> inst.render comp)
let f = Function$ (fun [arity:1](Instance) -> ())
let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> a + b)
let f = Function$ (fun [arity:2]1 -> fun [arity:1]2 -> ())
let f = Function$ (fun [arity:2]a -> fun b -> a + b)
let f = Function$ (fun [arity:2]1 -> fun 2 -> ())
let f = Function$ (fun [arity:1]{js|stringPattern|js} -> ())
let f =
Function$
(fun [arity:2]{js|stringPattern|js} ->
fun [arity:1]{js|stringPattern|js} -> ())
(fun [arity:2]{js|stringPattern|js} -> fun {js|stringPattern|js} -> ())
let f = Function$ (fun [arity:1]() -> ())
let f = Function$ (fun [arity:2](a : int) -> fun [arity:1](b : int) -> a + b)
let f = Function$ (fun [arity:2]_ -> fun [arity:1]_ -> ())
let f =
Function$
(fun [arity:2][|a;b|] -> fun [arity:1][|c;d|] -> ((a + b) + c) + d)
let f = Function$ (fun [arity:2](a : int) -> fun (b : int) -> a + b)
let f = Function$ (fun [arity:2]_ -> fun _ -> ())
let f = Function$ (fun [arity:2][|a;b|] -> fun [|c;d|] -> ((a + b) + c) + d)
let f = Function$ (fun [arity:1]{ a } -> a + 1)
let f =
Function$
(fun [arity:2]{ a; b } -> fun [arity:1]{ c; d } -> ((a + b) + c) + d)
Function$ (fun [arity:2]{ a; b } -> fun { c; d } -> ((a + b) + c) + d)
let f = Function$ (fun [arity:1](a, b) -> a + b)
let f =
Function$ (fun [arity:2](a, b) -> fun [arity:1](c, d) -> ((a + b) + c) + d)
let f = Function$ (fun [arity:2](a, b) -> fun (c, d) -> ((a + b) + c) + d)
let f = Function$ (fun [arity:1]exception Terminate -> ())
let f =
Function$
(fun [arity:2]exception Terminate -> fun [arity:1]exception Exit -> ())
Function$ (fun [arity:2]exception Terminate -> fun exception Exit -> ())
let f = Function$ (fun [arity:1][] -> ())
let f = Function$ (fun [arity:1](x::xs) -> x + (xs |.u Belt.List.length))
let f = Function$ (fun [arity:2](x : int) -> fun [arity:1](y : int) -> x + y)
let f = Function$ (fun [arity:2](x : int) -> fun (y : int) -> x + y)
let f =
Function$
(fun [arity:2]~a:((a)[@res.namedArgLoc ]) ->
fun [arity:1]~b:((b)[@res.namedArgLoc ]) -> a + b)
fun ~b:((b)[@res.namedArgLoc ]) -> a + b)
let f =
Function$
(fun [arity:2]~a:((x)[@res.namedArgLoc ]) ->
fun [arity:1]~b:((y)[@res.namedArgLoc ]) -> x + y)
fun ~b:((y)[@res.namedArgLoc ]) -> x + y)
let f =
Function$
(fun [arity:2]~a:(((x : int))[@res.namedArgLoc ]) ->
fun [arity:1]~b:(((y : int))[@res.namedArgLoc ]) -> x + y)
fun ~b:(((y : int))[@res.namedArgLoc ]) -> x + y)
let f =
Function$
(fun [arity:3]?a:(((a)[@res.namedArgLoc ])= 1) ->
fun [arity:2]?b:(((b)[@res.namedArgLoc ])= 2) ->
fun [arity:1]c -> (a + b) + c)
fun ?b:(((b)[@res.namedArgLoc ])= 2) -> fun c -> (a + b) + c)
let f =
Function$
(fun [arity:3]?a:(((x)[@res.namedArgLoc ])= 1) ->
fun [arity:2]?b:(((y)[@res.namedArgLoc ])= 2) ->
fun [arity:1]c -> (x + y) + c)
fun ?b:(((y)[@res.namedArgLoc ])= 2) -> fun c -> (x + y) + c)
let f =
Function$
(fun [arity:3]?a:((((x : int))[@res.namedArgLoc ])= 1) ->
fun [arity:2]?b:((((y : int))[@res.namedArgLoc ])= 2) ->
fun [arity:1]c -> (x + y) + c)
fun ?b:((((y : int))[@res.namedArgLoc ])= 2) -> fun c -> (x + y) + c)
let f =
Function$
(fun [arity:3]?a:((a)[@res.namedArgLoc ]) ->
fun [arity:2]?b:((b)[@res.namedArgLoc ]) ->
fun [arity:1]c ->
fun ?b:((b)[@res.namedArgLoc ]) ->
fun c ->
match (a, b) with | (Some a, Some b) -> (a + b) + c | _ -> 3)
let f =
Function$
(fun [arity:3]?a:((x)[@res.namedArgLoc ]) ->
fun [arity:2]?b:((y)[@res.namedArgLoc ]) ->
fun [arity:1]c ->
fun ?b:((y)[@res.namedArgLoc ]) ->
fun c ->
match (x, y) with | (Some a, Some b) -> (a + b) + c | _ -> 3)
let f =
Function$
(fun [arity:3]?a:(((x : int option))[@res.namedArgLoc ]) ->
fun [arity:2]?b:(((y : int option))[@res.namedArgLoc ]) ->
fun [arity:1]c ->
fun ?b:(((y : int option))[@res.namedArgLoc ]) ->
fun c ->
match (x, y) with | (Some a, Some b) -> (a + b) + c | _ -> 3)
let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> a + b)
let f = Function$ (fun [arity:2]a -> fun b -> a + b)
let f = Function$ (fun [arity:1]() -> ())
let f = Function$ (fun [arity:1]() -> ())
let f = Function$ (fun [arity:3]a -> fun [arity:2]b -> fun [arity:1]c -> ())
let f =
Function$
(fun [arity:4]a ->
fun [arity:3]b -> fun [arity:2]c -> fun [arity:1]d -> ())
let f = Function$ (fun [arity:3]a -> fun [arity:2]b -> fun [arity:1]c -> ())
let f = Function$ (fun [arity:3]a -> fun b -> fun c -> ())
let f = Function$ (fun [arity:4]a -> fun b -> fun c -> fun d -> ())
let f = Function$ (fun [arity:3]a -> fun b -> fun c -> ())
let f =
Function$
(fun [arity:4]~a:((a)[@res.namedArgLoc ][@attr ]) ->
fun [arity:3]b ->
fun [arity:2]~c:((c)[@res.namedArgLoc ][@attr ]) ->
fun [arity:1]d -> ())
fun b -> fun ~c:((c)[@res.namedArgLoc ][@attr ]) -> fun d -> ())
let f =
Function$
(fun [arity:4]~a:((a)[@res.namedArgLoc ][@attr ]) ->
fun [arity:3]((b)[@attrOnB ]) ->
fun [arity:2]~c:((c)[@res.namedArgLoc ][@attr ]) ->
fun [arity:1]((d)[@attrOnD ]) -> ())
fun ((b)[@attrOnB ]) ->
fun ~c:((c)[@res.namedArgLoc ][@attr ]) ->
fun ((d)[@attrOnD ]) -> ())
let f = Function$ (fun [arity:1]list -> list ())
;;match colour with
| Red when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,9 @@ let async =
[@res.braces ])
let f =
((if isPositive
then
Function$ ((fun [arity:2]a -> fun [arity:1]b -> (a + b : int))
[@res.async ])
then Function$ ((fun [arity:2]a -> fun b -> (a + b : int))[@res.async ])
else
Function$ (((fun [arity:2]c -> fun [arity:1]d -> (c - d : int)))
[@res.async ]))
Function$ (((fun [arity:2]c -> fun d -> (c - d : int)))[@res.async ]))
[@res.ternary ])
let foo = async ~a:((34)[@res.namedArgLoc ])
let bar =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ let reifyStyle (type a) =
let calc_fps =
Function$
(fun [arity:2]t0 ->
fun [arity:1]t1 -> ((let delta = (t1 -. t0) /. 1000. in 1. /. delta)
fun t1 -> ((let delta = (t1 -. t0) /. 1000. in 1. /. delta)
[@res.braces ]))
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ let numbers = [three; (module struct let x = 4 end)]
let plus =
Function$
(fun [arity:2]m1 ->
fun [arity:1]m2 -> ((((module
fun m2 -> ((((module
struct let x = (to_int m1) + (to_int m2) end) : (module X_int)))
[@res.braces ]))
let plus =
Function$
(fun [arity:2]m1 ->
fun [arity:1]m2 -> ((module
fun m2 -> ((module
struct let x = (to_int m1) + (to_int m2) end) : (module X_int)))
let unique_instance = ((module
struct module Query_handler = Unique
Expand All @@ -31,15 +31,15 @@ let build_instance (type a) =
Function$
(fun [arity:2]((module Q) : (module Query_handler with type config = a))
->
fun [arity:1]config -> ((module
fun config -> ((module
struct module Query_handler = Q
let this = Q.create config end) : (module
Query_handler_instance)))
let build_instance (type a) =
Function$
(fun [arity:2]((module Q) : (module Query_handler with type config = a))
->
fun [arity:1]config -> ((((module
fun config -> ((((module
struct module Query_handler = Q
let this = Q.create config end) : (module
Query_handler_instance)))
Expand Down
Loading

0 comments on commit 2423ad0

Please sign in to comment.