Skip to content

Remove a number of ast nodes never populated by the .res parser, and resulting dead code. #6830

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 29 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f698f1b
Remove str/sig class type from untyped and typed ast.
cristianoc Jun 25, 2024
81338d0
Remove Pexp_object.
cristianoc Jun 25, 2024
acacc4b
Remove class_expr and related definitions.
cristianoc Jun 25, 2024
5148bd4
Remove class_field.
cristianoc Jun 25, 2024
42ce69e
Remove class_field_desc and class_field_kind
cristianoc Jun 25, 2024
cf4e562
Make Pcty_signature dummy.
cristianoc Jun 25, 2024
e244142
Remove class_signature.
cristianoc Jun 25, 2024
b237476
Remove class_type_field
cristianoc Jun 25, 2024
690fafa
Remove class_type_declaration and resulting dead code.
cristianoc Jun 25, 2024
0c55b0b
Remove class_infos and resulting dead code.
cristianoc Jun 25, 2024
97cc0fa
Remove class_type and dead code.
cristianoc Jun 25, 2024
cda7c4e
Remove Ptyp_class
cristianoc Jun 25, 2024
6c079e3
Remove remaining unused parts of typeclass.ml*
cristianoc Jun 25, 2024
c64a7ba
Clean up more unused class code.
cristianoc Jun 25, 2024
12f4b7a
Clean up Sig_class_type and dead code.
cristianoc Jun 25, 2024
89859b4
Remove enter/leave class type decl.
cristianoc Jun 25, 2024
9b1d0a9
Clean up env cltype.
cristianoc Jun 25, 2024
934a5b0
Clean up cltype.
cristianoc Jun 25, 2024
5e313b8
Remove class_type_declaration
cristianoc Jun 25, 2024
bdbcb2e
Remove uses of class declaration, and made class_type abstract before…
cristianoc Jun 25, 2024
ffb7a6f
Remove class cases from typed mapper.
cristianoc Jun 25, 2024
f1ff4e8
Remove class_type_field.
cristianoc Jun 25, 2024
67a52eb
Remove class_type_desc and class_signature.
cristianoc Jun 25, 2024
e8e0c0c
Remove class_type from typed tree.
cristianoc Jun 25, 2024
50a03a6
Remove class_signature from types.
cristianoc Jun 25, 2024
c595f82
Remove class_type.
cristianoc Jun 25, 2024
e9c3dc7
Clean up unused poly variant types.
cristianoc Jun 25, 2024
e729841
Remove now-unused includeclass.ml*
cristianoc Jun 25, 2024
ce4db7d
Update CHANGELOG.md
cristianoc Jun 27, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
- Convert OCaml codebase to snake case style. https://github.com/rescript-lang/rescript-compiler/pull/6702
- Refactor uppercase exotic ident handling. https://github.com/rescript-lang/rescript-compiler/pull/6779
- Fix `-nostdlib` internal compiler option. https://github.com/rescript-lang/rescript-compiler/pull/6824
- Remove a number of ast nodes never populated by the .res parser, and resulting dead code. https://github.com/rescript-lang/rescript-compiler/pull/6830

#### :nail_care: Polish

Expand Down
132 changes: 4 additions & 128 deletions jscomp/frontend/bs_ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ type mapper = {
attributes: mapper -> attribute list -> attribute list;
case: mapper -> case -> case;
cases: mapper -> case list -> case list;
class_expr: mapper -> class_expr -> class_expr;
class_field: mapper -> class_field -> class_field;
class_signature: mapper -> class_signature -> class_signature;
class_structure: mapper -> class_structure -> class_structure;
class_type: mapper -> class_type -> class_type;
class_type_declaration:
mapper -> class_type_declaration -> class_type_declaration;
class_type_field: mapper -> class_type_field -> class_type_field;
constructor_declaration:
mapper -> constructor_declaration -> constructor_declaration;
expr: mapper -> expression -> expression;
Expand Down Expand Up @@ -115,8 +107,7 @@ module T = struct
constr ~loc ~attrs (map_loc sub lid) (List.map (sub.typ sub) tl)
| Ptyp_object (l, o) ->
object_ ~loc ~attrs (List.map (object_field sub) l) o
| Ptyp_class (lid, tl) ->
class_ ~loc ~attrs (map_loc sub lid) (List.map (sub.typ sub) tl)
| Ptyp_class () -> assert false
| Ptyp_alias (t, s) -> alias ~loc ~attrs (sub.typ sub t) s
| Ptyp_variant (rl, b, ll) ->
variant ~loc ~attrs (List.map (row_field sub) rl) b ll
Expand Down Expand Up @@ -192,44 +183,6 @@ module T = struct
~attrs:(sub.attributes sub pext_attributes)
end

module CT = struct
(* Type expressions for the class language *)

let map sub {pcty_loc = loc; pcty_desc = desc; pcty_attributes = attrs} =
let open Cty in
let loc = sub.location sub loc in
let attrs = sub.attributes sub attrs in
match desc with
| Pcty_constr (lid, tys) ->
constr ~loc ~attrs (map_loc sub lid) (List.map (sub.typ sub) tys)
| Pcty_signature x -> signature ~loc ~attrs (sub.class_signature sub x)
| Pcty_arrow (lab, t, ct) ->
arrow ~loc ~attrs lab (sub.typ sub t) (sub.class_type sub ct)
| Pcty_extension x -> extension ~loc ~attrs (sub.extension sub x)
| Pcty_open (ovf, lid, ct) ->
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.class_type sub ct)

let map_field sub {pctf_desc = desc; pctf_loc = loc; pctf_attributes = attrs}
=
let open Ctf in
let loc = sub.location sub loc in
let attrs = sub.attributes sub attrs in
match desc with
| Pctf_inherit ct -> inherit_ ~loc ~attrs (sub.class_type sub ct)
| Pctf_val (s, m, v, t) ->
val_ ~loc ~attrs (map_loc sub s) m v (sub.typ sub t)
| Pctf_method (s, p, v, t) ->
method_ ~loc ~attrs (map_loc sub s) p v (sub.typ sub t)
| Pctf_constraint (t1, t2) ->
constraint_ ~loc ~attrs (sub.typ sub t1) (sub.typ sub t2)
| Pctf_attribute x -> attribute ~loc (sub.attribute sub x)
| Pctf_extension x -> extension ~loc ~attrs (sub.extension sub x)

let map_signature sub {pcsig_self; pcsig_fields} =
Csig.mk (sub.typ sub pcsig_self)
(List.map (sub.class_type_field sub) pcsig_fields)
end

module MT = struct
(* Type expressions for the module language *)

Expand Down Expand Up @@ -280,8 +233,7 @@ module MT = struct
| Psig_open x -> open_ ~loc (sub.open_description sub x)
| Psig_include x -> include_ ~loc (sub.include_description sub x)
| Psig_class () -> assert false
| Psig_class_type l ->
class_type ~loc (List.map (sub.class_type_declaration sub) l)
| Psig_class_type () -> assert false
| Psig_extension (x, attrs) ->
extension ~loc (sub.extension sub x) ~attrs:(sub.attributes sub attrs)
| Psig_attribute x -> attribute ~loc (sub.attribute sub x)
Expand Down Expand Up @@ -336,8 +288,7 @@ module M = struct
| Pstr_modtype x -> modtype ~loc (sub.module_type_declaration sub x)
| Pstr_open x -> open_ ~loc (sub.open_description sub x)
| Pstr_class () -> {pstr_loc = loc; pstr_desc = Pstr_class ()}
| Pstr_class_type l ->
class_type ~loc (List.map (sub.class_type_declaration sub) l)
| Pstr_class_type () -> {pstr_loc = loc; pstr_desc = Pstr_class_type ()}
| Pstr_include x -> include_ ~loc (sub.include_declaration sub x)
| Pstr_extension (x, attrs) ->
extension ~loc (sub.extension sub x) ~attrs:(sub.attributes sub attrs)
Expand Down Expand Up @@ -422,7 +373,7 @@ module E = struct
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
| Pexp_poly (e, t) ->
poly ~loc ~attrs (sub.expr sub e) (map_opt (sub.typ sub) t)
| Pexp_object cls -> object_ ~loc ~attrs (sub.class_structure sub cls)
| Pexp_object () -> assert false
| Pexp_newtype (s, e) ->
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
| Pexp_pack me -> pack ~loc ~attrs (sub.module_expr sub me)
Expand Down Expand Up @@ -465,73 +416,6 @@ module P = struct
| Ppat_extension x -> extension ~loc ~attrs (sub.extension sub x)
end

module CE = struct
(* Value expressions for the class language *)

let map sub {pcl_loc = loc; pcl_desc = desc; pcl_attributes = attrs} =
let open Cl in
let loc = sub.location sub loc in
let attrs = sub.attributes sub attrs in
match desc with
| Pcl_constr (lid, tys) ->
constr ~loc ~attrs (map_loc sub lid) (List.map (sub.typ sub) tys)
| Pcl_structure s -> structure ~loc ~attrs (sub.class_structure sub s)
| Pcl_fun (lab, e, p, ce) ->
fun_ ~loc ~attrs lab
(map_opt (sub.expr sub) e)
(sub.pat sub p) (sub.class_expr sub ce)
| Pcl_apply (ce, l) ->
apply ~loc ~attrs (sub.class_expr sub ce)
(List.map (map_snd (sub.expr sub)) l)
| Pcl_let (r, vbs, ce) ->
(* #if false then
let_ ~loc ~attrs r (List.map (sub.value_binding sub) vbs)
(sub.class_expr sub ce)
#else *)
let_ ~loc ~attrs r
((if r = Recursive then sub.value_bindings_rec else sub.value_bindings)
sub vbs)
(sub.class_expr sub ce)
(* #end *)
| Pcl_constraint (ce, ct) ->
constraint_ ~loc ~attrs (sub.class_expr sub ce) (sub.class_type sub ct)
| Pcl_extension x -> extension ~loc ~attrs (sub.extension sub x)
| Pcl_open (ovf, lid, ce) ->
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.class_expr sub ce)

let map_kind sub = function
| Cfk_concrete (o, e) -> Cfk_concrete (o, sub.expr sub e)
| Cfk_virtual t -> Cfk_virtual (sub.typ sub t)

let map_field sub {pcf_desc = desc; pcf_loc = loc; pcf_attributes = attrs} =
let open Cf in
let loc = sub.location sub loc in
let attrs = sub.attributes sub attrs in
match desc with
| Pcf_inherit () -> {pcf_loc = loc; pcf_attributes = attrs; pcf_desc = desc}
| Pcf_val (s, m, k) -> val_ ~loc ~attrs (map_loc sub s) m (map_kind sub k)
| Pcf_method (s, p, k) ->
method_ ~loc ~attrs (map_loc sub s) p (map_kind sub k)
| Pcf_constraint (t1, t2) ->
constraint_ ~loc ~attrs (sub.typ sub t1) (sub.typ sub t2)
| Pcf_initializer e -> initializer_ ~loc ~attrs (sub.expr sub e)
| Pcf_attribute x -> attribute ~loc (sub.attribute sub x)
| Pcf_extension x -> extension ~loc ~attrs (sub.extension sub x)

let map_structure sub {pcstr_self; pcstr_fields} =
{
pcstr_self = sub.pat sub pcstr_self;
pcstr_fields = List.map (sub.class_field sub) pcstr_fields;
}

let class_infos sub f
{pci_virt; pci_params = pl; pci_name; pci_expr; pci_loc; pci_attributes} =
Ci.mk ~virt:pci_virt
~params:(List.map (map_fst (sub.typ sub)) pl)
(map_loc sub pci_name) (f pci_expr) ~loc:(sub.location sub pci_loc)
~attrs:(sub.attributes sub pci_attributes)
end

(* Now, a generic AST mapper, to be extended to cover all kinds and
cases of the OCaml grammar. The default behavior of the mapper is
the identity. *)
Expand All @@ -545,14 +429,6 @@ let default_mapper =
signature_item = MT.map_signature_item;
module_type = MT.map;
with_constraint = MT.map_with_constraint;
class_expr = CE.map;
class_field = CE.map_field;
class_structure = CE.map_structure;
class_type = CT.map;
class_type_field = CT.map_field;
class_signature = CT.map_signature;
class_type_declaration =
(fun this -> CE.class_infos this (this.class_type this));
type_declaration = T.map_type_declaration;
(* #if true then *)
type_declaration_list = T.map_type_declaration_list;
Expand Down
8 changes: 0 additions & 8 deletions jscomp/frontend/bs_ast_mapper.mli
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,6 @@ type mapper = {
attributes: mapper -> attribute list -> attribute list;
case: mapper -> case -> case;
cases: mapper -> case list -> case list;
class_expr: mapper -> class_expr -> class_expr;
class_field: mapper -> class_field -> class_field;
class_signature: mapper -> class_signature -> class_signature;
class_structure: mapper -> class_structure -> class_structure;
class_type: mapper -> class_type -> class_type;
class_type_declaration:
mapper -> class_type_declaration -> class_type_declaration;
class_type_field: mapper -> class_type_field -> class_type_field;
constructor_declaration:
mapper -> constructor_declaration -> constructor_declaration;
expr: mapper -> expression -> expression;
Expand Down
127 changes: 1 addition & 126 deletions jscomp/ml/ast_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ module Typ = struct
let tuple ?loc ?attrs a = mk ?loc ?attrs (Ptyp_tuple a)
let constr ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_constr (a, b))
let object_ ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_object (a, b))
let class_ ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_class (a, b))
let alias ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_alias (a, b))
let variant ?loc ?attrs a b c = mk ?loc ?attrs (Ptyp_variant (a, b, c))
let poly ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_poly (a, b))
Expand Down Expand Up @@ -88,8 +87,7 @@ module Typ = struct
Ptyp_constr(longident, List.map loop lst)
| Ptyp_object (lst, o) ->
Ptyp_object (List.map loop_object_field lst, o)
| Ptyp_class (longident, lst) ->
Ptyp_class (longident, List.map loop lst)
| Ptyp_class () -> assert false
| Ptyp_alias(core_type, string) ->
check_variable var_names t.ptyp_loc string;
Ptyp_alias(loop core_type, string)
Expand Down Expand Up @@ -183,7 +181,6 @@ module Exp = struct
let assert_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_assert a)
let lazy_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_lazy a)
let poly ?loc ?attrs a b = mk ?loc ?attrs (Pexp_poly (a, b))
let object_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_object a)
let newtype ?loc ?attrs a b = mk ?loc ?attrs (Pexp_newtype (a, b))
let pack ?loc ?attrs a = mk ?loc ?attrs (Pexp_pack a)
let open_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_open (a, b, c))
Expand Down Expand Up @@ -240,7 +237,6 @@ module Sig = struct
let open_ ?loc a = mk ?loc (Psig_open a)
let include_ ?loc a = mk ?loc (Psig_include a)

let class_type ?loc a = mk ?loc (Psig_class_type a)
let extension ?loc ?(attrs = []) a = mk ?loc (Psig_extension (a, attrs))
let attribute ?loc a = mk ?loc (Psig_attribute a)
let text txt =
Expand All @@ -263,7 +259,6 @@ module Str = struct
let rec_module ?loc a = mk ?loc (Pstr_recmodule a)
let modtype ?loc a = mk ?loc (Pstr_modtype a)
let open_ ?loc a = mk ?loc (Pstr_open a)
let class_type ?loc a = mk ?loc (Pstr_class_type a)
let include_ ?loc a = mk ?loc (Pstr_include a)
let extension ?loc ?(attrs = []) a = mk ?loc (Pstr_extension (a, attrs))
let attribute ?loc a = mk ?loc (Pstr_attribute a)
Expand All @@ -274,95 +269,6 @@ module Str = struct
f_txt
end

module Cl = struct
let mk ?(loc = !default_loc) ?(attrs = []) d =
{
pcl_desc = d;
pcl_loc = loc;
pcl_attributes = attrs;
}
let attr d a = {d with pcl_attributes = d.pcl_attributes @ [a]}

let constr ?loc ?attrs a b = mk ?loc ?attrs (Pcl_constr (a, b))
let structure ?loc ?attrs a = mk ?loc ?attrs (Pcl_structure a)
let fun_ ?loc ?attrs a b c d = mk ?loc ?attrs (Pcl_fun (a, b, c, d))
let apply ?loc ?attrs a b = mk ?loc ?attrs (Pcl_apply (a, b))
let let_ ?loc ?attrs a b c = mk ?loc ?attrs (Pcl_let (a, b, c))
let constraint_ ?loc ?attrs a b = mk ?loc ?attrs (Pcl_constraint (a, b))
let extension ?loc ?attrs a = mk ?loc ?attrs (Pcl_extension a)
let open_ ?loc ?attrs a b c = mk ?loc ?attrs (Pcl_open (a, b, c))
end

module Cty = struct
let mk ?(loc = !default_loc) ?(attrs = []) d =
{
pcty_desc = d;
pcty_loc = loc;
pcty_attributes = attrs;
}
let attr d a = {d with pcty_attributes = d.pcty_attributes @ [a]}

let constr ?loc ?attrs a b = mk ?loc ?attrs (Pcty_constr (a, b))
let signature ?loc ?attrs a = mk ?loc ?attrs (Pcty_signature a)
let arrow ?loc ?attrs a b c = mk ?loc ?attrs (Pcty_arrow (a, b, c))
let extension ?loc ?attrs a = mk ?loc ?attrs (Pcty_extension a)
let open_ ?loc ?attrs a b c = mk ?loc ?attrs (Pcty_open (a, b, c))
end

module Ctf = struct
let mk ?(loc = !default_loc) ?(attrs = [])
?(docs = empty_docs) d =
{
pctf_desc = d;
pctf_loc = loc;
pctf_attributes = add_docs_attrs docs attrs;
}

let inherit_ ?loc ?attrs a = mk ?loc ?attrs (Pctf_inherit a)
let val_ ?loc ?attrs a b c d = mk ?loc ?attrs (Pctf_val (a, b, c, d))
let method_ ?loc ?attrs a b c d = mk ?loc ?attrs (Pctf_method (a, b, c, d))
let constraint_ ?loc ?attrs a b = mk ?loc ?attrs (Pctf_constraint (a, b))
let extension ?loc ?attrs a = mk ?loc ?attrs (Pctf_extension a)
let attribute ?loc a = mk ?loc (Pctf_attribute a)
let text txt =
let f_txt = Ext_list.filter txt (fun ds -> docstring_body ds <> "")in
List.map
(fun ds -> attribute ~loc:(docstring_loc ds) (text_attr ds))
f_txt

let attr d a = {d with pctf_attributes = d.pctf_attributes @ [a]}

end

module Cf = struct
let mk ?(loc = !default_loc) ?(attrs = [])
?(docs = empty_docs) d =
{
pcf_desc = d;
pcf_loc = loc;
pcf_attributes = add_docs_attrs docs attrs;
}


let val_ ?loc ?attrs a b c = mk ?loc ?attrs (Pcf_val (a, b, c))
let method_ ?loc ?attrs a b c = mk ?loc ?attrs (Pcf_method (a, b, c))
let constraint_ ?loc ?attrs a b = mk ?loc ?attrs (Pcf_constraint (a, b))
let initializer_ ?loc ?attrs a = mk ?loc ?attrs (Pcf_initializer a)
let extension ?loc ?attrs a = mk ?loc ?attrs (Pcf_extension a)
let attribute ?loc a = mk ?loc (Pcf_attribute a)
let text txt =
let f_txt = Ext_list.filter txt (fun ds -> docstring_body ds <> "")in
List.map
(fun ds -> attribute ~loc:(docstring_loc ds) (text_attr ds))
f_txt

let virtual_ ct = Cfk_virtual ct
let concrete o e = Cfk_concrete (o, e)

let attr d a = {d with pcf_attributes = d.pcf_attributes @ [a]}

end

module Val = struct
let mk ?(loc = !default_loc) ?(attrs = []) ?(docs = empty_docs)
?(prim = []) name typ =
Expand Down Expand Up @@ -444,21 +350,6 @@ module Vb = struct
}
end

module Ci = struct
let mk ?(loc = !default_loc) ?(attrs = [])
?(docs = empty_docs) ?(text = [])
?(virt = Concrete) ?(params = []) name expr =
{
pci_virt = virt;
pci_params = params;
pci_name = name;
pci_expr = expr;
pci_attributes =
add_text_attrs text (add_docs_attrs docs attrs);
pci_loc = loc;
}
end

module Type = struct
let mk ?(loc = !default_loc) ?(attrs = [])
?(docs = empty_docs) ?(text = [])
Expand Down Expand Up @@ -542,19 +433,3 @@ module Te = struct
}

end

module Csig = struct
let mk self fields =
{
pcsig_self = self;
pcsig_fields = fields;
}
end

module Cstr = struct
let mk self fields =
{
pcstr_self = self;
pcstr_fields = fields;
}
end
Loading