Skip to content

Commit

Permalink
Remove support for total application with curried function.
Browse files Browse the repository at this point in the history
There should be no curried functions left.
  • Loading branch information
cristianoc committed Dec 19, 2024
1 parent c3d92a9 commit df8a5e8
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions compiler/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2424,17 +2424,16 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
end_def ();
wrap_trace_gadt_instances env (lower_args env []) ty;
begin_def ();
let uncurried =
let total_app =
not
@@ Ext_list.exists sexp.pexp_attributes (fun ({txt}, _) ->
txt = "res.partial")
&& (not @@ is_automatic_curried_application env funct)
in
let type_clash_context = type_clash_context_from_function sexp sfunct in
let args, ty_res, fully_applied =
match translate_unified_ops env funct sargs with
| Some (targs, result_type) -> (targs, result_type, true)
| None -> type_application ?type_clash_context uncurried env funct sargs
| None -> type_application ?type_clash_context total_app env funct sargs
in
end_def ();
unify_var env (newvar ()) funct.exp_type;
Expand Down Expand Up @@ -3414,12 +3413,6 @@ and type_argument ?type_clash_context ?recarg env sarg ty_expected' ty_expected
unify_exp ?type_clash_context env texp ty_expected;
texp
and is_automatic_curried_application env funct =
(* When a curried function is used with uncurried application, treat it as a curried application *)
match (expand_head env funct.exp_type).desc with
| Tarrow _ -> true
| _ -> false
(** This is ad-hoc translation for unifying specific primitive operations
See [Unified_ops] module for detailed explanation.
*)
Expand Down Expand Up @@ -3515,7 +3508,7 @@ and translate_unified_ops (env : Env.t) (funct : Typedtree.expression)
| _ -> None)
| _ -> None
and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
and type_application ?type_clash_context total_app env funct (sargs : sargs) :
targs * Types.type_expr * bool =
let result_type omitted ty_fun =
List.fold_left
Expand All @@ -3530,7 +3523,7 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
let force_tvar =
let t = funct.exp_type in
match (expand_head env t).desc with
| Tvar _ when uncurried -> true
| Tvar _ when total_app -> true
| _ -> false
in
let has_uncurried_type funct =
Expand Down Expand Up @@ -3578,7 +3571,7 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
| Some (arity, _) ->
let newarity = arity - nargs in
let fully_applied = newarity <= 0 in
if uncurried && not fully_applied then
if total_app && not fully_applied then
raise
(Error
( funct.exp_loc,
Expand All @@ -3604,7 +3597,7 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
(List.rev args),
instance env (result_type omitted ty_fun) )
in
if List.length args < max_arity && uncurried then
if List.length args < max_arity && total_app then
match (expand_head env ty_fun).desc with
| Tarrow (Optional l, t1, t2, _, _) ->
ignored := (Optional l, t1, ty_fun.level) :: !ignored;
Expand All @@ -3617,7 +3610,7 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
| _ -> collect_args ()
else collect_args ()
| [(Nolabel, {pexp_desc = Pexp_construct ({txt = Lident "()"}, None)})]
when uncurried && omitted = [] && args <> []
when total_app && omitted = [] && args <> []
&& List.length args = List.length !ignored ->
(* foo(. ) treated as empty application if all args are optional (hence ignored) *)
type_unknown_args max_arity ~args ~top_arity:None omitted ty_fun []
Expand Down Expand Up @@ -3680,7 +3673,7 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
let sargs, omitted, arg =
match extract_label name sargs with
| None ->
if optional && (uncurried || label_assoc Nolabel sargs) then (
if optional && (total_app || label_assoc Nolabel sargs) then (
ignored := (l, ty, lv) :: !ignored;
( sargs,
omitted,
Expand Down Expand Up @@ -3728,9 +3721,9 @@ and type_application ?type_clash_context uncurried env funct (sargs : sargs) :
(List.map Printtyp.string_of_label
(Ext_list.filter labels (fun x -> x <> Nolabel))) ))
in
if uncurried then force_uncurried_type funct;
if total_app then force_uncurried_type funct;
let ty, max_arity = extract_uncurried_type funct in
let top_arity = if uncurried then Some max_arity else None in
let top_arity = if total_app then Some max_arity else None in
match sargs with
(* Special case for ignore: avoid discarding warning *)
| [(Nolabel, sarg)] when is_ignore ~env ~arity:top_arity funct ->
Expand Down

0 comments on commit df8a5e8

Please sign in to comment.