Skip to content

Commit dab2a95

Browse files
committed
sync latest syntax
1 parent cbc9312 commit dab2a95

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

analysis/vendor/ml/ast_uncurried.ml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(* Untyped AST *)
1+
(* Uncurried AST *)
22

33

44
let encode_arity_string arity = "Has_arity" ^ string_of_int arity
@@ -50,7 +50,7 @@ let rec attributes_to_arity (attrs : Parsetree.attributes) =
5050
let uncurriedFun ~loc ~arity funExpr =
5151
Ast_helper.Exp.construct ~loc
5252
~attrs:(arity_to_attributes arity)
53-
{ txt = Lident "Function$"; loc }
53+
(Location.mknoloc (Longident.Lident "Function$"))
5454
(Some funExpr)
5555

5656
let exprIsUncurriedFun (expr : Parsetree.expression) =
@@ -63,12 +63,19 @@ let exprExtractUncurriedFun (expr : Parsetree.expression) =
6363
| Pexp_construct ({ txt = Lident "Function$" }, Some e) -> e
6464
| _ -> assert false
6565

66-
let typeIsUncurriedFun (typ : Parsetree.core_type) =
66+
let coreTypeIsUncurriedFun (typ : Parsetree.core_type) =
6767
match typ.ptyp_desc with
6868
| Ptyp_constr ({txt = Lident "function$"}, [{ptyp_desc = Ptyp_arrow _}; _]) ->
6969
true
7070
| _ -> false
7171

72+
let typeIsUncurriedFun (typ : Types.type_expr) =
73+
match typ.desc with
74+
| Tconstr (Pident {name = "function$"}, [{desc = Tarrow _}; _], _) ->
75+
true
76+
| _ -> false
77+
78+
7279
let typeExtractUncurriedFun (typ : Parsetree.core_type) =
7380
match typ.ptyp_desc with
7481
| Ptyp_constr ({txt = Lident "function$"}, [tArg; tArity]) ->
@@ -106,3 +113,9 @@ let uncurried_type_get_arity ~env typ =
106113
| Tconstr (Pident { name = "function$" }, [ _t; tArity ], _) ->
107114
type_to_arity tArity
108115
| _ -> assert false
116+
117+
let uncurried_type_get_arity_opt ~env typ =
118+
match (Ctype.expand_head env typ).desc with
119+
| Tconstr (Pident { name = "function$" }, [ _t; tArity ], _) ->
120+
Some (type_to_arity tArity)
121+
| _ -> None

analysis/vendor/res_syntax/react_jsx_common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let raiseErrorMultipleReactComponent ~loc =
4545
let optionalAttr = ({txt = "res.optional"; loc = Location.none}, PStr [])
4646

4747
let extractUncurried typ =
48-
if Ast_uncurried.typeIsUncurriedFun typ then
48+
if Ast_uncurried.coreTypeIsUncurriedFun typ then
4949
let _arity, t = Ast_uncurried.typeExtractUncurriedFun typ in
5050
t
5151
else typ

analysis/vendor/res_syntax/res_outcome_printer.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,9 @@ let rec printOutTypeDoc (outType : Outcometree.out_type) =
217217
->
218218
(* function$<(int, int) => int, [#2]> -> (. int, int) => int *)
219219
printOutArrowType ~uncurried:true arrowType
220+
| Otyp_constr (Oide_ident "function$", [Otyp_var _; _arity]) ->
221+
(* function$<'a, arity> -> _ => _ *)
222+
printOutTypeDoc (Otyp_stuff "_ => _")
220223
| Otyp_constr (outIdent, []) -> printOutIdentDoc ~allowUident:false outIdent
221224
| Otyp_manifest (typ1, typ2) ->
222225
Doc.concat [printOutTypeDoc typ1; Doc.text " = "; printOutTypeDoc typ2]

analysis/vendor/res_syntax/res_parens.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ let includeModExpr modExpr =
442442
let arrowReturnTypExpr typExpr =
443443
match typExpr.Parsetree.ptyp_desc with
444444
| Parsetree.Ptyp_arrow _ -> true
445-
| _ when Ast_uncurried.typeIsUncurriedFun typExpr -> true
445+
| _ when Ast_uncurried.coreTypeIsUncurriedFun typExpr -> true
446446
| _ -> false
447447

448448
let patternRecordRowRhs (pattern : Parsetree.pattern) =

analysis/vendor/res_syntax/res_printer.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl =
15911591
let doc = printTypExpr ~state n cmtTbl in
15921592
match n.ptyp_desc with
15931593
| Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ -> addParens doc
1594-
| _ when Ast_uncurried.typeIsUncurriedFun n -> addParens doc
1594+
| _ when Ast_uncurried.coreTypeIsUncurriedFun n -> addParens doc
15951595
| _ -> doc
15961596
in
15971597
Doc.group
@@ -1652,7 +1652,7 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl =
16521652
let needsParens =
16531653
match typ.ptyp_desc with
16541654
| Ptyp_arrow _ -> true
1655-
| _ when Ast_uncurried.typeIsUncurriedFun typ -> true
1655+
| _ when Ast_uncurried.coreTypeIsUncurriedFun typ -> true
16561656
| _ -> false
16571657
in
16581658
let doc = printTypExpr ~state typ cmtTbl in
@@ -1664,7 +1664,7 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl =
16641664
| Ptyp_object (fields, openFlag) ->
16651665
printObject ~state ~inline:false fields openFlag cmtTbl
16661666
| Ptyp_arrow _ -> printArrow ~uncurried:false typExpr
1667-
| Ptyp_constr _ when Ast_uncurried.typeIsUncurriedFun typExpr ->
1667+
| Ptyp_constr _ when Ast_uncurried.coreTypeIsUncurriedFun typExpr ->
16681668
let arity, tArg = Ast_uncurried.typeExtractUncurriedFun typExpr in
16691669
printArrow ~uncurried:true ~arity tArg
16701670
| Ptyp_constr (longidentLoc, [{ptyp_desc = Ptyp_object (fields, openFlag)}])
@@ -4018,7 +4018,7 @@ and printPexpApply ~state expr cmtTbl =
40184018
argsDoc;
40194019
]
40204020
else
4021-
let argsDoc = printArguments ~state ~dotted args cmtTbl in
4021+
let argsDoc = printArguments ~state ~dotted ~partial args cmtTbl in
40224022
Doc.concat [printAttributes ~state attrs cmtTbl; callExprDoc; argsDoc]
40234023
| _ -> assert false
40244024

@@ -4524,7 +4524,7 @@ and printArgumentsWithCallbackInLastPosition ~state ~dotted args cmtTbl =
45244524
Lazy.force breakAllArgs;
45254525
]
45264526

4527-
and printArguments ~state ~dotted
4527+
and printArguments ~state ~dotted ?(partial = false)
45284528
(args : (Asttypes.arg_label * Parsetree.expression) list) cmtTbl =
45294529
match args with
45304530
| [
@@ -4564,7 +4564,7 @@ and printArguments ~state ~dotted
45644564
~sep:(Doc.concat [Doc.comma; Doc.line])
45654565
(List.map (fun arg -> printArgument ~state arg cmtTbl) args);
45664566
]);
4567-
Doc.trailingComma;
4567+
(if partial then Doc.nil else Doc.trailingComma);
45684568
Doc.softLine;
45694569
Doc.rparen;
45704570
])

0 commit comments

Comments
 (0)