Skip to content

Commit 778cc5b

Browse files
committed
AST: use inline record for Pexp_apply.
1 parent eaf8e7b commit 778cc5b

25 files changed

+378
-207
lines changed

analysis/src/CompletionFrontEnd.ml

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -255,33 +255,43 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
255255
| None -> None
256256
| Some contexPath -> Some (CPObj (contexPath, txt)))
257257
| Pexp_apply
258-
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}},
259-
[
260-
(_, lhs);
261-
(_, {pexp_desc = Pexp_apply (d, args); pexp_loc; pexp_attributes});
262-
] ) ->
258+
{
259+
funct =
260+
{
261+
pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")};
262+
pexp_loc;
263+
pexp_attributes;
264+
};
265+
args = [(_, lhs); (_, {pexp_desc = Pexp_apply {funct = d; args}})];
266+
} ->
263267
(* Transform away pipe with apply call *)
264268
exprToContextPath
265269
{
266-
pexp_desc = Pexp_apply (d, (Nolabel, lhs) :: args);
270+
pexp_desc = Pexp_apply {funct = d; args = (Nolabel, lhs) :: args};
267271
pexp_loc;
268272
pexp_attributes;
269273
}
270274
| Pexp_apply
271-
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}},
272-
[(_, lhs); (_, {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes})]
273-
) ->
275+
{
276+
funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}};
277+
args =
278+
[
279+
(_, lhs); (_, {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes});
280+
];
281+
} ->
274282
(* Transform away pipe with identifier *)
275283
exprToContextPath
276284
{
277285
pexp_desc =
278286
Pexp_apply
279-
( {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes},
280-
[(Nolabel, lhs)] );
287+
{
288+
funct = {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes};
289+
args = [(Nolabel, lhs)];
290+
};
281291
pexp_loc;
282292
pexp_attributes;
283293
}
284-
| Pexp_apply (e1, args) -> (
294+
| Pexp_apply {funct = e1; args} -> (
285295
match exprToContextPath e1 with
286296
| None -> None
287297
| Some contexPath -> Some (CPApply (contexPath, args |> List.map fst)))
@@ -313,14 +323,18 @@ let completePipeChain (exp : Parsetree.expression) =
313323
(* When the left side of the pipe we're completing is a function application.
314324
Example: someArray->Js.Array2.map(v => v + 2)-> *)
315325
| Pexp_apply
316-
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}},
317-
[_; (_, {pexp_desc = Pexp_apply (d, _)})] ) ->
326+
{
327+
funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}};
328+
args = [_; (_, {pexp_desc = Pexp_apply {funct = d}})];
329+
} ->
318330
exprToContextPath exp |> Option.map (fun ctxPath -> (ctxPath, d.pexp_loc))
319331
(* When the left side of the pipe we're completing is an identifier application.
320332
Example: someArray->filterAllTheGoodStuff-> *)
321333
| Pexp_apply
322-
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}},
323-
[_; (_, {pexp_desc = Pexp_ident _; pexp_loc})] ) ->
334+
{
335+
funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}};
336+
args = [_; (_, {pexp_desc = Pexp_ident _; pexp_loc})];
337+
} ->
324338
exprToContextPath exp |> Option.map (fun ctxPath -> (ctxPath, pexp_loc))
325339
| _ -> None
326340

@@ -1094,11 +1108,15 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
10941108
scope := oldScope);
10951109
resetCurrentCtxPath oldCtxPath
10961110
| Pexp_apply
1097-
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u"); loc = opLoc}},
1098-
[
1099-
(_, lhs);
1100-
(_, {pexp_desc = Pexp_extension _; pexp_loc = {loc_ghost = true}});
1101-
] )
1111+
{
1112+
funct =
1113+
{pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u"); loc = opLoc}};
1114+
args =
1115+
[
1116+
(_, lhs);
1117+
(_, {pexp_desc = Pexp_extension _; pexp_loc = {loc_ghost = true}});
1118+
];
1119+
}
11021120
when opLoc |> Loc.hasPos ~pos:posBeforeCursor ->
11031121
(* Case foo-> when the parser adds a ghost expression to the rhs
11041122
so the apply expression does not include the cursor *)
@@ -1228,7 +1246,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
12281246
exprLoc = e.pexp_loc;
12291247
}))
12301248
| None -> ())
1231-
| Pexp_apply ({pexp_desc = Pexp_ident compName}, args)
1249+
| Pexp_apply {funct = {pexp_desc = Pexp_ident compName}; args}
12321250
when Res_parsetree_viewer.is_jsx_expression expr ->
12331251
inJsxContext := true;
12341252
let jsxProps = CompletionJsx.extractJsxProps ~compName ~args in
@@ -1269,23 +1287,34 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
12691287
}))
12701288
else iterateJsxProps ~iterator jsxProps
12711289
| Pexp_apply
1272-
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}},
1273-
[
1274-
(_, lhs);
1275-
(_, {pexp_desc = Pexp_ident {txt = Longident.Lident id; loc}});
1276-
] )
1290+
{
1291+
funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}};
1292+
args =
1293+
[
1294+
(_, lhs);
1295+
(_, {pexp_desc = Pexp_ident {txt = Longident.Lident id; loc}});
1296+
];
1297+
}
12771298
when loc |> Loc.hasPos ~pos:posBeforeCursor ->
12781299
if Debug.verbose () then print_endline "[expr_iter] Case foo->id";
12791300
setPipeResult ~lhs ~id |> ignore
12801301
| Pexp_apply
1281-
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u"); loc = opLoc}},
1282-
[(_, lhs); _] )
1302+
{
1303+
funct =
1304+
{
1305+
pexp_desc =
1306+
Pexp_ident {txt = Lident ("|." | "|.u"); loc = opLoc};
1307+
};
1308+
args = [(_, lhs); _];
1309+
}
12831310
when Loc.end_ opLoc = posCursor ->
12841311
if Debug.verbose () then print_endline "[expr_iter] Case foo->";
12851312
setPipeResult ~lhs ~id:"" |> ignore
12861313
| Pexp_apply
1287-
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}},
1288-
[_; (_, {pexp_desc = Pexp_apply (funExpr, args)})] )
1314+
{
1315+
funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}};
1316+
args = [_; (_, {pexp_desc = Pexp_apply {funct = funExpr; args}})];
1317+
}
12891318
when (* Normally named arg completion fires when the cursor is right after the expression.
12901319
E.g in foo(~<---there
12911320
But it should not fire in foo(~a)<---there *)
@@ -1318,10 +1347,13 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
13181347
resetCurrentCtxPath oldCtxPath)
13191348
| Some argCompletable -> setResult argCompletable)
13201349
| Pexp_apply
1321-
({pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}}, [_; _]) ->
1350+
{
1351+
funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}};
1352+
args = [_; _];
1353+
} ->
13221354
(* Ignore any other pipe. *)
13231355
()
1324-
| Pexp_apply (funExpr, args)
1356+
| Pexp_apply {funct = funExpr; args}
13251357
when not
13261358
(Loc.end_ expr.pexp_loc = posCursor
13271359
&& charBeforeCursor = Some ')') -> (

analysis/src/DumpAst.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ and printExprItem expr ~pos ~indentation =
171171
|> String.concat "\n")
172172
| Pexp_ident {txt} ->
173173
"Pexp_ident:" ^ (Utils.flattenLongIdent txt |> SharedTypes.ident)
174-
| Pexp_apply (expr, args) ->
174+
| Pexp_apply {funct = expr; args} ->
175175
let printLabel labelled ~pos =
176176
match labelled with
177177
| None -> "<unlabelled>"

analysis/src/SemanticTokens.ml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ let command ~debug ~emitter ~path =
247247
~posEnd:(Some (Loc.end_ loc))
248248
~lid ~debug;
249249
Ast_iterator.default_iterator.expr iterator e
250-
| Pexp_apply ({pexp_desc = Pexp_ident lident; pexp_loc}, args)
250+
| Pexp_apply {funct = {pexp_desc = Pexp_ident lident; pexp_loc}; args}
251251
when Res_parsetree_viewer.is_jsx_expression e ->
252252
(*
253253
Angled brackets:
@@ -299,11 +299,14 @@ let command ~debug ~emitter ~path =
299299

300300
args |> List.iter (fun (_lbl, arg) -> iterator.expr iterator arg)
301301
| Pexp_apply
302-
( {
303-
pexp_desc =
304-
Pexp_ident {txt = Longident.Lident (("<" | ">") as op); loc};
305-
},
306-
[_; _] ) ->
302+
{
303+
funct =
304+
{
305+
pexp_desc =
306+
Pexp_ident {txt = Longident.Lident (("<" | ">") as op); loc};
307+
};
308+
args = [_; _];
309+
} ->
307310
if debug then
308311
Printf.printf "Binary operator %s %s\n" op (Loc.toString loc);
309312
emitter |> emitFromLoc ~loc ~type_:Operator;

analysis/src/SignatureHelp.ml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,20 @@ let signatureHelp ~path ~pos ~currentFile ~debug ~allowForConstructorPayloads =
364364
| {
365365
pexp_desc =
366366
Pexp_apply
367-
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}},
368-
[
369-
_;
370-
( _,
371-
{
372-
pexp_desc =
373-
Pexp_apply (({pexp_desc = Pexp_ident _} as exp), args);
374-
pexp_loc;
375-
} );
376-
] );
367+
{
368+
funct = {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}};
369+
args =
370+
[
371+
_;
372+
( _,
373+
{
374+
pexp_desc =
375+
Pexp_apply
376+
{funct = {pexp_desc = Pexp_ident _} as exp; args};
377+
pexp_loc;
378+
} );
379+
];
380+
};
377381
}
378382
when locHasCursor pexp_loc ->
379383
let argAtCursor, extractedArgs =
@@ -383,7 +387,8 @@ let signatureHelp ~path ~pos ~currentFile ~debug ~allowForConstructorPayloads =
383387
(exp.pexp_loc, `FunctionCall (argAtCursor, exp, extractedArgs))
384388
(* Look for applying idents, like someIdent(...) *)
385389
| {
386-
pexp_desc = Pexp_apply (({pexp_desc = Pexp_ident _} as exp), args);
390+
pexp_desc =
391+
Pexp_apply {funct = {pexp_desc = Pexp_ident _} as exp; args};
387392
pexp_loc;
388393
}
389394
when locHasCursor pexp_loc ->

analysis/src/Xform.ml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,15 @@ module IfThenElse = struct
8888
( {
8989
pexp_desc =
9090
Pexp_apply
91-
( {
92-
pexp_desc =
93-
Pexp_ident {txt = Lident (("=" | "<>") as op)};
94-
},
95-
[(Nolabel, arg1); (Nolabel, arg2)] );
91+
{
92+
funct =
93+
{
94+
pexp_desc =
95+
Pexp_ident
96+
{txt = Longident.Lident (("=" | "<>") as op)};
97+
};
98+
args = [(Nolabel, arg1); (Nolabel, arg2)];
99+
};
96100
},
97101
e1,
98102
Some e2 )

compiler/frontend/ast_compatible.ml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,32 @@ let apply_simple ?(loc = default_loc) ?(attrs = []) (fn : expression)
3939
pexp_loc = loc;
4040
pexp_attributes = attrs;
4141
pexp_desc =
42-
Pexp_apply (fn, Ext_list.map args (fun x -> (Asttypes.Nolabel, x)));
42+
Pexp_apply
43+
{funct = fn; args = Ext_list.map args (fun x -> (Asttypes.Nolabel, x))};
4344
}
4445

4546
let app1 ?(loc = default_loc) ?(attrs = []) fn arg1 : expression =
4647
{
4748
pexp_loc = loc;
4849
pexp_attributes = attrs;
49-
pexp_desc = Pexp_apply (fn, [(Nolabel, arg1)]);
50+
pexp_desc = Pexp_apply {funct = fn; args = [(Nolabel, arg1)]};
5051
}
5152

5253
let app2 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 : expression =
5354
{
5455
pexp_loc = loc;
5556
pexp_attributes = attrs;
56-
pexp_desc = Pexp_apply (fn, [(Nolabel, arg1); (Nolabel, arg2)]);
57+
pexp_desc =
58+
Pexp_apply {funct = fn; args = [(Nolabel, arg1); (Nolabel, arg2)]};
5759
}
5860

5961
let app3 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 arg3 : expression =
6062
{
6163
pexp_loc = loc;
6264
pexp_attributes = attrs;
6365
pexp_desc =
64-
Pexp_apply (fn, [(Nolabel, arg1); (Nolabel, arg2); (Nolabel, arg3)]);
66+
Pexp_apply
67+
{funct = fn; args = [(Nolabel, arg1); (Nolabel, arg2); (Nolabel, arg3)]};
6568
}
6669

6770
let fun_ ?(loc = default_loc) ?(attrs = []) ?(async = false) ~arity pat exp =
@@ -101,7 +104,11 @@ let apply_labels ?(loc = default_loc) ?(attrs = []) fn
101104
pexp_loc = loc;
102105
pexp_attributes = attrs;
103106
pexp_desc =
104-
Pexp_apply (fn, Ext_list.map args (fun (l, a) -> (Asttypes.Labelled l, a)));
107+
Pexp_apply
108+
{
109+
funct = fn;
110+
args = Ext_list.map args (fun (l, a) -> (Asttypes.Labelled l, a));
111+
};
105112
}
106113

107114
let label_arrow ?(loc = default_loc) ?(attrs = []) ~arity s a b : core_type =

compiler/frontend/ast_exp_apply.ml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ let sane_property_name_check loc s =
6464
(* match fn as *)
6565
let view_as_app (fn : exp) (s : string list) : app_pattern option =
6666
match fn.pexp_desc with
67-
| Pexp_apply ({pexp_desc = Pexp_ident {txt = Lident op; _}}, args)
67+
| Pexp_apply {funct = {pexp_desc = Pexp_ident {txt = Lident op; _}}; args}
6868
when Ext_list.has_string s op ->
6969
Some {op; loc = fn.pexp_loc; args = check_and_discard args}
7070
| _ -> None
@@ -88,10 +88,10 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
8888
{f with pexp_desc = Pexp_variant (label, Some a); pexp_loc = e.pexp_loc}
8989
| Pexp_construct (ctor, None) ->
9090
{f with pexp_desc = Pexp_construct (ctor, Some a); pexp_loc = e.pexp_loc}
91-
| Pexp_apply (fn1, args) ->
91+
| Pexp_apply {funct = fn1; args} ->
9292
Bs_ast_invariant.warn_discarded_unused_attributes fn1.pexp_attributes;
9393
{
94-
pexp_desc = Pexp_apply (fn1, (Nolabel, a) :: args);
94+
pexp_desc = Pexp_apply {funct = fn1; args = (Nolabel, a) :: args};
9595
pexp_loc = e.pexp_loc;
9696
pexp_attributes = e.pexp_attributes @ f.pexp_attributes;
9797
}
@@ -107,12 +107,16 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
107107
fn with
108108
pexp_desc = Pexp_construct (ctor, Some bounded_obj_arg);
109109
}
110-
| Pexp_apply (fn, args) ->
110+
| Pexp_apply {funct = fn; args} ->
111111
Bs_ast_invariant.warn_discarded_unused_attributes
112112
fn.pexp_attributes;
113113
{
114114
Parsetree.pexp_desc =
115-
Pexp_apply (fn, (Nolabel, bounded_obj_arg) :: args);
115+
Pexp_apply
116+
{
117+
funct = fn;
118+
args = (Nolabel, bounded_obj_arg) :: args;
119+
};
116120
pexp_attributes = [];
117121
pexp_loc = fn.pexp_loc;
118122
}

0 commit comments

Comments
 (0)