Skip to content

Commit 0e03792

Browse files
committed
Store location directly in the label on Pexp_fun.
1 parent 5a59871 commit 0e03792

25 files changed

+130
-211
lines changed

analysis/src/CompletionFrontEnd.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
14371437
| Some (ctxPath, currentUnlabelledCount) ->
14381438
(processingFun :=
14391439
match lbl with
1440-
| Nolabel -> Some (ctxPath, currentUnlabelledCount + 1)
1440+
| Nolbl -> Some (ctxPath, currentUnlabelledCount + 1)
14411441
| _ -> Some (ctxPath, currentUnlabelledCount));
14421442
if Debug.verbose () then
14431443
print_endline "[expr_iter] Completing for argument value";
@@ -1447,10 +1447,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
14471447
functionContextPath = ctxPath;
14481448
argumentLabel =
14491449
(match lbl with
1450-
| Nolabel ->
1450+
| Nolbl ->
14511451
Unlabelled {argumentPosition = currentUnlabelledCount}
1452-
| Optional name -> Optional name
1453-
| Labelled name -> Labelled name);
1452+
| Opt {txt = name} -> Optional name
1453+
| Lbl {txt = name} -> Labelled name);
14541454
})
14551455
in
14561456
(match defaultExpOpt with

analysis/src/DumpAst.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ and printExprItem expr ~pos ~indentation =
218218
^ addIndentation (indentation + 1)
219219
^ "arg: "
220220
^ (match arg with
221-
| Nolabel -> "Nolabel"
222-
| Labelled name -> "Labelled(" ^ name ^ ")"
223-
| Optional name -> "Optional(" ^ name ^ ")")
221+
| Nolbl -> "Nolabel"
222+
| Lbl {txt = name} -> "Labelled(" ^ name ^ ")"
223+
| Opt {txt = name} -> "Optional(" ^ name ^ ")")
224224
^ ",\n"
225225
^ addIndentation (indentation + 2)
226226
^ "pattern: "

analysis/src/Xform.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ module AddTypeAnnotation = struct
300300
match e.pexp_desc with
301301
| Pexp_fun {arg_label; lhs = pat; rhs = e} ->
302302
let isUnlabeledOnlyArg =
303-
argNum = 1 && arg_label = Nolabel
303+
argNum = 1 && arg_label = Nolbl
304304
&&
305305
match e.pexp_desc with
306306
| Pexp_fun _ -> false

compiler/frontend/ast_compatible.ml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,7 @@ let fun_ ?(loc = default_loc) ?(attrs = []) ?(async = false) ~arity pat exp =
8282
pexp_attributes = attrs;
8383
pexp_desc =
8484
Pexp_fun
85-
{
86-
arg_label = Nolabel;
87-
label_loc = Location.none;
88-
default = None;
89-
lhs = pat;
90-
rhs = exp;
91-
arity;
92-
async;
93-
};
85+
{arg_label = Nolbl; default = None; lhs = pat; rhs = exp; arity; async};
9486
}
9587

9688
let const_exp_string ?(loc = default_loc) ?(attrs = []) ?delimiter (s : string)

compiler/frontend/ast_pat.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ val arity_of_fun : t -> Parsetree.expression -> int
3030
(** [arity_of_fun pat e] tells the arity of
3131
expression [fun pat -> e]*)
3232

33-
val labels_of_fun : Parsetree.expression -> Asttypes.arg_label list
33+
val labels_of_fun : Parsetree.expression -> Asttypes.arg_label_loc list
3434

3535
val is_single_variable_pattern_conservative : t -> string option

compiler/frontend/ast_uncurry_gen.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
val to_method_callback :
2626
Location.t ->
2727
Bs_ast_mapper.mapper ->
28-
Asttypes.arg_label ->
28+
Asttypes.arg_label_loc ->
2929
Parsetree.pattern ->
3030
Parsetree.expression ->
3131
Parsetree.expression_desc

compiler/frontend/bs_ast_mapper.ml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -311,17 +311,9 @@ module E = struct
311311
sub vbs)
312312
(sub.expr sub e)
313313
(* #end *)
314-
| Pexp_fun
315-
{
316-
arg_label = lab;
317-
label_loc;
318-
default = def;
319-
lhs = p;
320-
rhs = e;
321-
arity;
322-
async;
323-
} ->
324-
fun_ ~loc ~attrs ~label_loc ~arity ~async lab
314+
| Pexp_fun {arg_label = lab; default = def; lhs = p; rhs = e; arity; async}
315+
->
316+
fun_ ~loc ~attrs ~arity ~async lab
325317
(map_opt (sub.expr sub) def)
326318
(sub.pat sub p) (sub.expr sub e)
327319
| Pexp_apply {funct = e; args = l; partial} ->

compiler/frontend/bs_syntaxerr.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ let () =
104104

105105
let err loc error = raise (Error (loc, error))
106106

107-
let optional_err loc (lbl : Asttypes.arg_label) =
107+
let optional_err loc (lbl : Asttypes.arg_label_loc) =
108108
match lbl with
109-
| Optional _ -> raise (Error (loc, Optional_in_uncurried_bs_attribute))
109+
| Opt _ -> raise (Error (loc, Optional_in_uncurried_bs_attribute))
110110
| _ -> ()
111111

112112
let err_if_label loc (lbl : Asttypes.arg_label_loc) =

compiler/frontend/bs_syntaxerr.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ type error =
5454

5555
val err : Location.t -> error -> 'a
5656

57-
val optional_err : Location.t -> Asttypes.arg_label -> unit
57+
val optional_err : Location.t -> Asttypes.arg_label_loc -> unit
5858

5959
val err_if_label : Location.t -> Asttypes.arg_label_loc -> unit

compiler/ml/ast_helper.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,9 @@ module Exp = struct
151151
let ident ?loc ?attrs a = mk ?loc ?attrs (Pexp_ident a)
152152
let constant ?loc ?attrs a = mk ?loc ?attrs (Pexp_constant a)
153153
let let_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_let (a, b, c))
154-
let fun_ ?loc ?attrs ?(async = false) ?(label_loc = Location.none) ~arity a b
155-
c d =
154+
let fun_ ?loc ?attrs ?(async = false) ~arity a b c d =
156155
mk ?loc ?attrs
157-
(Pexp_fun
158-
{arg_label = a; label_loc; default = b; lhs = c; rhs = d; arity; async})
156+
(Pexp_fun {arg_label = a; default = b; lhs = c; rhs = d; arity; async})
159157
let apply ?loc ?attrs ?(partial = false) funct args =
160158
mk ?loc ?attrs (Pexp_apply {funct; args; partial})
161159
let match_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_match (a, b))

compiler/ml/ast_helper.mli

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ module Exp : sig
139139
?loc:loc ->
140140
?attrs:attrs ->
141141
?async:bool ->
142-
?label_loc:loc ->
143142
arity:int option ->
144-
arg_label ->
143+
arg_label_loc ->
145144
expression option ->
146145
pattern ->
147146
expression ->

compiler/ml/ast_mapper.ml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,9 @@ module E = struct
274274
| Pexp_constant x -> constant ~loc ~attrs x
275275
| Pexp_let (r, vbs, e) ->
276276
let_ ~loc ~attrs r (List.map (sub.value_binding sub) vbs) (sub.expr sub e)
277-
| Pexp_fun
278-
{
279-
arg_label = lab;
280-
label_loc;
281-
default = def;
282-
lhs = p;
283-
rhs = e;
284-
arity;
285-
async;
286-
} ->
287-
fun_ ~loc ~attrs ~label_loc ~arity ~async lab
277+
| Pexp_fun {arg_label = lab; default = def; lhs = p; rhs = e; arity; async}
278+
->
279+
fun_ ~loc ~attrs ~arity ~async lab
288280
(map_opt (sub.expr sub) def)
289281
(sub.pat sub p) (sub.expr sub e)
290282
| Pexp_apply {funct = e; args = l; partial} ->

compiler/ml/ast_mapper_from0.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ module E = struct
305305
| Pexp_let (r, vbs, e) ->
306306
let_ ~loc ~attrs r (List.map (sub.value_binding sub) vbs) (sub.expr sub e)
307307
| Pexp_fun (lab, def, p, e) ->
308+
let lab = Asttypes.to_arg_label_loc lab in
308309
let async = Ext_list.exists attrs (fun ({txt}, _) -> txt = "res.async") in
309310
fun_ ~loc ~attrs ~async ~arity:None lab
310311
(map_opt (sub.expr sub) def)

compiler/ml/ast_mapper_to0.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ module E = struct
294294
let_ ~loc ~attrs r (List.map (sub.value_binding sub) vbs) (sub.expr sub e)
295295
| Pexp_fun {arg_label = lab; default = def; lhs = p; rhs = e; arity; async}
296296
-> (
297+
let lab = Asttypes.to_arg_label lab in
297298
let attrs =
298299
if async then
299300
({txt = "res.async"; loc = Location.none}, Pt.PStr []) :: attrs

compiler/ml/parsetree.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ and expression_desc =
230230
let rec P1 = E1 and ... and Pn = EN in E (flag = Recursive)
231231
*)
232232
| Pexp_fun of {
233-
arg_label: arg_label;
234-
label_loc: Location.t;
233+
arg_label: arg_label_loc;
235234
default: expression option;
236235
lhs: pattern;
237236
rhs: expression;

compiler/ml/pprintast.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,10 @@ and simple_pattern ctxt (f : Format.formatter) (x : pattern) : unit =
494494

495495
and label_exp ctxt f (l, opt, p) =
496496
match l with
497-
| Nolabel ->
497+
| Nolbl ->
498498
(* single case pattern parens needed here *)
499499
pp f "%a@ " (simple_pattern ctxt) p
500-
| Optional rest -> (
500+
| Opt {txt = rest} -> (
501501
match p with
502502
| {ppat_desc = Ppat_var {txt; _}; ppat_attributes = []} when txt = rest -> (
503503
match opt with
@@ -508,7 +508,7 @@ and label_exp ctxt f (l, opt, p) =
508508
| Some o ->
509509
pp f "?%s:(%a=@;%a)@;" rest (pattern1 ctxt) p (expression ctxt) o
510510
| None -> pp f "?%s:%a@;" rest (simple_pattern ctxt) p))
511-
| Labelled l -> (
511+
| Lbl {txt = l} -> (
512512
match p with
513513
| {ppat_desc = Ppat_var {txt; _}; ppat_attributes = []} when txt = l ->
514514
pp f "~%s@;" l
@@ -988,7 +988,7 @@ and binding ctxt f {pvb_pat = p; pvb_expr = x; _} =
988988
| Some arity -> "[arity:" ^ string_of_int arity ^ "]"
989989
in
990990
let async_str = if async then "async " else "" in
991-
if label = Nolabel then
991+
if label = Nolbl then
992992
pp f "%s%s%a@ %a" async_str arity_str (simple_pattern ctxt) p
993993
pp_print_pexp_function e
994994
else

compiler/ml/printast.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,6 @@ let option i f ppf x =
110110
let longident_loc i ppf li = line i ppf "%a\n" fmt_longident_loc li
111111
let string i ppf s = line i ppf "\"%s\"\n" s
112112
let string_loc i ppf s = line i ppf "%a\n" fmt_string_loc s
113-
let arg_label i ppf = function
114-
| Nolabel -> line i ppf "Nolabel\n"
115-
| Optional s -> line i ppf "Optional \"%s\"\n" s
116-
| Labelled s -> line i ppf "Labelled \"%s\"\n" s
117113

118114
let arg_label_loc i ppf = function
119115
| Nolbl -> line i ppf "Nolabel\n"
@@ -251,7 +247,7 @@ and expression i ppf x =
251247
| None -> ()
252248
| Some arity -> line i ppf "arity:%d\n" arity
253249
in
254-
arg_label i ppf l;
250+
arg_label_loc i ppf l;
255251
option i expression ppf eo;
256252
pattern i ppf p;
257253
expression i ppf e

compiler/ml/typecore.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,7 @@ let rec type_approx env sexp =
18981898
match sexp.pexp_desc with
18991899
| Pexp_let (_, _, e) -> type_approx env e
19001900
| Pexp_fun {arg_label = p; rhs = e; arity} ->
1901+
let p = Asttypes.to_arg_label p in
19011902
let ty = if is_optional p then type_option (newvar ()) else newvar () in
19021903
newty (Tarrow (p, ty, type_approx env e, Cok, arity))
19031904
| Pexp_match (_, {pc_rhs = e} :: _) -> type_approx env e
@@ -2363,6 +2364,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
23632364
arity;
23642365
async;
23652366
} ->
2367+
let l = Asttypes.to_arg_label l in
23662368
assert (is_optional l);
23672369
(* default allowed only with optional argument *)
23682370
let open Ast_helper in
@@ -2405,6 +2407,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
24052407
[Exp.case pat body]
24062408
| Pexp_fun
24072409
{arg_label = l; default = None; lhs = spat; rhs = sbody; arity; async} ->
2410+
let l = Asttypes.to_arg_label l in
24082411
type_function ?in_function ~arity ~async loc sexp.pexp_attributes env
24092412
ty_expected l
24102413
[Ast_helper.Exp.case spat sbody]

0 commit comments

Comments
 (0)