Skip to content

Commit 82ba4a6

Browse files
committed
Store location directly in the label on Pexp_fun.
1 parent 5ea8a86 commit 82ba4a6

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))

0 commit comments

Comments
 (0)