Skip to content

Commit b0b5fb7

Browse files
committed
Use inline record for Texp_apply.
1 parent 115224e commit b0b5fb7

14 files changed

+83
-47
lines changed

analysis/reanalyze/src/Arnold.ml

+14-7
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ module FindFunctionsCalled = struct
534534
let super = Tast_mapper.default in
535535
let expr (self : Tast_mapper.mapper) (e : Typedtree.expression) =
536536
(match e.exp_desc with
537-
| Texp_apply ({exp_desc = Texp_ident (callee, _, _)}, _args) ->
537+
| Texp_apply {funct = {exp_desc = Texp_ident (callee, _, _)}} ->
538538
let functionName = Path.name callee in
539539
callees := !callees |> StringSet.add functionName
540540
| _ -> ());
@@ -577,7 +577,10 @@ module ExtendFunctionTable = struct
577577
} ->
578578
Some (path, loc)
579579
| Some
580-
{exp_desc = Texp_apply ({exp_desc = Texp_ident (path, {loc}, _)}, args)}
580+
{
581+
exp_desc =
582+
Texp_apply {funct = {exp_desc = Texp_ident (path, {loc}, _)}; args};
583+
}
581584
when kindOpt <> None ->
582585
let checkArg ((argLabel : Asttypes.arg_label), _argOpt) =
583586
match (argLabel, kindOpt) with
@@ -617,7 +620,7 @@ module ExtendFunctionTable = struct
617620
calls a progress function"
618621
functionName printPos id_pos;
619622
})))
620-
| Texp_apply ({exp_desc = Texp_ident (callee, _, _)}, args)
623+
| Texp_apply {funct = {exp_desc = Texp_ident (callee, _, _)}; args}
621624
when callee |> FunctionTable.isInFunctionInTable ~functionTable ->
622625
let functionName = Path.name callee in
623626
args
@@ -665,7 +668,8 @@ module CheckExpressionWellFormed = struct
665668
| Texp_ident (path, {loc}, _) ->
666669
checkIdent ~path ~loc;
667670
e
668-
| Texp_apply ({exp_desc = Texp_ident (functionPath, _, _)}, args) ->
671+
| Texp_apply {funct = {exp_desc = Texp_ident (functionPath, _, _)}; args}
672+
->
669673
let functionName = Path.name functionPath in
670674
args
671675
|> List.iter (fun ((argLabel : Asttypes.arg_label), argOpt) ->
@@ -739,8 +743,10 @@ module Compile = struct
739743
match expr.exp_desc with
740744
| Texp_ident _ -> Command.nothing
741745
| Texp_apply
742-
(({exp_desc = Texp_ident (calleeToRename, l, vd)} as expr), argsToExtend)
743-
-> (
746+
{
747+
funct = {exp_desc = Texp_ident (calleeToRename, l, vd)} as expr;
748+
args = argsToExtend;
749+
} -> (
744750
let callee, args =
745751
match
746752
Hashtbl.find_opt ctx.innerRecursiveFunctions
@@ -844,7 +850,8 @@ module Compile = struct
844850
and create a function call with the appropriate arguments *)
845851
assert false
846852
| None -> expr |> expression ~ctx |> evalArgs ~args ~ctx)
847-
| Texp_apply (expr, args) -> expr |> expression ~ctx |> evalArgs ~args ~ctx
853+
| Texp_apply {funct = expr; args} ->
854+
expr |> expression ~ctx |> evalArgs ~args ~ctx
848855
| Texp_let
849856
( Recursive,
850857
[{vb_pat = {pat_desc = Tpat_var (id, _); pat_loc}; vb_expr}],

analysis/reanalyze/src/DeadValue.ml

+14-8
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,16 @@ let rec collectExpr super self (e : Typedtree.expression) =
126126
ValueReferences.add locTo.loc_start Location.none.loc_start)
127127
else addValueReference ~addFileReference:true ~locFrom ~locTo
128128
| Texp_apply
129-
( {
130-
exp_desc =
131-
Texp_ident
132-
(path, _, {Types.val_loc = {loc_ghost = false; _} as locTo});
133-
exp_type;
134-
},
135-
args ) ->
129+
{
130+
funct =
131+
{
132+
exp_desc =
133+
Texp_ident
134+
(path, _, {Types.val_loc = {loc_ghost = false; _} as locTo});
135+
exp_type;
136+
};
137+
args;
138+
} ->
136139
args
137140
|> processOptionalArgs ~expType:exp_type
138141
~locFrom:(locFrom : Location.t)
@@ -163,7 +166,10 @@ let rec collectExpr super self (e : Typedtree.expression) =
163166
{
164167
exp_desc =
165168
Texp_apply
166-
({exp_desc = Texp_ident (idArg2, _, _)}, args);
169+
{
170+
funct = {exp_desc = Texp_ident (idArg2, _, _)};
171+
args;
172+
};
167173
};
168174
};
169175
};

analysis/reanalyze/src/Exception.ml

+9-5
Original file line numberDiff line numberDiff line change
@@ -294,24 +294,28 @@ let traverseAst () =
294294
}
295295
:: !currentEvents
296296
| Texp_apply
297-
( {exp_desc = Texp_ident (atat, _, _)},
298-
[(_lbl1, Some {exp_desc = Texp_ident (callee, _, _)}); arg] )
297+
{
298+
funct = {exp_desc = Texp_ident (atat, _, _)};
299+
args = [(_lbl1, Some {exp_desc = Texp_ident (callee, _, _)}); arg];
300+
}
299301
when (* raise @@ Exn(...) *)
300302
atat |> Path.name = "Pervasives.@@" && callee |> Path.name |> isRaise
301303
->
302304
let exceptions = [arg] |> raiseArgs in
303305
currentEvents := {Event.exceptions; loc; kind = Raises} :: !currentEvents;
304306
arg |> snd |> iterExprOpt self
305307
| Texp_apply
306-
( {exp_desc = Texp_ident (atat, _, _)},
307-
[arg; (_lbl1, Some {exp_desc = Texp_ident (callee, _, _)})] )
308+
{
309+
funct = {exp_desc = Texp_ident (atat, _, _)};
310+
args = [arg; (_lbl1, Some {exp_desc = Texp_ident (callee, _, _)})];
311+
}
308312
when (* Exn(...) |> raise *)
309313
atat |> Path.name = "Pervasives.|>" && callee |> Path.name |> isRaise
310314
->
311315
let exceptions = [arg] |> raiseArgs in
312316
currentEvents := {Event.exceptions; loc; kind = Raises} :: !currentEvents;
313317
arg |> snd |> iterExprOpt self
314-
| Texp_apply (({exp_desc = Texp_ident (callee, _, _)} as e), args) ->
318+
| Texp_apply {funct = {exp_desc = Texp_ident (callee, _, _)} as e; args} ->
315319
let calleeName = Path.name callee in
316320
if calleeName |> isRaise then
317321
let exceptions = args |> raiseArgs in

analysis/reanalyze/src/SideEffects.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let rec exprNoSideEffects (expr : Typedtree.expression) =
2626
| Texp_ident _ | Texp_constant _ -> true
2727
| Texp_construct (_, _, el) -> el |> List.for_all exprNoSideEffects
2828
| Texp_function _ -> true
29-
| Texp_apply ({exp_desc = Texp_ident (path, _, _)}, args)
29+
| Texp_apply {funct = {exp_desc = Texp_ident (path, _, _)}; args}
3030
when path |> pathIsWhitelistedForSideEffects ->
3131
args |> List.for_all (fun (_, eo) -> eo |> exprOptNoSideEffects)
3232
| Texp_apply _ -> false

compiler/gentype/TranslateStructure.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ let rec addAnnotationsToTypes_ ~config ~(expr : Typedtree.expression)
1818
else a_name
1919
in
2020
{a_name; a_type} :: next_types1
21-
| Texp_apply ({exp_desc = Texp_ident (path, _, _)}, [(_, Some expr1)]), _, _
22-
-> (
21+
| ( Texp_apply
22+
{funct = {exp_desc = Texp_ident (path, _, _)}; args = [(_, Some expr1)]},
23+
_,
24+
_ ) -> (
2325
match path |> TranslateTypeExprFromTypes.path_to_list |> List.rev with
2426
| ["Js"; "Internal"; fn_mk]
2527
when (* Uncurried function definition uses Js.Internal.fn_mkX(...) *)

compiler/ml/printtyped.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ and expression i ppf x =
295295
line i ppf "%a" Ident.print param;
296296
arg_label i ppf p;
297297
case i ppf case_
298-
| Texp_apply (e, l) ->
298+
| Texp_apply {funct = e; args = l} ->
299299
line i ppf "Texp_apply\n";
300300
expression i ppf e;
301301
list i label_x_expression ppf l

compiler/ml/rec_check.ml

+5-3
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ let rec classify_expression : Typedtree.expression -> sd =
201201
| Texp_pack _ | Texp_function _ | Texp_lazy _ | Texp_extension_constructor _
202202
->
203203
Static
204-
| Texp_apply ({exp_desc = Texp_ident (_, _, vd)}, _) when is_ref vd -> Static
204+
| Texp_apply {funct = {exp_desc = Texp_ident (_, _, vd)}} when is_ref vd ->
205+
Static
205206
| Texp_apply _ | Texp_match _ | Texp_ifthenelse _ | Texp_send _ | Texp_field _
206207
| Texp_assert _ | Texp_try _ | Texp_override _ ->
207208
Dynamic
@@ -235,10 +236,11 @@ let rec expression : Env.env -> Typedtree.expression -> Use.t =
235236
| Texp_constant _ -> Use.empty
236237
| Texp_new _ -> assert false
237238
| Texp_instvar _ -> Use.empty
238-
| Texp_apply ({exp_desc = Texp_ident (_, _, vd)}, [(_, Some arg)])
239+
| Texp_apply
240+
{funct = {exp_desc = Texp_ident (_, _, vd)}; args = [(_, Some arg)]}
239241
when is_ref vd ->
240242
Use.guard (expression env arg)
241-
| Texp_apply (e, args) ->
243+
| Texp_apply {funct = e; args} ->
242244
let arg env (_, eo) = option expression env eo in
243245
Use.(join (inspect (expression env e)) (inspect (list arg env args)))
244246
| Texp_tuple exprs -> Use.guard (list expression env exprs)

compiler/ml/tast_iterator.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ let expr sub {exp_extra; exp_desc; exp_env; _} =
156156
sub.value_bindings sub (rec_flag, list);
157157
sub.expr sub exp
158158
| Texp_function {case; _} -> sub.case sub case
159-
| Texp_apply (exp, list) ->
159+
| Texp_apply {funct = exp; args = list} ->
160160
sub.expr sub exp;
161161
List.iter (fun (_, o) -> Option.iter (sub.expr sub) o) list
162162
| Texp_match (exp, list1, list2, _) ->

compiler/ml/tast_mapper.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,12 @@ let expr sub x =
202202
| Texp_function {arg_label; arity; param; case; partial; async} ->
203203
Texp_function
204204
{arg_label; arity; param; case = sub.case sub case; partial; async}
205-
| Texp_apply (exp, list) ->
205+
| Texp_apply {funct = exp; args = list} ->
206206
Texp_apply
207-
(sub.expr sub exp, List.map (tuple2 id (opt (sub.expr sub))) list)
207+
{
208+
funct = sub.expr sub exp;
209+
args = List.map (tuple2 id (opt (sub.expr sub))) list;
210+
}
208211
| Texp_match (exp, cases, exn_cases, p) ->
209212
Texp_match
210213
(sub.expr sub exp, sub.cases sub cases, sub.cases sub exn_cases, p)

compiler/ml/translcore.ml

+9-6
Original file line numberDiff line numberDiff line change
@@ -711,11 +711,14 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
711711
loc )
712712
| None -> lambda)
713713
| Texp_apply
714-
( ({
715-
exp_desc = Texp_ident (_, _, {val_kind = Val_prim p});
716-
exp_type = prim_type;
717-
} as funct),
718-
oargs )
714+
{
715+
funct =
716+
{
717+
exp_desc = Texp_ident (_, _, {val_kind = Val_prim p});
718+
exp_type = prim_type;
719+
} as funct;
720+
args = oargs;
721+
}
719722
when List.length oargs >= p.prim_arity
720723
&& List.for_all (fun (_, arg) -> arg <> None) oargs -> (
721724
let args, args' = cut p.prim_arity oargs in
@@ -757,7 +760,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
757760
| Plazyforce, [a] -> wrap (Matching.inline_lazy_force a e.exp_loc)
758761
| Plazyforce, _ -> assert false
759762
| _ -> wrap (Lprim (prim, argl, e.exp_loc))))
760-
| Texp_apply (funct, oargs) ->
763+
| Texp_apply {funct; args = oargs} ->
761764
let inlined, funct =
762765
Translattribute.get_and_remove_inlined_attribute funct
763766
in

compiler/ml/typecore.ml

+11-8
Original file line numberDiff line numberDiff line change
@@ -1799,7 +1799,7 @@ let rec is_nonexpansive exp =
17991799
List.for_all (fun vb -> is_nonexpansive vb.vb_expr) pat_exp_list
18001800
&& is_nonexpansive body
18011801
| Texp_function _ -> true
1802-
| Texp_apply (e, (_, None) :: el) ->
1802+
| Texp_apply {funct = e; args = (_, None) :: el} ->
18031803
is_nonexpansive e && List.for_all is_nonexpansive_opt (List.map snd el)
18041804
| Texp_match (e, cases, [], _) ->
18051805
is_nonexpansive e
@@ -1834,12 +1834,15 @@ let rec is_nonexpansive exp =
18341834
or the relaxed value restriction. See GPR#1142 *)
18351835
| Texp_assert exp -> is_nonexpansive exp
18361836
| Texp_apply
1837-
( {
1838-
exp_desc =
1839-
Texp_ident
1840-
(_, _, {val_kind = Val_prim {Primitive.prim_name = "%raise"}});
1841-
},
1842-
[(Nolabel, Some e)] ) ->
1837+
{
1838+
funct =
1839+
{
1840+
exp_desc =
1841+
Texp_ident
1842+
(_, _, {val_kind = Val_prim {Primitive.prim_name = "%raise"}});
1843+
};
1844+
args = [(Nolabel, Some e)];
1845+
} ->
18431846
is_nonexpansive e
18441847
| _ -> false
18451848
@@ -2443,7 +2446,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
24432446
let mk_apply funct args =
24442447
rue
24452448
{
2446-
exp_desc = Texp_apply (funct, args);
2449+
exp_desc = Texp_apply {funct; args};
24472450
exp_loc = loc;
24482451
exp_extra = [];
24492452
exp_type = ty_res;

compiler/ml/typedtree.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ and expression_desc =
8484
partial: partial;
8585
async: bool;
8686
}
87-
| Texp_apply of expression * (arg_label * expression option) list
87+
| Texp_apply of {
88+
funct: expression;
89+
args: (arg_label * expression option) list;
90+
}
8891
| Texp_match of expression * case list * case list * partial
8992
| Texp_try of expression * case list
9093
| Texp_tuple of expression list

compiler/ml/typedtree.mli

+4-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ and expression_desc =
148148
[Partial] if the pattern match is partial
149149
[Total] otherwise.
150150
*)
151-
| Texp_apply of expression * (arg_label * expression option) list
151+
| Texp_apply of {
152+
funct: expression;
153+
args: (arg_label * expression option) list;
154+
}
152155
(** E0 ~l1:E1 ... ~ln:En
153156
154157
The expression can be None if the expression is abstracted over

compiler/ml/typedtreeIter.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ end = struct
231231
iter_bindings rec_flag list;
232232
iter_expression exp
233233
| Texp_function {case; _} -> iter_case case
234-
| Texp_apply (exp, list) ->
234+
| Texp_apply {funct = exp; args = list} ->
235235
iter_expression exp;
236236
List.iter
237237
(fun (_label, expo) ->

0 commit comments

Comments
 (0)