Skip to content

Commit 1912f93

Browse files
authored
Remove dead Sig_class and Sig_class_type signature variants (#8470)
Types.signature_item carried Sig_class and Sig_class_type (OCaml class / class-type items, each `of unit` dummy AST nodes). ReScript has no classes, so the parser and type checker never construct them; every match arm was assert false / identity / skip. Remove both variants and all their handling across the type system (btype, subst, env, mtype, includemod, printtyp, translmod, transl_recmodule), gentype, and analysis. Also drop the stale commented-out get_string block in lam_print.ml referencing the old 3-arg Sig_class form, and simplify the now-trivial filter_rem_sig. The frozen parsetree0 Pstr_class/Psig_class dummies are independent and left untouched.
1 parent f882bba commit 1912f93

15 files changed

Lines changed: 13 additions & 96 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
- Remove the unreachable `Longident.Lapply` constructor (OCaml's applicative-functor path syntax `F(X).t`, which ReScript's grammar cannot produce). https://github.com/rescript-lang/rescript/pull/8469
7575
- Refactor analysis for server side use. https://github.com/rescript-lang/rescript/pull/8478
7676
- Remove unused files. https://github.com/rescript-lang/rescript/pull/8481
77+
- Remove the dead `Sig_class`/`Sig_class_type` signature variants (OCaml class items, which ReScript cannot produce). https://github.com/rescript-lang/rescript/pull/8470
7778

7879
# 13.0.0-alpha.4
7980

analysis/src/create_interface.ml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,6 @@ let print_signature ~extractor ~signature =
263263
in
264264
Buffer.add_string buf (indent ^ new_item_str ^ "\n");
265265
process_signature ~indent items
266-
| Sig_class _ :: items ->
267-
(* not needed *)
268-
process_signature ~indent items
269-
| Sig_class_type _ :: items ->
270-
(* not needed *)
271-
process_signature ~indent items
272266
| [] -> ()
273267
and process_module_type ~indent (mt : Types.module_type) =
274268
match mt with

compiler/core/lam_print.ml

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -256,33 +256,6 @@ let flatten (lam : Lam.t) : (print_kind * Ident.t * Lam.t) list * Lam.t =
256256
aux (Ext_list.map bind_args (fun (id, l) -> (Recursive, id, l))) body
257257
| _ -> assert false
258258

259-
(* let get_string ((id : Ident.t), (pos : int)) (env : Env.t) : string =
260-
match Env.find_module (Pident id) env with
261-
| {md_type = Mty_signature signature ; _ } ->
262-
(* Env.prefix_idents, could be cached *)
263-
let serializable_sigs =
264-
Ext_list.filter (fun x ->
265-
match x with
266-
| Sig_typext _
267-
| Sig_module _
268-
| Sig_class _ -> true
269-
| Sig_value(_, {val_kind = Val_prim _}) -> false
270-
| Sig_value _ -> true
271-
| _ -> false
272-
) signature in
273-
(begin match Ext_list.nth_opt serializable_sigs pos with
274-
| Some (Sig_value (i,_)
275-
| Sig_module (i,_,_)
276-
| Sig_typext (i,_,_)
277-
| Sig_modtype(i,_)
278-
| Sig_class (i,_,_)
279-
| Sig_class_type(i,_,_)
280-
| Sig_type(i,_,_)) -> i
281-
| None -> assert false
282-
end).name
283-
| _ -> assert false
284-
*)
285-
286259
let lambda ppf v =
287260
let rec lam ppf (l : Lam.t) =
288261
match l with

compiler/gentype/translate_signature_from_types.ml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ and translate_signature_item_from_types ~config ~output_file_relative ~resolver
9393
| Types.Sig_modtype _ ->
9494
log_not_implemented ("Sig_modtype " ^ __LOC__);
9595
Translation.empty
96-
| Types.Sig_class _ ->
97-
log_not_implemented ("Sig_class " ^ __LOC__);
98-
Translation.empty
99-
| Types.Sig_class_type _ ->
100-
log_not_implemented ("Sig_class_type " ^ __LOC__);
101-
Translation.empty
10296

10397
(** Like translateSignature but from Types not Typedtree *)
10498
and translate_signature_from_types ~config ~output_file_relative ~resolver

compiler/gentype/translate_type_expr_from_types.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,7 @@ and signature_to_module_runtime_representation ~config ~type_vars_gen ~type_env
750750
}
751751
in
752752
(dependencies, [field])
753-
| Types.Sig_type _ | Types.Sig_typext _ | Types.Sig_modtype _
754-
| Types.Sig_class _ | Types.Sig_class_type _ ->
753+
| Types.Sig_type _ | Types.Sig_typext _ | Types.Sig_modtype _ ->
755754
([], []))
756755
in
757756
let dependencies, fields =

compiler/ml/btype.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,6 @@ let type_iterators =
335335
| Sig_typext (_, td, _) -> it.it_extension_constructor it td
336336
| Sig_module (_, md, _) -> it.it_module_declaration it md
337337
| Sig_modtype (_, mtd) -> it.it_modtype_declaration it mtd
338-
| Sig_class () -> assert false
339-
| Sig_class_type () -> assert false
340338
and it_value_description it vd = it.it_type_expr it vd.val_type
341339
and it_type_declaration it td =
342340
List.iter (it.it_type_expr it) td.type_params;

compiler/ml/env.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,8 +1454,6 @@ let rec prefix_idents root pos sub = function
14541454
prefix_idents root pos (Subst.add_modtype id (Mty_ident p) sub) rem
14551455
in
14561456
(p :: pl, final_sub)
1457-
| Sig_class _ :: _ -> assert false
1458-
| Sig_class_type _ :: _ -> assert false
14591457

14601458
let prefix_idents root sub sg =
14611459
if sub = Subst.identity then (
@@ -1551,9 +1549,7 @@ and components_of_module_maker (env, sub, path, mty) =
15511549
let decl' = Subst.modtype_declaration sub decl in
15521550
c.comp_modtypes <-
15531551
Tbl.add (Ident.name id) (decl', nopos) c.comp_modtypes;
1554-
env := store_modtype id decl !env
1555-
| Sig_class () -> assert false
1556-
| Sig_class_type () -> assert false)
1552+
env := store_modtype id decl !env)
15571553
sg pl;
15581554
Some (Structure_comps c)
15591555
| Mty_functor (param, _ty_arg, ty_res) ->
@@ -1796,8 +1792,6 @@ let add_item comp env =
17961792
| Sig_typext (id, ext, _) -> add_extension ~check:false id ext env
17971793
| Sig_module (id, md, _) -> add_module_declaration ~check:false id md env
17981794
| Sig_modtype (id, decl) -> add_modtype id decl env
1799-
| Sig_class () -> env
1800-
| Sig_class_type () -> env
18011795

18021796
let rec add_signature sg env =
18031797
match sg with

compiler/ml/includemod.ml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,13 @@ let item_ident_name = function
126126
| Sig_typext (id, d, _) -> (id, d.ext_loc, Field_typext (Ident.name id))
127127
| Sig_module (id, d, _) -> (id, d.md_loc, Field_module (Ident.name id))
128128
| Sig_modtype (id, d) -> (id, d.mtd_loc, Field_modtype (Ident.name id))
129-
| Sig_class () -> assert false
130-
| Sig_class_type () -> assert false
131129

132130
let is_runtime_component = function
133131
| Sig_value (_, {val_kind = Val_prim _})
134132
| Sig_type (_, _, _)
135-
| Sig_modtype (_, _)
136-
| Sig_class_type () ->
133+
| Sig_modtype (_, _) ->
137134
false
138-
| Sig_value (_, _)
139-
| Sig_typext (_, _, _)
140-
| Sig_module (_, _, _)
141-
| Sig_class () ->
142-
true
135+
| Sig_value (_, _) | Sig_typext (_, _, _) | Sig_module (_, _, _) -> true
143136

144137
(* Print a coercion *)
145138

@@ -301,7 +294,6 @@ and signatures ~loc env cxt subst sig1 sig2 =
301294
| Sig_modtype (i, _)
302295
| Sig_type (i, _, _) ->
303296
Ident.name i
304-
| Sig_class () | Sig_class_type () -> assert false
305297
in
306298
List.fold_right
307299
(fun item fields ->
@@ -360,8 +352,7 @@ and signatures ~loc env cxt subst sig1 sig2 =
360352
| Sig_module _ -> Subst.add_module id2 (Pident id1) subst
361353
| Sig_modtype _ ->
362354
Subst.add_modtype id2 (Mty_ident (Pident id1)) subst
363-
| Sig_value _ | Sig_typext _ | Sig_class _ | Sig_class_type () ->
364-
subst
355+
| Sig_value _ | Sig_typext _ -> subst
365356
in
366357
pair_components new_subst ((item1, item2, pos1) :: paired) unpaired rem
367358
| exception Not_found ->
@@ -399,8 +390,6 @@ and signature_components ~loc old_env env cxt subst paired =
399390
| (Sig_modtype (id1, info1), Sig_modtype (_id2, info2), _pos) :: rem ->
400391
modtype_infos ~loc env cxt subst id1 info1 info2;
401392
comps_rec rem
402-
| (Sig_class (), Sig_class (), _) :: _ -> assert false
403-
| (Sig_class_type (), Sig_class_type (), _pos) :: _ -> assert false
404393
| _ -> assert false
405394

406395
and module_declarations ~loc env cxt subst id1 md1 md2 =

compiler/ml/mtype.ml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ and strengthen_sig ~aliasable env sg p pos =
8989
in
9090
Sig_modtype (id, newdecl)
9191
:: strengthen_sig ~aliasable (Env.add_modtype id decl env) rem p pos
92-
(* Need to add the module type in case it is manifest *)
93-
| (Sig_class _ as sigelt) :: rem ->
94-
sigelt :: strengthen_sig ~aliasable env rem p (pos + 1)
95-
| (Sig_class_type _ as sigelt) :: rem ->
96-
sigelt :: strengthen_sig ~aliasable env rem p pos
92+
(* Need to add the module type in case it is manifest *)
9793

9894
and strengthen_decl ~aliasable env md p =
9995
match md.md_type with
@@ -160,9 +156,7 @@ let nondep_supertype env mid mty =
160156
{mtd_type = None; mtd_loc = Location.none; mtd_attributes = []}
161157
)
162158
:: rem'
163-
| _ -> raise Not_found))
164-
| Sig_class () -> assert false
165-
| Sig_class_type () -> assert false)
159+
| _ -> raise Not_found)))
166160
and nondep_modtype_decl env mtd =
167161
{mtd with mtd_type = Misc.may_map (nondep_mty env Strict) mtd.mtd_type}
168162
in
@@ -229,8 +223,7 @@ and type_paths_sig env p pos sg =
229223
p (pos + 1) rem
230224
| Sig_modtype (id, decl) :: rem ->
231225
type_paths_sig (Env.add_modtype id decl env) p pos rem
232-
| (Sig_typext _ | Sig_class _) :: rem -> type_paths_sig env p (pos + 1) rem
233-
| Sig_class_type _ :: rem -> type_paths_sig env p pos rem
226+
| Sig_typext _ :: rem -> type_paths_sig env p (pos + 1) rem
234227

235228
let rec no_code_needed env mty =
236229
match scrape env mty with
@@ -252,9 +245,8 @@ and no_code_needed_sig env sg =
252245
&& no_code_needed_sig
253246
(Env.add_module_declaration ~check:false id md env)
254247
rem
255-
| (Sig_type _ | Sig_modtype _ | Sig_class_type _) :: rem ->
256-
no_code_needed_sig env rem
257-
| (Sig_typext _ | Sig_class _) :: _ -> false
248+
| (Sig_type _ | Sig_modtype _) :: rem -> no_code_needed_sig env rem
249+
| Sig_typext _ :: _ -> false
258250

259251
(* Check whether a module type may return types *)
260252

@@ -286,8 +278,7 @@ and contains_type_item env = function
286278
is kept local to expressions. *)
287279
raise Exit
288280
| Sig_module (_, {md_type = mty}, _) -> contains_type env mty
289-
| Sig_value _ | Sig_type _ | Sig_typext _ | Sig_class _ | Sig_class_type _ ->
290-
()
281+
| Sig_value _ | Sig_type _ | Sig_typext _ -> ()
291282

292283
let contains_type env mty =
293284
try

compiler/ml/printtyp.ml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,7 @@ let wrap_env fenv ftree arg =
10711071
set_printing_env env;
10721072
tree
10731073

1074-
let filter_rem_sig item rem =
1075-
match (item, rem) with
1076-
| Sig_class_type _, tydecl1 :: tydecl2 :: rem -> ([tydecl1; tydecl2], rem)
1077-
| _ -> ([], rem)
1074+
let filter_rem_sig _item rem = ([], rem)
10781075

10791076
let dummy =
10801077
{
@@ -1161,8 +1158,6 @@ and trees_of_sigitem = function
11611158
in
11621159
[tree_of_module id md.md_type rs ~ellipsis]
11631160
| Sig_modtype (id, decl) -> [tree_of_modtype_declaration id decl]
1164-
| Sig_class () -> []
1165-
| Sig_class_type () -> []
11661161

11671162
and tree_of_modtype_declaration id decl =
11681163
let mty =

0 commit comments

Comments
 (0)