Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use identical variant names for arg_label and arg_label_loc. #7254

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions analysis/reanalyze/src/Arnold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ module Compile = struct
let argsFromKind =
innerFunctionDefinition.kind
|> List.map (fun (entry : Kind.entry) ->
( Asttypes.Labelled entry.label,
( (Asttypes.Labelled entry.label : Asttypes.arg_label),
Some
{
expr with
Expand All @@ -785,7 +785,7 @@ module Compile = struct
args
|> List.find_opt (fun arg ->
match arg with
| Asttypes.Labelled s, Some _ -> s = label
| (Labelled s : Asttypes.arg_label), Some _ -> s = label
| _ -> false)
in
let argOpt =
Expand Down
2 changes: 1 addition & 1 deletion analysis/reanalyze/src/DeadValue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ let processOptionalArgs ~expType ~(locFrom : Location.t) ~locTo ~path args =
| None -> Some false
in
match lbl with
| Asttypes.Optional s when not locFrom.loc_ghost ->
| (Optional s : Asttypes.arg_label) when not locFrom.loc_ghost ->
if argIsSupplied <> Some false then supplied := s :: !supplied;
if argIsSupplied = None then suppliedMaybe := s :: !suppliedMaybe
| _ -> ());
Expand Down
4 changes: 3 additions & 1 deletion analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,9 @@ and getCompletionsForContextPath ~debug ~full ~opens ~rawOpens ~pos ~env ~exact
(* compute the application of the first label, then the next ones *)
let args = processApply args [label] in
processApply args nextLabels
| (Asttypes.Nolabel, _) :: nextArgs, [Asttypes.Nolabel] -> nextArgs
| ( ((Nolabel : Asttypes.arg_label), _) :: nextArgs,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example of extra type annotations.

[(Nolabel : Asttypes.arg_label)] ) ->
nextArgs
| ((Labelled _, _) as arg) :: nextArgs, [Nolabel] ->
arg :: processApply nextArgs labels
| (Optional _, _) :: nextArgs, [Nolabel] -> processApply nextArgs labels
Expand Down
13 changes: 7 additions & 6 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
(* Transform away pipe with apply call *)
exprToContextPath
{
pexp_desc = Pexp_apply {funct = d; args = (Nolbl, lhs) :: args; partial};
pexp_desc =
Pexp_apply {funct = d; args = (Nolabel, lhs) :: args; partial};
pexp_loc;
pexp_attributes;
}
Expand All @@ -288,7 +289,7 @@ let rec exprToContextPathInner (e : Parsetree.expression) =
Pexp_apply
{
funct = {pexp_desc = Pexp_ident id; pexp_loc; pexp_attributes};
args = [(Nolbl, lhs)];
args = [(Nolabel, lhs)];
partial;
};
pexp_loc;
Expand Down Expand Up @@ -1437,7 +1438,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
| Some (ctxPath, currentUnlabelledCount) ->
(processingFun :=
match lbl with
| Nolbl -> Some (ctxPath, currentUnlabelledCount + 1)
| Nolabel -> Some (ctxPath, currentUnlabelledCount + 1)
| _ -> Some (ctxPath, currentUnlabelledCount));
if Debug.verbose () then
print_endline "[expr_iter] Completing for argument value";
Expand All @@ -1447,10 +1448,10 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
functionContextPath = ctxPath;
argumentLabel =
(match lbl with
| Nolbl ->
| Nolabel ->
Unlabelled {argumentPosition = currentUnlabelledCount}
| Opt {txt = name} -> Optional name
| Lbl {txt = name} -> Labelled name);
| Optional {txt = name} -> Optional name
| Labelled {txt = name} -> Labelled name);
})
in
(match defaultExpOpt with
Expand Down
5 changes: 3 additions & 2 deletions analysis/src/CompletionJsx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -465,14 +465,15 @@ let extractJsxProps ~(compName : Longident.t Location.loc) ~args =
in
let rec processProps ~acc args =
match args with
| (Asttypes.Lbl {txt = "children"}, {Parsetree.pexp_loc}) :: _ ->
| (Asttypes.Labelled {txt = "children"}, {Parsetree.pexp_loc}) :: _ ->
{
compName;
props = List.rev acc;
childrenStart =
(if pexp_loc.loc_ghost then None else Some (Loc.start pexp_loc));
}
| ((Lbl {txt = s; loc} | Opt {txt = s; loc}), (eProp : Parsetree.expression))
| ( (Labelled {txt = s; loc} | Optional {txt = s; loc}),
(eProp : Parsetree.expression) )
:: rest -> (
let namedArgLoc = if loc = Location.none then None else Some loc in
match namedArgLoc with
Expand Down
4 changes: 2 additions & 2 deletions analysis/src/CreateInterface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ let printSignature ~extractor ~signature =
labelDecl.ld_type
in
let lblName = labelDecl.ld_id |> Ident.name in
let lbl =
if labelDecl.ld_optional then Asttypes.Optional lblName
let lbl : Asttypes.arg_label =
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another example of annotation required.

if labelDecl.ld_optional then Optional lblName
else Labelled lblName
in
{
Expand Down
6 changes: 3 additions & 3 deletions analysis/src/DumpAst.ml
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ and printExprItem expr ~pos ~indentation =
^ addIndentation (indentation + 1)
^ "arg: "
^ (match arg with
| Nolbl -> "Nolabel"
| Lbl {txt = name} -> "Labelled(" ^ name ^ ")"
| Opt {txt = name} -> "Optional(" ^ name ^ ")")
| Nolabel -> "Nolabel"
| Labelled {txt = name} -> "Labelled(" ^ name ^ ")"
| Optional {txt = name} -> "Optional(" ^ name ^ ")")
^ ",\n"
^ addIndentation (indentation + 2)
^ "pattern: "
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/SemanticTokens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ let command ~debug ~emitter ~path =

let posOfGreatherthanAfterProps =
let rec loop = function
| (Asttypes.Lbl {txt = "children"}, {Parsetree.pexp_loc}) :: _ ->
| (Asttypes.Labelled {txt = "children"}, {Parsetree.pexp_loc}) :: _ ->
Loc.start pexp_loc
| _ :: args -> loop args
| [] -> (* should not happen *) (-1, -1)
Expand Down
8 changes: 4 additions & 4 deletions analysis/src/SharedTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ module Completable = struct
contextPathToString cp ^ "("
^ (labels
|> List.map (function
| Asttypes.Nolabel -> "Nolabel"
| (Nolabel : Asttypes.arg_label) -> "Nolabel"
| Labelled s -> "~" ^ s
| Optional s -> "?" ^ s)
|> String.concat ", ")
Expand Down Expand Up @@ -898,7 +898,7 @@ type arg = {label: label; exp: Parsetree.expression}
let extractExpApplyArgs ~args =
let rec processArgs ~acc args =
match args with
| ( ((Asttypes.Lbl {txt = s; loc} | Opt {txt = s; loc}) as label),
| ( ((Asttypes.Labelled {txt = s; loc} | Optional {txt = s; loc}) as label),
(e : Parsetree.expression) )
:: rest -> (
let namedArgLoc = if loc = Location.none then None else Some loc in
Expand All @@ -909,15 +909,15 @@ let extractExpApplyArgs ~args =
name = s;
opt =
(match label with
| Opt _ -> true
| Optional _ -> true
| _ -> false);
posStart = Loc.start loc;
posEnd = Loc.end_ loc;
}
in
processArgs ~acc:({label = Some labelled; exp = e} :: acc) rest
| None -> processArgs ~acc rest)
| (Nolbl, (e : Parsetree.expression)) :: rest ->
| (Nolabel, (e : Parsetree.expression)) :: rest ->
if e.pexp_loc.loc_ghost then processArgs ~acc rest
else processArgs ~acc:({label = None; exp = e} :: acc) rest
| [] -> List.rev acc
Expand Down
15 changes: 8 additions & 7 deletions analysis/src/SignatureHelp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ let extractParameters ~signature ~typeStrForParser ~labelPrefixLen =
(* The AST locations does not account for "=?" of optional arguments, so add that to the offset here if needed. *)
let endOffset =
match argumentLabel with
| Asttypes.Opt _ -> endOffset + 2
| Asttypes.Optional _ -> endOffset + 2
| _ -> endOffset
in
extractParams nextFunctionExpr
Expand All @@ -154,25 +154,25 @@ let findActiveParameter ~argAtCursor ~args =
(* If a function only has one, unlabelled argument, we can safely assume that's active whenever we're in the signature help for that function,
even if we technically didn't find anything at the cursor (which we don't for empty expressions). *)
match args with
| [(Asttypes.Nolabel, _)] -> Some 0
| [((Nolabel : Asttypes.arg_label), _)] -> Some 0
| _ -> None)
| Some (Unlabelled unlabelledArgumentIndex) ->
let index = ref 0 in
args
|> List.find_map (fun (label, _) ->
match label with
| Asttypes.Nolabel when !index = unlabelledArgumentIndex ->
| (Nolabel : Asttypes.arg_label)
when !index = unlabelledArgumentIndex ->
Some !index
| _ ->
index := !index + 1;
None)
| Some (Labelled name) ->
let index = ref 0 in
args
|> List.find_map (fun (label, _) ->
|> List.find_map (fun ((label : Asttypes.arg_label), _) ->
match label with
| (Asttypes.Labelled labelName | Optional labelName)
when labelName = name ->
| (Labelled labelName | Optional labelName) when labelName = name ->
Some !index
| _ ->
index := !index + 1;
Expand Down Expand Up @@ -483,7 +483,8 @@ let signatureHelp ~path ~pos ~currentFile ~debug ~allowForConstructorPayloads =
documentation =
(match
args
|> List.find_opt (fun (lbl, _) ->
|> List.find_opt
(fun ((lbl : Asttypes.arg_label), _) ->
let argCount = !unlabelledArgCount in
unlabelledArgCount := argCount + 1;
match (lbl, argLabel) with
Expand Down
4 changes: 2 additions & 2 deletions analysis/src/TypeUtils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ module Codegen = struct
let mkFailWithExp () =
Ast_helper.Exp.apply
(Ast_helper.Exp.ident {txt = Lident "failwith"; loc = Location.none})
[(Nolbl, Ast_helper.Exp.constant (Pconst_string ("TODO", None)))]
[(Nolabel, Ast_helper.Exp.constant (Pconst_string ("TODO", None)))]

let mkConstructPat ?payload name =
Ast_helper.Pat.construct
Expand Down Expand Up @@ -1123,7 +1123,7 @@ let getFirstFnUnlabelledArgType ~env ~full t =
in
let rec findFirstUnlabelledArgType labels =
match labels with
| (Asttypes.Nolabel, t) :: _ -> Some t
| ((Nolabel : Asttypes.arg_label), t) :: _ -> Some t
| _ :: rest -> findFirstUnlabelledArgType rest
| [] -> None
in
Expand Down
4 changes: 2 additions & 2 deletions analysis/src/Xform.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module IfThenElse = struct
Pexp_ident
{txt = Longident.Lident (("==" | "!=") as op)};
};
args = [(Nolbl, arg1); (Nolbl, arg2)];
args = [(Nolabel, arg1); (Nolabel, arg2)];
};
},
e1,
Expand Down Expand Up @@ -300,7 +300,7 @@ module AddTypeAnnotation = struct
match e.pexp_desc with
| Pexp_fun {arg_label; lhs = pat; rhs = e} ->
let isUnlabeledOnlyArg =
argNum = 1 && arg_label = Nolbl
argNum = 1 && arg_label = Nolabel
&&
match e.pexp_desc with
| Pexp_fun _ -> false
Expand Down
29 changes: 20 additions & 9 deletions compiler/frontend/ast_compatible.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open Parsetree
let default_loc = Location.none

let arrow ?loc ?attrs ~arity a b =
Ast_helper.Typ.arrow ?loc ?attrs ~arity Nolbl a b
Ast_helper.Typ.arrow ?loc ?attrs ~arity Nolabel a b

let apply_simple ?(loc = default_loc) ?(attrs = []) (fn : expression)
(args : expression list) : expression =
Expand All @@ -42,7 +42,8 @@ let apply_simple ?(loc = default_loc) ?(attrs = []) (fn : expression)
Pexp_apply
{
funct = fn;
args = Ext_list.map args (fun x -> (Asttypes.Nolbl, x));
args =
Ext_list.map args (fun x -> ((Nolabel : Asttypes.arg_label_loc), x));
partial = false;
};
}
Expand All @@ -51,7 +52,8 @@ let app1 ?(loc = default_loc) ?(attrs = []) fn arg1 : expression =
{
pexp_loc = loc;
pexp_attributes = attrs;
pexp_desc = Pexp_apply {funct = fn; args = [(Nolbl, arg1)]; partial = false};
pexp_desc =
Pexp_apply {funct = fn; args = [(Nolabel, arg1)]; partial = false};
}

let app2 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 : expression =
Expand All @@ -60,7 +62,7 @@ let app2 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 : expression =
pexp_attributes = attrs;
pexp_desc =
Pexp_apply
{funct = fn; args = [(Nolbl, arg1); (Nolbl, arg2)]; partial = false};
{funct = fn; args = [(Nolabel, arg1); (Nolabel, arg2)]; partial = false};
}

let app3 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 arg3 : expression =
Expand All @@ -71,7 +73,7 @@ let app3 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 arg3 : expression =
Pexp_apply
{
funct = fn;
args = [(Nolbl, arg1); (Nolbl, arg2); (Nolbl, arg3)];
args = [(Nolabel, arg1); (Nolabel, arg2); (Nolabel, arg3)];
partial = false;
};
}
Expand All @@ -82,7 +84,14 @@ let fun_ ?(loc = default_loc) ?(attrs = []) ?(async = false) ~arity pat exp =
pexp_attributes = attrs;
pexp_desc =
Pexp_fun
{arg_label = Nolbl; default = None; lhs = pat; rhs = exp; arity; async};
{
arg_label = Nolabel;
default = None;
lhs = pat;
rhs = exp;
arity;
async;
};
}

let const_exp_string ?(loc = default_loc) ?(attrs = []) ?delimiter (s : string)
Expand Down Expand Up @@ -111,7 +120,9 @@ let apply_labels ?(loc = default_loc) ?(attrs = []) fn
funct = fn;
args =
Ext_list.map args (fun (l, a) ->
(Asttypes.Lbl {txt = l; loc = Location.none}, a));
( (Labelled {txt = l; loc = Location.none}
: Asttypes.arg_label_loc),
a ));
partial = false;
};
}
Expand All @@ -120,7 +131,7 @@ let label_arrow ?(loc = default_loc) ?(attrs = []) ~arity txt arg ret :
core_type =
{
ptyp_desc =
Ptyp_arrow {lbl = Asttypes.Lbl {txt; loc = default_loc}; arg; ret; arity};
Ptyp_arrow {lbl = Labelled {txt; loc = default_loc}; arg; ret; arity};
ptyp_loc = loc;
ptyp_attributes = attrs;
}
Expand All @@ -129,7 +140,7 @@ let opt_arrow ?(loc = default_loc) ?(attrs = []) ~arity txt arg ret : core_type
=
{
ptyp_desc =
Ptyp_arrow {lbl = Asttypes.Opt {txt; loc = default_loc}; arg; ret; arity};
Ptyp_arrow {lbl = Optional {txt; loc = default_loc}; arg; ret; arity};
ptyp_loc = loc;
ptyp_attributes = attrs;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/frontend/ast_core_type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -171,5 +171,5 @@ let list_of_arrow (ty : t) : t * param_type list =
let add_last_obj (ty : t) (obj : t) =
let result, params = list_of_arrow ty in
mk_fn_type
(params @ [{label = Nolbl; ty = obj; attr = []; loc = obj.ptyp_loc}])
(params @ [{label = Nolabel; ty = obj; attr = []; loc = obj.ptyp_loc}])
result
2 changes: 1 addition & 1 deletion compiler/frontend/ast_core_type_class_type.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
| Meth_callback attr, attrs -> (attrs, attr +> ty)
in
Ast_compatible.object_field name attrs
(Ast_typ_uncurry.to_uncurry_type loc self Nolbl core_type
(Ast_typ_uncurry.to_uncurry_type loc self Nolabel core_type
(Ast_literal.type_unit ~loc ()))
in
let not_getter_setter ty =
Expand Down
7 changes: 4 additions & 3 deletions compiler/frontend/ast_exp_apply.ml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
| Pexp_apply {funct = fn1; args; partial} ->
Bs_ast_invariant.warn_discarded_unused_attributes fn1.pexp_attributes;
{
pexp_desc = Pexp_apply {funct = fn1; args = (Nolbl, a) :: args; partial};
pexp_desc =
Pexp_apply {funct = fn1; args = (Nolabel, a) :: args; partial};
pexp_loc = e.pexp_loc;
pexp_attributes = e.pexp_attributes @ f.pexp_attributes;
}
Expand All @@ -115,7 +116,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
Pexp_apply
{
funct = fn;
args = (Nolbl, bounded_obj_arg) :: args;
args = (Nolabel, bounded_obj_arg) :: args;
partial = false;
};
pexp_attributes = [];
Expand Down Expand Up @@ -169,7 +170,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
let arg = self.expr self arg in
let fn = Exp.send ~loc obj {txt = name ^ Literals.setter_suffix; loc} in
Exp.constraint_ ~loc
(Exp.apply ~loc fn [(Nolbl, arg)])
(Exp.apply ~loc fn [(Nolabel, arg)])
(Ast_literal.type_unit ~loc ())
in
match obj.pexp_desc with
Expand Down
2 changes: 1 addition & 1 deletion compiler/frontend/ast_exp_extension.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ let handle_extension e (self : Bs_ast_mapper.mapper)
Exp.apply ~loc
(Exp.ident ~loc {txt = Longident.parse "Js.Exn.raiseError"; loc})
[
( Nolbl,
( Nolabel,
Exp.constant ~loc
(Pconst_string
( (pretext
Expand Down
Loading