Skip to content

Commit 7163f0c

Browse files
committed
sync latest parser
1 parent 82192fb commit 7163f0c

16 files changed

+280
-151
lines changed

analysis/vendor/ext/config.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ let bs_only = ref true
1313

1414
let unsafe_empty_array = ref false
1515

16-
let use_automatic_curried_application = ref false
16+
type uncurried = Legacy | Uncurried | Swap
17+
let uncurried = ref Legacy
1718

1819
and cmi_magic_number = "Caml1999I022"
1920

analysis/vendor/ext/config.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ val cmt_magic_number : string
4747

4848
val print_config : out_channel -> unit
4949

50-
val use_automatic_curried_application : bool ref
50+
type uncurried = Legacy | Uncurried | Swap
51+
val uncurried : uncurried ref

analysis/vendor/ml/ctype.ml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,9 +2341,6 @@ let rec unify (env:Env.t ref) t1 t2 =
23412341
with Cannot_expand ->
23422342
unify2 env t1 t2
23432343
end
2344-
| (Tconstr (Pident {name="function$"}, [tFun; _], _), Tarrow _) when !Config.use_automatic_curried_application ->
2345-
(* subtype: an uncurried function is cast to a curried one *)
2346-
unify2 env tFun t2
23472344
| _ ->
23482345
unify2 env t1 t2
23492346
end;
@@ -2399,6 +2396,9 @@ and unify3 env t1 t1' t2 t2' =
23992396
link_type t2' t1;
24002397
| (Tfield _, Tfield _) -> (* special case for GADTs *)
24012398
unify_fields env t1' t2'
2399+
| (Tconstr (Pident {name="function$"}, [tFun; _], _), Tarrow _) when !Config.uncurried = Uncurried ->
2400+
(* subtype: an uncurried function is cast to a curried one *)
2401+
unify2 env tFun t2
24022402
| _ ->
24032403
begin match !umode with
24042404
| Expression ->
@@ -3951,7 +3951,33 @@ let rec subtype_rec env trace t1 t2 cstrs =
39513951
end
39523952
| (Tconstr(p1, _, _), _) when generic_private_abbrev env p1 ->
39533953
subtype_rec env trace (expand_abbrev_opt env t1) t2 cstrs
3954-
(* | (_, Tconstr(p2, _, _)) when generic_private_abbrev false env p2 ->
3954+
| (Tconstr(_, [], _), Tconstr(_, [], _)) -> (* type coercion for records *)
3955+
(match extract_concrete_typedecl env t1, extract_concrete_typedecl env t2 with
3956+
| (_, _, {type_kind=Type_record (fields1, repr1)}), (_, _, {type_kind=Type_record (fields2, repr2)}) ->
3957+
let field_is_optional id repr = match repr with
3958+
| Record_optional_labels lbls -> List.mem (Ident.name id) lbls
3959+
| _ -> false in
3960+
let violation = ref false in
3961+
let label_decl_sub (acc1, acc2) ld2 =
3962+
match fields1 |> List.find_opt (fun ld1 -> Ident.name ld1.ld_id = Ident.name ld2.ld_id) with
3963+
| Some ld1 ->
3964+
if field_is_optional ld1.ld_id repr1 && not (field_is_optional ld2.ld_id repr2) then
3965+
(* optional field can't be cast to non-optional one *)
3966+
violation := true;
3967+
ld1.ld_type :: acc1, ld2.ld_type :: acc2
3968+
| None ->
3969+
(* field must be present *)
3970+
violation := true;
3971+
(acc1, acc2) in
3972+
let tl1, tl2 = List.fold_left label_decl_sub ([], []) fields2 in
3973+
if !violation
3974+
then (trace, t1, t2, !univar_pairs)::cstrs
3975+
else
3976+
subtype_list env trace tl1 tl2 cstrs
3977+
| _ -> (trace, t1, t2, !univar_pairs)::cstrs
3978+
| exception Not_found -> (trace, t1, t2, !univar_pairs)::cstrs
3979+
)
3980+
(* | (_, Tconstr(p2, _, _)) when generic_private_abbrev false env p2 ->
39553981
subtype_rec env trace t1 (expand_abbrev_opt env t2) cstrs *)
39563982
| (Tobject (f1, _), Tobject (f2, _))
39573983
when is_Tvar (object_row f1) && is_Tvar (object_row f2) ->

analysis/vendor/ml/typecore.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2980,7 +2980,7 @@ and type_argument ?recarg env sarg ty_expected' ty_expected =
29802980
texp
29812981
and is_automatic_curried_application env funct =
29822982
(* When a curried function is used with uncurried application, treat it as a curried application *)
2983-
!Config.use_automatic_curried_application &&
2983+
!Config.uncurried = Uncurried &&
29842984
match (expand_head env funct.exp_type).desc with
29852985
| Tarrow _ -> true
29862986
| _ -> false

analysis/vendor/res_syntax/reactjs_jsx_v3.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ let jsxMapper ~config =
597597
match List.filter React_jsx_common.hasAttr pval_attributes with
598598
| [] -> [item]
599599
| [_] ->
600+
let pval_type = React_jsx_common.extractUncurried pval_type in
600601
let rec getPropTypes types ({ptyp_loc; ptyp_desc} as fullType) =
601602
match ptyp_desc with
602603
| Ptyp_arrow (name, type_, ({ptyp_desc = Ptyp_arrow _} as rest))
@@ -648,6 +649,7 @@ let jsxMapper ~config =
648649
let emptyLoc = Location.in_file fileName in
649650
let mapBinding binding =
650651
if React_jsx_common.hasAttrOnBinding binding then
652+
let binding = React_jsx_common.removeArity binding in
651653
let bindingLoc = binding.pvb_loc in
652654
let bindingPatLoc = binding.pvb_pat.ppat_loc in
653655
let binding =
@@ -957,6 +959,13 @@ let jsxMapper ~config =
957959
}
958960
innerExpressionWithRef
959961
in
962+
let fullExpression =
963+
if !Config.uncurried = Uncurried then
964+
fullExpression
965+
|> Ast_uncurried.uncurriedFun ~loc:fullExpression.pexp_loc
966+
~arity:1
967+
else fullExpression
968+
in
960969
let fullExpression =
961970
match fullModuleName with
962971
| "" -> fullExpression
@@ -1031,6 +1040,7 @@ let jsxMapper ~config =
10311040
match List.filter React_jsx_common.hasAttr pval_attributes with
10321041
| [] -> [item]
10331042
| [_] ->
1043+
let pval_type = React_jsx_common.extractUncurried pval_type in
10341044
let rec getPropTypes types ({ptyp_loc; ptyp_desc} as fullType) =
10351045
match ptyp_desc with
10361046
| Ptyp_arrow (name, type_, ({ptyp_desc = Ptyp_arrow _} as rest))

analysis/vendor/res_syntax/reactjs_jsx_v4.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,12 @@ let mapBinding ~config ~emptyLoc ~pstr_loc ~fileName ~recFlag binding =
952952
innerExpression
953953
else innerExpression)
954954
in
955+
let fullExpression =
956+
if !Config.uncurried = Uncurried then
957+
fullExpression
958+
|> Ast_uncurried.uncurriedFun ~loc:fullExpression.pexp_loc ~arity:1
959+
else fullExpression
960+
in
955961
let fullExpression =
956962
match fullModuleName with
957963
| "" -> fullExpression

0 commit comments

Comments
 (0)