Skip to content

Commit 873facd

Browse files
authored
Merge branch 'master' into caml_format
2 parents e962091 + f1ad9bd commit 873facd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+397
-4361
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
- Convert OCaml codebase to snake case style. https://github.com/rescript-lang/rescript-compiler/pull/6702
4141
- Refactor uppercase exotic ident handling. https://github.com/rescript-lang/rescript-compiler/pull/6779
4242
- Fix `-nostdlib` internal compiler option. https://github.com/rescript-lang/rescript-compiler/pull/6824
43+
- 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
4344
- Convert `caml_format` and `js_math` to `.res`. https://github.com/rescript-lang/rescript-compiler/pull/6834
4445

4546
#### :nail_care: Polish

jscomp/frontend/bs_ast_mapper.ml

Lines changed: 4 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ type mapper = {
2929
attributes: mapper -> attribute list -> attribute list;
3030
case: mapper -> case -> case;
3131
cases: mapper -> case list -> case list;
32-
class_expr: mapper -> class_expr -> class_expr;
33-
class_field: mapper -> class_field -> class_field;
34-
class_signature: mapper -> class_signature -> class_signature;
35-
class_structure: mapper -> class_structure -> class_structure;
36-
class_type: mapper -> class_type -> class_type;
37-
class_type_declaration:
38-
mapper -> class_type_declaration -> class_type_declaration;
39-
class_type_field: mapper -> class_type_field -> class_type_field;
4032
constructor_declaration:
4133
mapper -> constructor_declaration -> constructor_declaration;
4234
expr: mapper -> expression -> expression;
@@ -115,8 +107,7 @@ module T = struct
115107
constr ~loc ~attrs (map_loc sub lid) (List.map (sub.typ sub) tl)
116108
| Ptyp_object (l, o) ->
117109
object_ ~loc ~attrs (List.map (object_field sub) l) o
118-
| Ptyp_class (lid, tl) ->
119-
class_ ~loc ~attrs (map_loc sub lid) (List.map (sub.typ sub) tl)
110+
| Ptyp_class () -> assert false
120111
| Ptyp_alias (t, s) -> alias ~loc ~attrs (sub.typ sub t) s
121112
| Ptyp_variant (rl, b, ll) ->
122113
variant ~loc ~attrs (List.map (row_field sub) rl) b ll
@@ -192,44 +183,6 @@ module T = struct
192183
~attrs:(sub.attributes sub pext_attributes)
193184
end
194185

195-
module CT = struct
196-
(* Type expressions for the class language *)
197-
198-
let map sub {pcty_loc = loc; pcty_desc = desc; pcty_attributes = attrs} =
199-
let open Cty in
200-
let loc = sub.location sub loc in
201-
let attrs = sub.attributes sub attrs in
202-
match desc with
203-
| Pcty_constr (lid, tys) ->
204-
constr ~loc ~attrs (map_loc sub lid) (List.map (sub.typ sub) tys)
205-
| Pcty_signature x -> signature ~loc ~attrs (sub.class_signature sub x)
206-
| Pcty_arrow (lab, t, ct) ->
207-
arrow ~loc ~attrs lab (sub.typ sub t) (sub.class_type sub ct)
208-
| Pcty_extension x -> extension ~loc ~attrs (sub.extension sub x)
209-
| Pcty_open (ovf, lid, ct) ->
210-
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.class_type sub ct)
211-
212-
let map_field sub {pctf_desc = desc; pctf_loc = loc; pctf_attributes = attrs}
213-
=
214-
let open Ctf in
215-
let loc = sub.location sub loc in
216-
let attrs = sub.attributes sub attrs in
217-
match desc with
218-
| Pctf_inherit ct -> inherit_ ~loc ~attrs (sub.class_type sub ct)
219-
| Pctf_val (s, m, v, t) ->
220-
val_ ~loc ~attrs (map_loc sub s) m v (sub.typ sub t)
221-
| Pctf_method (s, p, v, t) ->
222-
method_ ~loc ~attrs (map_loc sub s) p v (sub.typ sub t)
223-
| Pctf_constraint (t1, t2) ->
224-
constraint_ ~loc ~attrs (sub.typ sub t1) (sub.typ sub t2)
225-
| Pctf_attribute x -> attribute ~loc (sub.attribute sub x)
226-
| Pctf_extension x -> extension ~loc ~attrs (sub.extension sub x)
227-
228-
let map_signature sub {pcsig_self; pcsig_fields} =
229-
Csig.mk (sub.typ sub pcsig_self)
230-
(List.map (sub.class_type_field sub) pcsig_fields)
231-
end
232-
233186
module MT = struct
234187
(* Type expressions for the module language *)
235188

@@ -280,8 +233,7 @@ module MT = struct
280233
| Psig_open x -> open_ ~loc (sub.open_description sub x)
281234
| Psig_include x -> include_ ~loc (sub.include_description sub x)
282235
| Psig_class () -> assert false
283-
| Psig_class_type l ->
284-
class_type ~loc (List.map (sub.class_type_declaration sub) l)
236+
| Psig_class_type () -> assert false
285237
| Psig_extension (x, attrs) ->
286238
extension ~loc (sub.extension sub x) ~attrs:(sub.attributes sub attrs)
287239
| Psig_attribute x -> attribute ~loc (sub.attribute sub x)
@@ -336,8 +288,7 @@ module M = struct
336288
| Pstr_modtype x -> modtype ~loc (sub.module_type_declaration sub x)
337289
| Pstr_open x -> open_ ~loc (sub.open_description sub x)
338290
| Pstr_class () -> {pstr_loc = loc; pstr_desc = Pstr_class ()}
339-
| Pstr_class_type l ->
340-
class_type ~loc (List.map (sub.class_type_declaration sub) l)
291+
| Pstr_class_type () -> {pstr_loc = loc; pstr_desc = Pstr_class_type ()}
341292
| Pstr_include x -> include_ ~loc (sub.include_declaration sub x)
342293
| Pstr_extension (x, attrs) ->
343294
extension ~loc (sub.extension sub x) ~attrs:(sub.attributes sub attrs)
@@ -422,7 +373,7 @@ module E = struct
422373
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
423374
| Pexp_poly (e, t) ->
424375
poly ~loc ~attrs (sub.expr sub e) (map_opt (sub.typ sub) t)
425-
| Pexp_object cls -> object_ ~loc ~attrs (sub.class_structure sub cls)
376+
| Pexp_object () -> assert false
426377
| Pexp_newtype (s, e) ->
427378
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
428379
| Pexp_pack me -> pack ~loc ~attrs (sub.module_expr sub me)
@@ -465,73 +416,6 @@ module P = struct
465416
| Ppat_extension x -> extension ~loc ~attrs (sub.extension sub x)
466417
end
467418

468-
module CE = struct
469-
(* Value expressions for the class language *)
470-
471-
let map sub {pcl_loc = loc; pcl_desc = desc; pcl_attributes = attrs} =
472-
let open Cl in
473-
let loc = sub.location sub loc in
474-
let attrs = sub.attributes sub attrs in
475-
match desc with
476-
| Pcl_constr (lid, tys) ->
477-
constr ~loc ~attrs (map_loc sub lid) (List.map (sub.typ sub) tys)
478-
| Pcl_structure s -> structure ~loc ~attrs (sub.class_structure sub s)
479-
| Pcl_fun (lab, e, p, ce) ->
480-
fun_ ~loc ~attrs lab
481-
(map_opt (sub.expr sub) e)
482-
(sub.pat sub p) (sub.class_expr sub ce)
483-
| Pcl_apply (ce, l) ->
484-
apply ~loc ~attrs (sub.class_expr sub ce)
485-
(List.map (map_snd (sub.expr sub)) l)
486-
| Pcl_let (r, vbs, ce) ->
487-
(* #if false then
488-
let_ ~loc ~attrs r (List.map (sub.value_binding sub) vbs)
489-
(sub.class_expr sub ce)
490-
#else *)
491-
let_ ~loc ~attrs r
492-
((if r = Recursive then sub.value_bindings_rec else sub.value_bindings)
493-
sub vbs)
494-
(sub.class_expr sub ce)
495-
(* #end *)
496-
| Pcl_constraint (ce, ct) ->
497-
constraint_ ~loc ~attrs (sub.class_expr sub ce) (sub.class_type sub ct)
498-
| Pcl_extension x -> extension ~loc ~attrs (sub.extension sub x)
499-
| Pcl_open (ovf, lid, ce) ->
500-
open_ ~loc ~attrs ovf (map_loc sub lid) (sub.class_expr sub ce)
501-
502-
let map_kind sub = function
503-
| Cfk_concrete (o, e) -> Cfk_concrete (o, sub.expr sub e)
504-
| Cfk_virtual t -> Cfk_virtual (sub.typ sub t)
505-
506-
let map_field sub {pcf_desc = desc; pcf_loc = loc; pcf_attributes = attrs} =
507-
let open Cf in
508-
let loc = sub.location sub loc in
509-
let attrs = sub.attributes sub attrs in
510-
match desc with
511-
| Pcf_inherit () -> {pcf_loc = loc; pcf_attributes = attrs; pcf_desc = desc}
512-
| Pcf_val (s, m, k) -> val_ ~loc ~attrs (map_loc sub s) m (map_kind sub k)
513-
| Pcf_method (s, p, k) ->
514-
method_ ~loc ~attrs (map_loc sub s) p (map_kind sub k)
515-
| Pcf_constraint (t1, t2) ->
516-
constraint_ ~loc ~attrs (sub.typ sub t1) (sub.typ sub t2)
517-
| Pcf_initializer e -> initializer_ ~loc ~attrs (sub.expr sub e)
518-
| Pcf_attribute x -> attribute ~loc (sub.attribute sub x)
519-
| Pcf_extension x -> extension ~loc ~attrs (sub.extension sub x)
520-
521-
let map_structure sub {pcstr_self; pcstr_fields} =
522-
{
523-
pcstr_self = sub.pat sub pcstr_self;
524-
pcstr_fields = List.map (sub.class_field sub) pcstr_fields;
525-
}
526-
527-
let class_infos sub f
528-
{pci_virt; pci_params = pl; pci_name; pci_expr; pci_loc; pci_attributes} =
529-
Ci.mk ~virt:pci_virt
530-
~params:(List.map (map_fst (sub.typ sub)) pl)
531-
(map_loc sub pci_name) (f pci_expr) ~loc:(sub.location sub pci_loc)
532-
~attrs:(sub.attributes sub pci_attributes)
533-
end
534-
535419
(* Now, a generic AST mapper, to be extended to cover all kinds and
536420
cases of the OCaml grammar. The default behavior of the mapper is
537421
the identity. *)
@@ -545,14 +429,6 @@ let default_mapper =
545429
signature_item = MT.map_signature_item;
546430
module_type = MT.map;
547431
with_constraint = MT.map_with_constraint;
548-
class_expr = CE.map;
549-
class_field = CE.map_field;
550-
class_structure = CE.map_structure;
551-
class_type = CT.map;
552-
class_type_field = CT.map_field;
553-
class_signature = CT.map_signature;
554-
class_type_declaration =
555-
(fun this -> CE.class_infos this (this.class_type this));
556432
type_declaration = T.map_type_declaration;
557433
(* #if true then *)
558434
type_declaration_list = T.map_type_declaration_list;

jscomp/frontend/bs_ast_mapper.mli

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,6 @@ type mapper = {
5757
attributes: mapper -> attribute list -> attribute list;
5858
case: mapper -> case -> case;
5959
cases: mapper -> case list -> case list;
60-
class_expr: mapper -> class_expr -> class_expr;
61-
class_field: mapper -> class_field -> class_field;
62-
class_signature: mapper -> class_signature -> class_signature;
63-
class_structure: mapper -> class_structure -> class_structure;
64-
class_type: mapper -> class_type -> class_type;
65-
class_type_declaration:
66-
mapper -> class_type_declaration -> class_type_declaration;
67-
class_type_field: mapper -> class_type_field -> class_type_field;
6860
constructor_declaration:
6961
mapper -> constructor_declaration -> constructor_declaration;
7062
expr: mapper -> expression -> expression;

jscomp/ml/ast_helper.ml

Lines changed: 1 addition & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ module Typ = struct
5454
let tuple ?loc ?attrs a = mk ?loc ?attrs (Ptyp_tuple a)
5555
let constr ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_constr (a, b))
5656
let object_ ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_object (a, b))
57-
let class_ ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_class (a, b))
5857
let alias ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_alias (a, b))
5958
let variant ?loc ?attrs a b c = mk ?loc ?attrs (Ptyp_variant (a, b, c))
6059
let poly ?loc ?attrs a b = mk ?loc ?attrs (Ptyp_poly (a, b))
@@ -88,8 +87,7 @@ module Typ = struct
8887
Ptyp_constr(longident, List.map loop lst)
8988
| Ptyp_object (lst, o) ->
9089
Ptyp_object (List.map loop_object_field lst, o)
91-
| Ptyp_class (longident, lst) ->
92-
Ptyp_class (longident, List.map loop lst)
90+
| Ptyp_class () -> assert false
9391
| Ptyp_alias(core_type, string) ->
9492
check_variable var_names t.ptyp_loc string;
9593
Ptyp_alias(loop core_type, string)
@@ -183,7 +181,6 @@ module Exp = struct
183181
let assert_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_assert a)
184182
let lazy_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_lazy a)
185183
let poly ?loc ?attrs a b = mk ?loc ?attrs (Pexp_poly (a, b))
186-
let object_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_object a)
187184
let newtype ?loc ?attrs a b = mk ?loc ?attrs (Pexp_newtype (a, b))
188185
let pack ?loc ?attrs a = mk ?loc ?attrs (Pexp_pack a)
189186
let open_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_open (a, b, c))
@@ -240,7 +237,6 @@ module Sig = struct
240237
let open_ ?loc a = mk ?loc (Psig_open a)
241238
let include_ ?loc a = mk ?loc (Psig_include a)
242239

243-
let class_type ?loc a = mk ?loc (Psig_class_type a)
244240
let extension ?loc ?(attrs = []) a = mk ?loc (Psig_extension (a, attrs))
245241
let attribute ?loc a = mk ?loc (Psig_attribute a)
246242
let text txt =
@@ -263,7 +259,6 @@ module Str = struct
263259
let rec_module ?loc a = mk ?loc (Pstr_recmodule a)
264260
let modtype ?loc a = mk ?loc (Pstr_modtype a)
265261
let open_ ?loc a = mk ?loc (Pstr_open a)
266-
let class_type ?loc a = mk ?loc (Pstr_class_type a)
267262
let include_ ?loc a = mk ?loc (Pstr_include a)
268263
let extension ?loc ?(attrs = []) a = mk ?loc (Pstr_extension (a, attrs))
269264
let attribute ?loc a = mk ?loc (Pstr_attribute a)
@@ -274,95 +269,6 @@ module Str = struct
274269
f_txt
275270
end
276271

277-
module Cl = struct
278-
let mk ?(loc = !default_loc) ?(attrs = []) d =
279-
{
280-
pcl_desc = d;
281-
pcl_loc = loc;
282-
pcl_attributes = attrs;
283-
}
284-
let attr d a = {d with pcl_attributes = d.pcl_attributes @ [a]}
285-
286-
let constr ?loc ?attrs a b = mk ?loc ?attrs (Pcl_constr (a, b))
287-
let structure ?loc ?attrs a = mk ?loc ?attrs (Pcl_structure a)
288-
let fun_ ?loc ?attrs a b c d = mk ?loc ?attrs (Pcl_fun (a, b, c, d))
289-
let apply ?loc ?attrs a b = mk ?loc ?attrs (Pcl_apply (a, b))
290-
let let_ ?loc ?attrs a b c = mk ?loc ?attrs (Pcl_let (a, b, c))
291-
let constraint_ ?loc ?attrs a b = mk ?loc ?attrs (Pcl_constraint (a, b))
292-
let extension ?loc ?attrs a = mk ?loc ?attrs (Pcl_extension a)
293-
let open_ ?loc ?attrs a b c = mk ?loc ?attrs (Pcl_open (a, b, c))
294-
end
295-
296-
module Cty = struct
297-
let mk ?(loc = !default_loc) ?(attrs = []) d =
298-
{
299-
pcty_desc = d;
300-
pcty_loc = loc;
301-
pcty_attributes = attrs;
302-
}
303-
let attr d a = {d with pcty_attributes = d.pcty_attributes @ [a]}
304-
305-
let constr ?loc ?attrs a b = mk ?loc ?attrs (Pcty_constr (a, b))
306-
let signature ?loc ?attrs a = mk ?loc ?attrs (Pcty_signature a)
307-
let arrow ?loc ?attrs a b c = mk ?loc ?attrs (Pcty_arrow (a, b, c))
308-
let extension ?loc ?attrs a = mk ?loc ?attrs (Pcty_extension a)
309-
let open_ ?loc ?attrs a b c = mk ?loc ?attrs (Pcty_open (a, b, c))
310-
end
311-
312-
module Ctf = struct
313-
let mk ?(loc = !default_loc) ?(attrs = [])
314-
?(docs = empty_docs) d =
315-
{
316-
pctf_desc = d;
317-
pctf_loc = loc;
318-
pctf_attributes = add_docs_attrs docs attrs;
319-
}
320-
321-
let inherit_ ?loc ?attrs a = mk ?loc ?attrs (Pctf_inherit a)
322-
let val_ ?loc ?attrs a b c d = mk ?loc ?attrs (Pctf_val (a, b, c, d))
323-
let method_ ?loc ?attrs a b c d = mk ?loc ?attrs (Pctf_method (a, b, c, d))
324-
let constraint_ ?loc ?attrs a b = mk ?loc ?attrs (Pctf_constraint (a, b))
325-
let extension ?loc ?attrs a = mk ?loc ?attrs (Pctf_extension a)
326-
let attribute ?loc a = mk ?loc (Pctf_attribute a)
327-
let text txt =
328-
let f_txt = Ext_list.filter txt (fun ds -> docstring_body ds <> "")in
329-
List.map
330-
(fun ds -> attribute ~loc:(docstring_loc ds) (text_attr ds))
331-
f_txt
332-
333-
let attr d a = {d with pctf_attributes = d.pctf_attributes @ [a]}
334-
335-
end
336-
337-
module Cf = struct
338-
let mk ?(loc = !default_loc) ?(attrs = [])
339-
?(docs = empty_docs) d =
340-
{
341-
pcf_desc = d;
342-
pcf_loc = loc;
343-
pcf_attributes = add_docs_attrs docs attrs;
344-
}
345-
346-
347-
let val_ ?loc ?attrs a b c = mk ?loc ?attrs (Pcf_val (a, b, c))
348-
let method_ ?loc ?attrs a b c = mk ?loc ?attrs (Pcf_method (a, b, c))
349-
let constraint_ ?loc ?attrs a b = mk ?loc ?attrs (Pcf_constraint (a, b))
350-
let initializer_ ?loc ?attrs a = mk ?loc ?attrs (Pcf_initializer a)
351-
let extension ?loc ?attrs a = mk ?loc ?attrs (Pcf_extension a)
352-
let attribute ?loc a = mk ?loc (Pcf_attribute a)
353-
let text txt =
354-
let f_txt = Ext_list.filter txt (fun ds -> docstring_body ds <> "")in
355-
List.map
356-
(fun ds -> attribute ~loc:(docstring_loc ds) (text_attr ds))
357-
f_txt
358-
359-
let virtual_ ct = Cfk_virtual ct
360-
let concrete o e = Cfk_concrete (o, e)
361-
362-
let attr d a = {d with pcf_attributes = d.pcf_attributes @ [a]}
363-
364-
end
365-
366272
module Val = struct
367273
let mk ?(loc = !default_loc) ?(attrs = []) ?(docs = empty_docs)
368274
?(prim = []) name typ =
@@ -444,21 +350,6 @@ module Vb = struct
444350
}
445351
end
446352

447-
module Ci = struct
448-
let mk ?(loc = !default_loc) ?(attrs = [])
449-
?(docs = empty_docs) ?(text = [])
450-
?(virt = Concrete) ?(params = []) name expr =
451-
{
452-
pci_virt = virt;
453-
pci_params = params;
454-
pci_name = name;
455-
pci_expr = expr;
456-
pci_attributes =
457-
add_text_attrs text (add_docs_attrs docs attrs);
458-
pci_loc = loc;
459-
}
460-
end
461-
462353
module Type = struct
463354
let mk ?(loc = !default_loc) ?(attrs = [])
464355
?(docs = empty_docs) ?(text = [])
@@ -542,19 +433,3 @@ module Te = struct
542433
}
543434

544435
end
545-
546-
module Csig = struct
547-
let mk self fields =
548-
{
549-
pcsig_self = self;
550-
pcsig_fields = fields;
551-
}
552-
end
553-
554-
module Cstr = struct
555-
let mk self fields =
556-
{
557-
pcstr_self = self;
558-
pcstr_fields = fields;
559-
}
560-
end

0 commit comments

Comments
 (0)