Skip to content

Rename @ns.* to @res.* in parser/printer and outcome printer. #5862

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

Merged
merged 6 commits into from
Nov 28, 2022
Merged
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
10 changes: 5 additions & 5 deletions jscomp/main/builtin_cmi_datasets.ml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jscomp/ml/datarepr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ let constructor_descrs ty_path decl cstrs =
if cd_args = Cstr_tuple [] then incr num_consts else incr num_nonconsts;
if cd_res = None then incr num_normal)
cstrs;
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "res.optional") in
let rec describe_constructors idx_const idx_nonconst = function
[] -> []
| {cd_id; cd_args; cd_res; cd_loc; cd_attributes} :: rem ->
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/printtyp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ and tree_of_constructor cd =
(name, args, Some ret)

and tree_of_label l =
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "ns.optional") in
let opt = l.ld_attributes |> List.exists (fun ({txt}, _) -> txt = "res.optional") in
let typ = match l.ld_type.desc with
| Tconstr (p, [t1], _) when opt && Path.same p Predef.path_option -> t1
| _ -> l.ld_type in
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ let check_optional_attr env ld attrs loc =
raise (Error (loc, env, Field_not_optional (ld.lbl_name, ld.lbl_res)));
true in
Ext_list.exists attrs (fun ({txt}, _) ->
txt = "ns.optional" && check_redundant ())
txt = "res.optional" && check_redundant ())

(* unification inside type_pat*)
let unify_pat_types loc env ty ty' =
Expand Down
4 changes: 2 additions & 2 deletions jscomp/ml/typedecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ let transl_declaration env sdecl id =
| (_,_,loc)::_ ->
Location.prerr_warning loc Warnings.Constraint_on_gadt
end;
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "res.optional") in
let scstrs =
Ext_list.map scstrs (fun ({pcd_args} as cstr) ->
match pcd_args with
Expand Down Expand Up @@ -409,7 +409,7 @@ let transl_declaration env sdecl id =
let tcstrs, cstrs = List.split (List.map make_cstr scstrs) in
Ttype_variant tcstrs, Type_variant cstrs
| Ptype_record lbls ->
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "res.optional") in
let optionalLabels =
Ext_list.filter_map lbls
(fun lbl -> if has_optional lbl.pld_attributes then Some lbl.pld_name.txt else None) in
Expand Down
2 changes: 1 addition & 1 deletion lib/4.06.1/unstable/all_ounit_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43418,7 +43418,7 @@ let constructor_descrs ty_path decl cstrs =
if cd_args = Cstr_tuple [] then incr num_consts else incr num_nonconsts;
if cd_res = None then incr num_normal)
cstrs;
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "ns.optional") in
let has_optional attrs = Ext_list.exists attrs (fun ({txt },_) -> txt = "res.optional") in
let rec describe_constructors idx_const idx_nonconst = function
[] -> []
| {cd_id; cd_args; cd_res; cd_loc; cd_attributes} :: rem ->
Expand Down
88 changes: 44 additions & 44 deletions lib/4.06.1/unstable/js_compiler.ml

Large diffs are not rendered by default.

116 changes: 59 additions & 57 deletions lib/4.06.1/unstable/js_playground_compiler.ml

Large diffs are not rendered by default.

118 changes: 60 additions & 58 deletions lib/4.06.1/whole_compiler.ml

Large diffs are not rendered by default.

64 changes: 32 additions & 32 deletions res_syntax/benchmarks/data/Napkinscript.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3189,15 +3189,15 @@ end = struct

let processBracesAttr expr =
match expr.pexp_attributes with
| (({txt = "ns.braces"}, _) as attr)::attrs ->
| (({txt = "res.braces"}, _) as attr)::attrs ->
(Some attr, {expr with pexp_attributes = attrs})
| _ ->
(None, expr)

let filterParsingAttrs attrs =
List.filter (fun attr ->
match attr with
| ({Location.txt = ("ns.ternary" | "ns.braces" | "bs" | "ns.namedArgLoc")}, _) -> false
| ({Location.txt = ("res.ternary" | "res.braces" | "bs" | "res.namedArgLoc")}, _) -> false
| _ -> true
) attrs

Expand Down Expand Up @@ -3301,7 +3301,7 @@ end = struct

let hasAttributes attrs =
List.exists (fun attr -> match attr with
| ({Location.txt = "bs" | "ns.ternary" | "ns.braces"}, _) -> false
| ({Location.txt = "bs" | "res.ternary" | "res.braces"}, _) -> false
| _ -> true
) attrs

Expand All @@ -3315,7 +3315,7 @@ end = struct
let rec hasTernaryAttribute attrs =
match attrs with
| [] -> false
| ({Location.txt="ns.ternary"},_)::_ -> true
| ({Location.txt="res.ternary"},_)::_ -> true
| _::attrs -> hasTernaryAttribute attrs

let isTernaryExpr expr = match expr with
Expand Down Expand Up @@ -3346,7 +3346,7 @@ end = struct

let filterTernaryAttributes attrs =
List.filter (fun attr -> match attr with
|({Location.txt="ns.ternary"},_) -> false
|({Location.txt="res.ternary"},_) -> false
| _ -> true
) attrs

Expand Down Expand Up @@ -3403,13 +3403,13 @@ end = struct

let filterPrinteableAttributes attrs =
List.filter (fun attr -> match attr with
| ({Location.txt="bs" | "ns.ternary"}, _) -> false
| ({Location.txt="bs" | "res.ternary"}, _) -> false
| _ -> true
) attrs

let partitionPrinteableAttributes attrs =
List.partition (fun attr -> match attr with
| ({Location.txt="bs" | "ns.ternary"}, _) -> false
| ({Location.txt="bs" | "res.ternary"}, _) -> false
| _ -> true
) attrs

Expand Down Expand Up @@ -5189,7 +5189,7 @@ module CommentTable = struct
walkList
~getLoc:(fun (_argLabel, expr) ->
let loc = match expr.Parsetree.pexp_attributes with
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_attrs ->
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_attrs ->
{loc with loc_end = expr.pexp_loc.loc_end}
| _ ->
expr.pexp_loc
Expand All @@ -5207,7 +5207,7 @@ module CommentTable = struct
~getLoc:(fun (_attrs, _argLbl, exprOpt, pattern) ->
let open Parsetree in
let startPos = match pattern.ppat_attributes with
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_attrs ->
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_attrs ->
loc.loc_start
| _ ->
pattern.ppat_loc.loc_start
Expand Down Expand Up @@ -5279,7 +5279,7 @@ module CommentTable = struct

and walkExprArgument (_argLabel, expr) t comments =
match expr.Parsetree.pexp_attributes with
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_attrs ->
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_attrs ->
let (leading, trailing) = partitionLeadingTrailing comments loc in
attach t.leading loc leading;
let (afterLabel, rest) = partitionAdjacentTrailing loc trailing in
Expand Down Expand Up @@ -7706,7 +7706,7 @@ module Printer = struct
ParsetreeViewer.isBinaryExpression expr ||
(match vb.pvb_expr with
| {
pexp_attributes = [({Location.txt="ns.ternary"}, _)];
pexp_attributes = [({Location.txt="res.ternary"}, _)];
pexp_desc = Pexp_ifthenelse (ifExpr, _, _)
} ->
ParsetreeViewer.isBinaryExpression ifExpr || ParsetreeViewer.hasAttributes ifExpr.pexp_attributes
Expand Down Expand Up @@ -9250,7 +9250,7 @@ module Printer = struct
match Parens.binaryExpr {expr with
pexp_attributes = List.filter (fun attr ->
match attr with
| ({Location.txt = ("ns.braces")}, _) -> false
| ({Location.txt = ("res.braces")}, _) -> false
| _ -> true
) expr.pexp_attributes
} with
Expand Down Expand Up @@ -9402,7 +9402,7 @@ module Printer = struct
ParsetreeViewer.isBinaryExpression targetExpr ||
(match targetExpr with
| {
pexp_attributes = [({Location.txt="ns.ternary"}, _)];
pexp_attributes = [({Location.txt="res.ternary"}, _)];
pexp_desc = Pexp_ifthenelse (ifExpr, _, _)
} ->
ParsetreeViewer.isBinaryExpression ifExpr || ParsetreeViewer.hasAttributes ifExpr.pexp_attributes
Expand Down Expand Up @@ -9599,7 +9599,7 @@ module Printer = struct
| (
(Asttypes.Labelled lblTxt | Optional lblTxt) as lbl,
{
Parsetree.pexp_attributes = [({Location.txt = "ns.namedArgLoc"; loc = argLoc}, _)];
Parsetree.pexp_attributes = [({Location.txt = "res.namedArgLoc"; loc = argLoc}, _)];
pexp_desc = Pexp_ident {txt = Longident.Lident ident}
}
) when lblTxt = ident (* jsx punning *) ->
Expand Down Expand Up @@ -9631,7 +9631,7 @@ module Printer = struct
end
| (lbl, expr) ->
let (argLoc, expr) = match expr.pexp_attributes with
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::attrs ->
| ({Location.txt = "res.namedArgLoc"; loc}, _)::attrs ->
(loc, {expr with pexp_attributes = attrs})
| _ ->
Location.none, expr
Expand Down Expand Up @@ -9845,11 +9845,11 @@ module Printer = struct
| (
(Asttypes.Labelled lbl),
({pexp_desc=Pexp_ident {txt = Longident.Lident name};
pexp_attributes = ([] | [({Location.txt = "ns.namedArgLoc";}, _)])
pexp_attributes = ([] | [({Location.txt = "res.namedArgLoc";}, _)])
} as argExpr)
) when lbl = name && not (ParsetreeViewer.isBracedExpr argExpr) ->
let loc = match arg.pexp_attributes with
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_ -> loc
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_ -> loc
| _ -> arg.pexp_loc
in
let doc = Doc.concat [
Expand All @@ -9866,11 +9866,11 @@ module Printer = struct
typ
);
pexp_loc;
pexp_attributes = ([] | [({Location.txt = "ns.namedArgLoc";}, _)]) as attrs
pexp_attributes = ([] | [({Location.txt = "res.namedArgLoc";}, _)]) as attrs
}
) when lbl = name && not (ParsetreeViewer.isBracedExpr argExpr) ->
let loc = match attrs with
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_ ->
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_ ->
{loc with loc_end = pexp_loc.loc_end}
| _ -> arg.pexp_loc
in
Expand All @@ -9885,11 +9885,11 @@ module Printer = struct
| (
(Asttypes.Optional lbl),
{pexp_desc=Pexp_ident {txt = Longident.Lident name};
pexp_attributes = ([] | [({Location.txt = "ns.namedArgLoc";}, _)])
pexp_attributes = ([] | [({Location.txt = "res.namedArgLoc";}, _)])
}
) when lbl = name ->
let loc = match arg.pexp_attributes with
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_ -> loc
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_ -> loc
| _ -> arg.pexp_loc
in
let doc = Doc.concat [
Expand All @@ -9900,7 +9900,7 @@ module Printer = struct
printComments doc cmtTbl loc
| (_lbl, expr) ->
let (argLoc, expr) = match expr.pexp_attributes with
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::attrs ->
| ({Location.txt = "res.namedArgLoc"; loc}, _)::attrs ->
(loc, {expr with pexp_attributes = attrs})
| _ ->
expr.pexp_loc, expr
Expand Down Expand Up @@ -10095,7 +10095,7 @@ module Printer = struct
| (
(Asttypes.Labelled lbl | Optional lbl),
{ppat_desc = Ppat_var stringLoc;
ppat_attributes = ([] | [({Location.txt = "ns.namedArgLoc";}, _)])
ppat_attributes = ([] | [({Location.txt = "res.namedArgLoc";}, _)])
}
) when lbl = stringLoc.txt ->
(* ~d *)
Expand All @@ -10106,7 +10106,7 @@ module Printer = struct
| (
(Asttypes.Labelled lbl | Optional lbl),
({ppat_desc = Ppat_constraint ({ ppat_desc = Ppat_var { txt } }, typ);
ppat_attributes = ([] | [({Location.txt = "ns.namedArgLoc";}, _)])
ppat_attributes = ([] | [({Location.txt = "res.namedArgLoc";}, _)])
})
) when lbl = txt ->
(* ~d: e *)
Expand Down Expand Up @@ -10141,13 +10141,13 @@ module Printer = struct
let cmtLoc = match defaultExpr with
| None ->
begin match pattern.ppat_attributes with
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_ ->
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_ ->
{loc with loc_end = pattern.ppat_loc.loc_end}
| _ -> pattern.ppat_loc
end
| Some expr ->
let startPos = match pattern.ppat_attributes with
| ({Location.txt = "ns.namedArgLoc"; loc}, _)::_ ->
| ({Location.txt = "res.namedArgLoc"; loc}, _)::_ ->
loc.loc_start
| _ -> pattern.ppat_loc.loc_start
in {
Expand Down Expand Up @@ -11991,7 +11991,7 @@ module ParsetreeCompatibility = struct
{pc_lhs = {ppat_desc = Ppat_construct ({txt = Longident.Lident "false"}, None)}; pc_rhs = elseExpr };
]
) ->
let ternaryMarker = (Location.mknoloc "ns.ternary", Parsetree.PStr []) in
let ternaryMarker = (Location.mknoloc "res.ternary", Parsetree.PStr []) in
Ast_helper.Exp.ifthenelse
~loc:expr.pexp_loc
~attrs:(ternaryMarker::expr.pexp_attributes)
Expand Down Expand Up @@ -12322,8 +12322,8 @@ end

let jsxAttr = (Location.mknoloc "JSX", Parsetree.PStr [])
let uncurryAttr = (Location.mknoloc "bs", Parsetree.PStr [])
let ternaryAttr = (Location.mknoloc "ns.ternary", Parsetree.PStr [])
let makeBracesAttr loc = (Location.mkloc "ns.braces" loc, Parsetree.PStr [])
let ternaryAttr = (Location.mknoloc "res.ternary", Parsetree.PStr [])
let makeBracesAttr loc = (Location.mkloc "res.braces" loc, Parsetree.PStr [])

type typDefOrExt =
| TypeDef of {recFlag: Asttypes.rec_flag; types: Parsetree.type_declaration list}
Expand Down Expand Up @@ -13769,7 +13769,7 @@ end
| Tilde ->
Parser.next p;
let (lblName, loc) = parseLident p in
let propLocAttr = (Location.mkloc "ns.namedArgLoc" loc, Parsetree.PStr []) in
let propLocAttr = (Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr []) in
begin match p.Parser.token with
| Comma | Equal | Rparen ->
let loc = mkLoc startPos p.prevEndPos in
Expand Down Expand Up @@ -14760,7 +14760,7 @@ end
| Question | Lident _ ->
let optional = Parser.optional p Question in
let (name, loc) = parseLident p in
let propLocAttr = (Location.mkloc "ns.namedArgLoc" loc, Parsetree.PStr []) in
let propLocAttr = (Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr []) in
(* optional punning: <foo ?a /> *)
if optional then
Some (
Expand Down Expand Up @@ -15444,7 +15444,7 @@ end
Parser.next p;
let endPos = p.prevEndPos in
let loc = mkLoc startPos endPos in
let propLocAttr = (Location.mkloc "ns.namedArgLoc" loc, Parsetree.PStr []) in
let propLocAttr = (Location.mkloc "res.namedArgLoc" loc, Parsetree.PStr []) in
let identExpr = Ast_helper.Exp.ident ~attrs:[propLocAttr] ~loc (
Location.mkloc (Longident.Lident ident) loc
) in
Expand Down
Loading