diff --git a/CHANGELOG.md b/CHANGELOG.md index 4de633be3f..7fda8cbfc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jscomp/frontend/bs_ast_mapper.ml b/jscomp/frontend/bs_ast_mapper.ml index 1c1ead24a8..1c22504682 100644 --- a/jscomp/frontend/bs_ast_mapper.ml +++ b/jscomp/frontend/bs_ast_mapper.ml @@ -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; @@ -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 @@ -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 *) @@ -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) @@ -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) @@ -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) @@ -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. *) @@ -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; diff --git a/jscomp/frontend/bs_ast_mapper.mli b/jscomp/frontend/bs_ast_mapper.mli index 869a20fb53..f1d54eec98 100644 --- a/jscomp/frontend/bs_ast_mapper.mli +++ b/jscomp/frontend/bs_ast_mapper.mli @@ -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; diff --git a/jscomp/ml/ast_helper.ml b/jscomp/ml/ast_helper.ml index 80fb40a1c7..4c372aa7af 100644 --- a/jscomp/ml/ast_helper.ml +++ b/jscomp/ml/ast_helper.ml @@ -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)) @@ -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) @@ -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)) @@ -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 = @@ -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) @@ -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 = @@ -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 = []) @@ -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 diff --git a/jscomp/ml/ast_helper.mli b/jscomp/ml/ast_helper.mli index 67f62492c3..355cbc55ab 100644 --- a/jscomp/ml/ast_helper.mli +++ b/jscomp/ml/ast_helper.mli @@ -62,7 +62,6 @@ module Typ : val constr: ?loc:loc -> ?attrs:attrs -> lid -> core_type list -> core_type val object_: ?loc:loc -> ?attrs:attrs -> object_field list -> closed_flag -> core_type - val class_: ?loc:loc -> ?attrs:attrs -> lid -> core_type list -> core_type val alias: ?loc:loc -> ?attrs:attrs -> core_type -> string -> core_type val variant: ?loc:loc -> ?attrs:attrs -> row_field list -> closed_flag -> label list option -> core_type @@ -165,7 +164,6 @@ module Exp: val lazy_: ?loc:loc -> ?attrs:attrs -> expression -> expression val poly: ?loc:loc -> ?attrs:attrs -> expression -> core_type option -> expression - val object_: ?loc:loc -> ?attrs:attrs -> class_structure -> expression val newtype: ?loc:loc -> ?attrs:attrs -> str -> expression -> expression val pack: ?loc:loc -> ?attrs:attrs -> module_expr -> expression val open_: ?loc:loc -> ?attrs:attrs -> override_flag -> lid -> expression @@ -267,7 +265,6 @@ module Sig: val modtype: ?loc:loc -> module_type_declaration -> signature_item val open_: ?loc:loc -> open_description -> signature_item val include_: ?loc:loc -> include_description -> signature_item - val class_type: ?loc:loc -> class_type_declaration list -> signature_item val extension: ?loc:loc -> ?attrs:attrs -> extension -> signature_item val attribute: ?loc:loc -> attribute -> signature_item val text: text -> signature_item list @@ -288,7 +285,6 @@ module Str: val rec_module: ?loc:loc -> module_binding list -> structure_item val modtype: ?loc:loc -> module_type_declaration -> structure_item val open_: ?loc:loc -> open_description -> structure_item - val class_type: ?loc:loc -> class_type_declaration list -> structure_item val include_: ?loc:loc -> include_declaration -> structure_item val extension: ?loc:loc -> ?attrs:attrs -> extension -> structure_item val attribute: ?loc:loc -> attribute -> structure_item @@ -335,104 +331,3 @@ module Vb: val mk: ?loc: loc -> ?attrs:attrs -> ?docs:docs -> ?text:text -> pattern -> expression -> value_binding end - - -(** {1 Class language} *) - -(** Class type expressions *) -module Cty: - sig - val mk: ?loc:loc -> ?attrs:attrs -> class_type_desc -> class_type - val attr: class_type -> attribute -> class_type - - val constr: ?loc:loc -> ?attrs:attrs -> lid -> core_type list -> class_type - val signature: ?loc:loc -> ?attrs:attrs -> class_signature -> class_type - val arrow: ?loc:loc -> ?attrs:attrs -> arg_label -> core_type -> - class_type -> class_type - val extension: ?loc:loc -> ?attrs:attrs -> extension -> class_type - val open_: ?loc:loc -> ?attrs:attrs -> override_flag -> lid -> class_type - -> class_type - end - -(** Class type fields *) -module Ctf: - sig - val mk: ?loc:loc -> ?attrs:attrs -> ?docs:docs -> - class_type_field_desc -> class_type_field - val attr: class_type_field -> attribute -> class_type_field - - val inherit_: ?loc:loc -> ?attrs:attrs -> class_type -> class_type_field - val val_: ?loc:loc -> ?attrs:attrs -> str -> mutable_flag -> - virtual_flag -> core_type -> class_type_field - val method_: ?loc:loc -> ?attrs:attrs -> str -> private_flag -> - virtual_flag -> core_type -> class_type_field - val constraint_: ?loc:loc -> ?attrs:attrs -> core_type -> core_type -> - class_type_field - val extension: ?loc:loc -> ?attrs:attrs -> extension -> class_type_field - val attribute: ?loc:loc -> attribute -> class_type_field - val text: text -> class_type_field list - end - -(** Class expressions *) -module Cl: - sig - val mk: ?loc:loc -> ?attrs:attrs -> class_expr_desc -> class_expr - val attr: class_expr -> attribute -> class_expr - - val constr: ?loc:loc -> ?attrs:attrs -> lid -> core_type list -> class_expr - val structure: ?loc:loc -> ?attrs:attrs -> class_structure -> class_expr - val fun_: ?loc:loc -> ?attrs:attrs -> arg_label -> expression option -> - pattern -> class_expr -> class_expr - val apply: ?loc:loc -> ?attrs:attrs -> class_expr -> - (arg_label * expression) list -> class_expr - val let_: ?loc:loc -> ?attrs:attrs -> rec_flag -> value_binding list -> - class_expr -> class_expr - val constraint_: ?loc:loc -> ?attrs:attrs -> class_expr -> class_type -> - class_expr - val extension: ?loc:loc -> ?attrs:attrs -> extension -> class_expr - val open_: ?loc:loc -> ?attrs:attrs -> override_flag -> lid -> class_expr - -> class_expr - end - -(** Class fields *) -module Cf: - sig - val mk: ?loc:loc -> ?attrs:attrs -> ?docs:docs -> class_field_desc -> - class_field - val attr: class_field -> attribute -> class_field - - val val_: ?loc:loc -> ?attrs:attrs -> str -> mutable_flag -> - class_field_kind -> class_field - val method_: ?loc:loc -> ?attrs:attrs -> str -> private_flag -> - class_field_kind -> class_field - val constraint_: ?loc:loc -> ?attrs:attrs -> core_type -> core_type -> - class_field - val initializer_: ?loc:loc -> ?attrs:attrs -> expression -> class_field - val extension: ?loc:loc -> ?attrs:attrs -> extension -> class_field - val attribute: ?loc:loc -> attribute -> class_field - val text: text -> class_field list - - val virtual_: core_type -> class_field_kind - val concrete: override_flag -> expression -> class_field_kind - - end - -(** Classes *) -module Ci: - sig - val mk: ?loc:loc -> ?attrs:attrs -> ?docs:docs -> ?text:text -> - ?virt:virtual_flag -> ?params:(core_type * variance) list -> - str -> 'a -> 'a class_infos - end - -(** Class signatures *) -module Csig: - sig - val mk: core_type -> class_type_field list -> class_signature - end - -(** Class structures *) -module Cstr: - sig - val mk: pattern -> class_field list -> class_structure - end diff --git a/jscomp/ml/ast_invariants.ml b/jscomp/ml/ast_invariants.ml index 31ee17eb9b..b6418e3504 100644 --- a/jscomp/ml/ast_invariants.ml +++ b/jscomp/ml/ast_invariants.ml @@ -49,7 +49,7 @@ let iterator = let loc = ty.ptyp_loc in match ty.ptyp_desc with | Ptyp_tuple ([] | [_]) -> invalid_tuple loc - | Ptyp_class (id, _) -> simple_longident id + | Ptyp_class () -> () | Ptyp_package (_, cstrs) -> List.iter (fun (id, _) -> simple_longident id) cstrs | _ -> () @@ -101,14 +101,6 @@ let iterator = | Pext_rebind id -> simple_longident id | _ -> () in - let class_expr self ce = - super.class_expr self ce; - let loc = ce.pcl_loc in - match ce.pcl_desc with - | Pcl_apply (_, []) -> no_args loc - | Pcl_constr (id, _) -> simple_longident id - | _ -> () - in let module_type self mty = super.module_type self mty; match mty.pmty_desc with @@ -153,7 +145,6 @@ let iterator = ; pat ; expr ; extension_constructor - ; class_expr ; module_expr ; module_type ; open_description diff --git a/jscomp/ml/ast_iterator.ml b/jscomp/ml/ast_iterator.ml index f5fa930a9a..8d2885b819 100755 --- a/jscomp/ml/ast_iterator.ml +++ b/jscomp/ml/ast_iterator.ml @@ -29,13 +29,6 @@ type iterator = { attributes: iterator -> attribute list -> unit; case: iterator -> case -> unit; cases: iterator -> case list -> unit; - class_expr: iterator -> class_expr -> unit; - class_field: iterator -> class_field -> unit; - class_signature: iterator -> class_signature -> unit; - class_structure: iterator -> class_structure -> unit; - class_type: iterator -> class_type -> unit; - class_type_declaration: iterator -> class_type_declaration -> unit; - class_type_field: iterator -> class_type_field -> unit; constructor_declaration: iterator -> constructor_declaration -> unit; expr: iterator -> expression -> unit; extension: iterator -> extension -> unit; @@ -103,8 +96,7 @@ module T = struct iter_loc sub lid; List.iter (sub.typ sub) tl | Ptyp_object (ol, _o) -> List.iter (object_field sub) ol - | Ptyp_class (lid, tl) -> - iter_loc sub lid; List.iter (sub.typ sub) tl + | Ptyp_class () -> () | Ptyp_alias (t, _) -> sub.typ sub t | Ptyp_variant (rl, _b, _ll) -> List.iter (row_field sub) rl @@ -171,39 +163,6 @@ module T = struct end -module CT = struct - (* Type expressions for the class language *) - - let iter sub {pcty_loc = loc; pcty_desc = desc; pcty_attributes = attrs} = - sub.location sub loc; - sub.attributes sub attrs; - match desc with - | Pcty_constr (lid, tys) -> - iter_loc sub lid; List.iter (sub.typ sub) tys - | Pcty_signature x -> sub.class_signature sub x - | Pcty_arrow (_lab, t, ct) -> - sub.typ sub t; sub.class_type sub ct - | Pcty_extension x -> sub.extension sub x - | Pcty_open (_ovf, lid, e) -> - iter_loc sub lid; sub.class_type sub e - - let iter_field sub {pctf_desc = desc; pctf_loc = loc; pctf_attributes = attrs} - = - sub.location sub loc; - sub.attributes sub attrs; - match desc with - | Pctf_inherit ct -> sub.class_type sub ct - | Pctf_val (_s, _m, _v, t) -> sub.typ sub t - | Pctf_method (_s, _p, _v, t) -> sub.typ sub t - | Pctf_constraint (t1, t2) -> - sub.typ sub t1; sub.typ sub t2 - | Pctf_attribute x -> sub.attribute sub x - | Pctf_extension x -> sub.extension sub x - - let iter_signature sub {pcsig_self; pcsig_fields} = - sub.typ sub pcsig_self; - List.iter (sub.class_type_field sub) pcsig_fields -end module MT = struct (* Type expressions for the module language *) @@ -249,8 +208,7 @@ module MT = struct | Psig_open x -> sub.open_description sub x | Psig_include x -> sub.include_description sub x | Psig_class () -> () - | Psig_class_type l -> - List.iter (sub.class_type_declaration sub) l + | Psig_class_type () -> () | Psig_extension (x, attrs) -> sub.extension sub x; sub.attributes sub attrs | Psig_attribute x -> sub.attribute sub x @@ -292,8 +250,7 @@ module M = struct | Pstr_modtype x -> sub.module_type_declaration sub x | Pstr_open x -> sub.open_description sub x | Pstr_class () -> () - | Pstr_class_type l -> - List.iter (sub.class_type_declaration sub) l + | Pstr_class_type () -> () | Pstr_include x -> sub.include_declaration sub x | Pstr_extension (x, attrs) -> sub.extension sub x; sub.attributes sub attrs @@ -367,7 +324,7 @@ module E = struct | Pexp_lazy e -> sub.expr sub e | Pexp_poly (e, t) -> sub.expr sub e; iter_opt (sub.typ sub) t - | Pexp_object cls -> sub.class_structure sub cls + | Pexp_object () -> () | Pexp_newtype (_s, e) -> sub.expr sub e | Pexp_pack me -> sub.module_expr sub me | Pexp_open (_ovf, lid, e) -> @@ -408,63 +365,6 @@ module P = struct end -module CE = struct - (* Value expressions for the class language *) - - let iter sub {pcl_loc = loc; pcl_desc = desc; pcl_attributes = attrs} = - sub.location sub loc; - sub.attributes sub attrs; - match desc with - | Pcl_constr (lid, tys) -> - iter_loc sub lid; List.iter (sub.typ sub) tys - | Pcl_structure s -> - sub.class_structure sub s - | Pcl_fun (_lab, e, p, ce) -> - iter_opt (sub.expr sub) e; - sub.pat sub p; - sub.class_expr sub ce - | Pcl_apply (ce, l) -> - sub.class_expr sub ce; - List.iter (iter_snd (sub.expr sub)) l - | Pcl_let (_r, vbs, ce) -> - List.iter (sub.value_binding sub) vbs; - sub.class_expr sub ce - | Pcl_constraint (ce, ct) -> - sub.class_expr sub ce; sub.class_type sub ct - | Pcl_extension x -> sub.extension sub x - | Pcl_open (_ovf, lid, e) -> - iter_loc sub lid; sub.class_expr sub e - - let iter_kind sub = function - | Cfk_concrete (_o, e) -> sub.expr sub e - | Cfk_virtual t -> sub.typ sub t - - let iter_field sub {pcf_desc = desc; pcf_loc = loc; pcf_attributes = attrs} = - sub.location sub loc; - sub.attributes sub attrs; - match desc with - | Pcf_inherit () -> () - | Pcf_val (s, _m, k) -> iter_loc sub s; iter_kind sub k - | Pcf_method (s, _p, k) -> - iter_loc sub s; iter_kind sub k - | Pcf_constraint (t1, t2) -> - sub.typ sub t1; sub.typ sub t2 - | Pcf_initializer e -> sub.expr sub e - | Pcf_attribute x -> sub.attribute sub x - | Pcf_extension x -> sub.extension sub x - - let iter_structure sub {pcstr_self; pcstr_fields} = - sub.pat sub pcstr_self; - List.iter (sub.class_field sub) pcstr_fields - - let class_infos sub f {pci_virt = _; pci_params = pl; pci_name; pci_expr; - pci_loc; pci_attributes} = - List.iter (iter_fst (sub.typ sub)) pl; - iter_loc sub pci_name; - f pci_expr; - sub.location sub pci_loc; - 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 @@ -479,14 +379,6 @@ let default_iterator = signature_item = MT.iter_signature_item; module_type = MT.iter; with_constraint = MT.iter_with_constraint; - class_expr = CE.iter; - class_field = CE.iter_field; - class_structure = CE.iter_structure; - class_type = CT.iter; - class_type_field = CT.iter_field; - class_signature = CT.iter_signature; - class_type_declaration = - (fun this -> CE.class_infos this (this.class_type this)); type_declaration = T.iter_type_declaration; type_kind = T.iter_type_kind; typ = T.iter; diff --git a/jscomp/ml/ast_iterator.mli b/jscomp/ml/ast_iterator.mli index 4f5058f1db..cf533fb164 100755 --- a/jscomp/ml/ast_iterator.mli +++ b/jscomp/ml/ast_iterator.mli @@ -26,13 +26,6 @@ type iterator = { attributes: iterator -> attribute list -> unit; case: iterator -> case -> unit; cases: iterator -> case list -> unit; - class_expr: iterator -> class_expr -> unit; - class_field: iterator -> class_field -> unit; - class_signature: iterator -> class_signature -> unit; - class_structure: iterator -> class_structure -> unit; - class_type: iterator -> class_type -> unit; - class_type_declaration: iterator -> class_type_declaration -> unit; - class_type_field: iterator -> class_type_field -> unit; constructor_declaration: iterator -> constructor_declaration -> unit; expr: iterator -> expression -> unit; extension: iterator -> extension -> unit; diff --git a/jscomp/ml/ast_mapper.ml b/jscomp/ml/ast_mapper.ml index 5aa10df2ff..710414c0b7 100644 --- a/jscomp/ml/ast_mapper.ml +++ b/jscomp/ml/ast_mapper.ml @@ -30,14 +30,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; @@ -106,8 +98,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 @@ -179,45 +170,6 @@ module T = struct 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 *) @@ -264,8 +216,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) @@ -310,8 +261,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) @@ -388,7 +338,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) @@ -430,71 +380,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) -> - let_ ~loc ~attrs r (List.map (sub.value_binding sub) vbs) - (sub.class_expr sub ce) - | 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_desc = desc; pcf_loc = loc; pcf_attributes = attrs} - | 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 @@ -509,14 +394,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; type_kind = T.map_type_kind; typ = T.map; diff --git a/jscomp/ml/ast_mapper.mli b/jscomp/ml/ast_mapper.mli index 3a4044d4c5..51a105d8e7 100644 --- a/jscomp/ml/ast_mapper.mli +++ b/jscomp/ml/ast_mapper.mli @@ -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; diff --git a/jscomp/ml/btype.ml b/jscomp/ml/btype.ml index de95c2dfe9..df9f8a4700 100644 --- a/jscomp/ml/btype.ml +++ b/jscomp/ml/btype.ml @@ -287,10 +287,7 @@ type type_iterators = it_extension_constructor: type_iterators -> extension_constructor -> unit; it_module_declaration: type_iterators -> module_declaration -> unit; it_modtype_declaration: type_iterators -> modtype_declaration -> unit; - it_class_declaration: type_iterators -> class_declaration -> unit; - it_class_type_declaration: type_iterators -> class_type_declaration -> unit; it_module_type: type_iterators -> module_type -> unit; - it_class_type: type_iterators -> class_type -> unit; it_type_kind: type_iterators -> type_kind -> unit; it_do_type_expr: type_iterators -> type_expr -> unit; it_type_expr: type_iterators -> type_expr -> unit; @@ -330,7 +327,7 @@ let type_iterators = | Sig_module (_, md, _) -> it.it_module_declaration it md | Sig_modtype (_, mtd) -> it.it_modtype_declaration it mtd | Sig_class () -> assert false - | Sig_class_type (_, ctd, _) -> it.it_class_type_declaration it ctd + | Sig_class_type () -> assert false and it_value_description it vd = it.it_type_expr it vd.val_type and it_type_declaration it td = @@ -346,15 +343,6 @@ let type_iterators = it.it_module_type it md.md_type and it_modtype_declaration it mtd = may (it.it_module_type it) mtd.mtd_type - and it_class_declaration it cd = - List.iter (it.it_type_expr it) cd.cty_params; - it.it_class_type it cd.cty_type; - may (it.it_type_expr it) cd.cty_new; - it.it_path cd.cty_path - and it_class_type_declaration it ctd = - List.iter (it.it_type_expr it) ctd.clty_params; - it.it_class_type it ctd.clty_type; - it.it_path ctd.clty_path and it_module_type it = function Mty_ident p | Mty_alias(_, p) -> it.it_path p @@ -362,20 +350,6 @@ let type_iterators = | Mty_functor (_, mto, mt) -> may (it.it_module_type it) mto; it.it_module_type it mt - and it_class_type it = function - Cty_constr (p, tyl, cty) -> - it.it_path p; - List.iter (it.it_type_expr it) tyl; - it.it_class_type it cty - | Cty_signature cs -> - it.it_type_expr it cs.csig_self; - Vars.iter (fun _ (_,_,ty) -> it.it_type_expr it ty) cs.csig_vars; - List.iter - (fun (p, tl) -> it.it_path p; List.iter (it.it_type_expr it) tl) - cs.csig_inher - | Cty_arrow (_, ty, cty) -> - it.it_type_expr it ty; - it.it_class_type it cty and it_type_kind it kind = iter_type_expr_kind (it.it_type_expr it) kind and it_do_type_expr it ty = @@ -391,8 +365,8 @@ let type_iterators = and it_path _p = () in { it_path; it_type_expr = it_do_type_expr; it_do_type_expr; - it_type_kind; it_class_type; it_module_type; - it_signature; it_class_type_declaration; it_class_declaration; + it_type_kind; it_module_type; + it_signature; it_modtype_declaration; it_module_declaration; it_extension_constructor; it_type_declaration; it_value_description; it_signature_item; } @@ -526,12 +500,6 @@ let unmark_extension_constructor ext = iter_type_expr_cstr_args unmark_type ext.ext_args; Misc.may unmark_type ext.ext_ret_type -let unmark_class_signature sign = - unmark_type sign.csig_self; - Vars.iter (fun _l (_m, _v, t) -> unmark_type t) sign.csig_vars - -let unmark_class_type cty = - unmark_iterators.it_class_type unmark_iterators cty (*******************************************) diff --git a/jscomp/ml/btype.mli b/jscomp/ml/btype.mli index ca1066cc5e..479ee63256 100644 --- a/jscomp/ml/btype.mli +++ b/jscomp/ml/btype.mli @@ -103,10 +103,7 @@ type type_iterators = it_extension_constructor: type_iterators -> extension_constructor -> unit; it_module_declaration: type_iterators -> module_declaration -> unit; it_modtype_declaration: type_iterators -> modtype_declaration -> unit; - it_class_declaration: type_iterators -> class_declaration -> unit; - it_class_type_declaration: type_iterators -> class_type_declaration -> unit; it_module_type: type_iterators -> module_type -> unit; - it_class_type: type_iterators -> class_type -> unit; it_type_kind: type_iterators -> type_kind -> unit; it_do_type_expr: type_iterators -> type_expr -> unit; it_type_expr: type_iterators -> type_expr -> unit; @@ -145,9 +142,6 @@ val mark_type_params: type_expr -> unit val unmark_type: type_expr -> unit val unmark_type_decl: type_declaration -> unit val unmark_extension_constructor: extension_constructor -> unit -val unmark_class_type: class_type -> unit -val unmark_class_signature: class_signature -> unit - (* Remove marks from a type *) (**** Memorization of abbreviation expansion ****) diff --git a/jscomp/ml/ctype.ml b/jscomp/ml/ctype.ml index 9aa37f2765..35da537cde 100644 --- a/jscomp/ml/ctype.ml +++ b/jscomp/ml/ctype.ml @@ -381,21 +381,6 @@ let hide_private_methods ty = (*******************************) -let rec signature_of_class_type = - function - Cty_constr (_, _, cty) -> signature_of_class_type cty - | Cty_signature sign -> sign - | Cty_arrow (_, _, cty) -> signature_of_class_type cty - -let self_type cty = - repr (signature_of_class_type cty).csig_self - -let rec class_type_arity = - function - Cty_constr (_, _, cty) -> class_type_arity cty - | Cty_signature _ -> 0 - | Cty_arrow (_, _, cty) -> 1 + class_type_arity cty - (*******************************************) (* Miscellaneous operations on row types *) @@ -546,34 +531,6 @@ type closed_class_failure = CC_Method of type_expr * bool * string * type_expr | CC_Value of type_expr * bool * string * type_expr -exception CCFailure of closed_class_failure - -let closed_class params sign = - let ty = object_fields (repr sign.csig_self) in - let (fields, rest) = flatten_fields ty in - List.iter mark_type params; - mark_type rest; - List.iter - (fun (lab, _, ty) -> if lab = dummy_method then mark_type ty) - fields; - try - mark_type_node (repr sign.csig_self); - List.iter - (fun (lab, kind, ty) -> - if field_kind_repr kind = Fpresent then - try closed_type ty with Non_closed (ty0, real) -> - raise (CCFailure (CC_Method (ty0, real, lab, ty)))) - fields; - mark_type_params (repr sign.csig_self); - List.iter unmark_type params; - unmark_class_signature sign; - None - with CCFailure reason -> - mark_type_params (repr sign.csig_self); - List.iter unmark_type params; - unmark_class_signature sign; - Some reason - (**********************) (* Type duplication *) @@ -585,8 +542,6 @@ let duplicate_type ty = Subst.type_expr Subst.identity ty (* Same, for class types *) -let duplicate_class_type ty = - Subst.class_type Subst.identity ty (*****************************) @@ -1175,28 +1130,6 @@ let instance_declaration decl = cleanup_types (); decl -let instance_class params cty = - let rec copy_class_type = - function - Cty_constr (path, tyl, cty) -> - Cty_constr (path, List.map simple_copy tyl, copy_class_type cty) - | Cty_signature sign -> - Cty_signature - {csig_self = copy sign.csig_self; - csig_vars = - Vars.map (function (m, v, ty) -> (m, v, copy ty)) sign.csig_vars; - csig_concr = sign.csig_concr; - csig_inher = - List.map (fun (p,tl) -> (p, List.map simple_copy tl)) - sign.csig_inher} - | Cty_arrow (l, ty, cty) -> - Cty_arrow (l, copy ty, copy_class_type cty) - in - let params' = List.map simple_copy params in - let cty' = copy_class_type cty in - cleanup_types (); - (params', cty') - (**** Instantiation for types with free universal variables ****) let rec diff_list l1 l2 = @@ -3346,9 +3279,6 @@ let eqtype_list rename type_pairs subst env tl1 tl2 = try eqtype_list rename type_pairs subst env tl1 tl2; backtrack snap with exn -> backtrack snap; raise exn -let eqtype rename type_pairs subst env t1 t2 = - eqtype_list rename type_pairs subst env [t1] [t2] - (* Two modes: with or without renaming of variables *) let equal env rename tyl1 tyl2 = try @@ -3366,7 +3296,6 @@ type class_match_failure = CM_Virtual_class | CM_Parameter_arity_mismatch of int * int | CM_Type_parameter_mismatch of Env.t * (type_expr * type_expr) list - | CM_Class_type_mismatch of Env.t * class_type * class_type | CM_Parameter_mismatch of Env.t * (type_expr * type_expr) list | CM_Val_type_mismatch of string * Env.t * (type_expr * type_expr) list | CM_Meth_type_mismatch of string * Env.t * (type_expr * type_expr) list @@ -3380,285 +3309,7 @@ type class_match_failure = | CM_Private_method of string | CM_Virtual_method of string -exception Failure of class_match_failure list - -let rec moregen_clty trace type_pairs env cty1 cty2 = - try - match cty1, cty2 with - Cty_constr (_, _, cty1), _ -> - moregen_clty true type_pairs env cty1 cty2 - | _, Cty_constr (_, _, cty2) -> - moregen_clty true type_pairs env cty1 cty2 - | Cty_arrow (l1, ty1, cty1'), Cty_arrow (l2, ty2, cty2') when Asttypes.same_arg_label l1 l2 -> - begin try moregen true type_pairs env ty1 ty2 with Unify trace -> - raise (Failure [CM_Parameter_mismatch (env, expand_trace env trace)]) - end; - moregen_clty false type_pairs env cty1' cty2' - | Cty_signature sign1, Cty_signature sign2 -> - let ty1 = object_fields (repr sign1.csig_self) in - let ty2 = object_fields (repr sign2.csig_self) in - let (fields1, _rest1) = flatten_fields ty1 - and (fields2, _rest2) = flatten_fields ty2 in - let (pairs, _miss1, _miss2) = associate_fields fields1 fields2 in - List.iter - (fun (lab, _k1, t1, _k2, t2) -> - begin try moregen true type_pairs env t1 t2 with Unify trace -> - raise (Failure [CM_Meth_type_mismatch - (lab, env, expand_trace env trace)]) - end) - pairs; - Vars.iter - (fun lab (_mut, _v, ty) -> - let (_mut', _v', ty') = Vars.find lab sign1.csig_vars in - try moregen true type_pairs env ty' ty with Unify trace -> - raise (Failure [CM_Val_type_mismatch - (lab, env, expand_trace env trace)])) - sign2.csig_vars - | _ -> - raise (Failure []) - with - Failure error when trace || error = [] -> - raise (Failure (CM_Class_type_mismatch (env, cty1, cty2)::error)) - -let match_class_types ?(trace=true) env pat_sch subj_sch = - let type_pairs = TypePairs.create 53 in - let old_level = !current_level in - current_level := generic_level - 1; - (* - Generic variables are first duplicated with [instance]. So, - their levels are lowered to [generic_level - 1]. The subject is - then copied with [duplicate_type]. That way, its levels won't be - changed. - *) - let (_, subj_inst) = instance_class [] subj_sch in - let subj = duplicate_class_type subj_inst in - current_level := generic_level; - (* Duplicate generic variables *) - let (_, patt) = instance_class [] pat_sch in - let res = - let sign1 = signature_of_class_type patt in - let sign2 = signature_of_class_type subj in - let t1 = repr sign1.csig_self in - let t2 = repr sign2.csig_self in - TypePairs.add type_pairs (t1, t2) (); - let (fields1, rest1) = flatten_fields (object_fields t1) - and (fields2, rest2) = flatten_fields (object_fields t2) in - let (pairs, miss1, miss2) = associate_fields fields1 fields2 in - let error = - List.fold_right - (fun (lab, k, _) err -> - let err = - let k = field_kind_repr k in - begin match k with - Fvar r -> set_kind r Fabsent; err - | _ -> CM_Hide_public lab::err - end - in - if Concr.mem lab sign1.csig_concr then err - else CM_Hide_virtual ("method", lab) :: err) - miss1 [] - in - let missing_method = List.map (fun (m, _, _) -> m) miss2 in - let error = - (List.map (fun m -> CM_Missing_method m) missing_method) @ error - in - (* Always succeeds *) - moregen true type_pairs env rest1 rest2; - let error = - List.fold_right - (fun (lab, k1, _t1, k2, _t2) err -> - try moregen_kind k1 k2; err with - Unify _ -> CM_Public_method lab::err) - pairs error - in - let error = - Vars.fold - (fun lab (mut, vr, _ty) err -> - try - let (mut', vr', _ty') = Vars.find lab sign1.csig_vars in - if mut = Mutable && mut' <> Mutable then - CM_Non_mutable_value lab::err - else if vr = Concrete && vr' <> Concrete then - CM_Non_concrete_value lab::err - else - err - with Not_found -> - CM_Missing_value lab::err) - sign2.csig_vars error - in - let error = - Vars.fold - (fun lab (_,vr,_) err -> - if vr = Virtual && not (Vars.mem lab sign2.csig_vars) then - CM_Hide_virtual ("instance variable", lab) :: err - else err) - sign1.csig_vars error - in - let error = - List.fold_right - (fun e l -> - if List.mem e missing_method then l else CM_Virtual_method e::l) - (Concr.elements (Concr.diff sign2.csig_concr sign1.csig_concr)) - error - in - match error with - [] -> - begin try - moregen_clty trace type_pairs env patt subj; - [] - with - Failure r -> r - end - | error -> - CM_Class_type_mismatch (env, patt, subj)::error - in - current_level := old_level; - res -let rec equal_clty trace type_pairs subst env cty1 cty2 = - try - match cty1, cty2 with - Cty_constr (_, _, cty1), Cty_constr (_, _, cty2) -> - equal_clty true type_pairs subst env cty1 cty2 - | Cty_constr (_, _, cty1), _ -> - equal_clty true type_pairs subst env cty1 cty2 - | _, Cty_constr (_, _, cty2) -> - equal_clty true type_pairs subst env cty1 cty2 - | Cty_arrow (l1, ty1, cty1'), Cty_arrow (l2, ty2, cty2') when Asttypes.same_arg_label l1 l2 -> - begin try eqtype true type_pairs subst env ty1 ty2 with Unify trace -> - raise (Failure [CM_Parameter_mismatch (env, expand_trace env trace)]) - end; - equal_clty false type_pairs subst env cty1' cty2' - | Cty_signature sign1, Cty_signature sign2 -> - let ty1 = object_fields (repr sign1.csig_self) in - let ty2 = object_fields (repr sign2.csig_self) in - let (fields1, _rest1) = flatten_fields ty1 - and (fields2, _rest2) = flatten_fields ty2 in - let (pairs, _miss1, _miss2) = associate_fields fields1 fields2 in - List.iter - (fun (lab, _k1, t1, _k2, t2) -> - begin try eqtype true type_pairs subst env t1 t2 with - Unify trace -> - raise (Failure [CM_Meth_type_mismatch - (lab, env, expand_trace env trace)]) - end) - pairs; - Vars.iter - (fun lab (_, _, ty) -> - let (_, _, ty') = Vars.find lab sign1.csig_vars in - try eqtype true type_pairs subst env ty' ty with Unify trace -> - raise (Failure [CM_Val_type_mismatch - (lab, env, expand_trace env trace)])) - sign2.csig_vars - | _ -> - raise - (Failure (if trace then [] - else [CM_Class_type_mismatch (env, cty1, cty2)])) - with - Failure error when trace -> - raise (Failure (CM_Class_type_mismatch (env, cty1, cty2)::error)) - -let match_class_declarations env patt_params patt_type subj_params subj_type = - let type_pairs = TypePairs.create 53 in - let subst = ref [] in - let sign1 = signature_of_class_type patt_type in - let sign2 = signature_of_class_type subj_type in - let t1 = repr sign1.csig_self in - let t2 = repr sign2.csig_self in - TypePairs.add type_pairs (t1, t2) (); - let (fields1, rest1) = flatten_fields (object_fields t1) - and (fields2, rest2) = flatten_fields (object_fields t2) in - let (pairs, miss1, miss2) = associate_fields fields1 fields2 in - let error = - List.fold_right - (fun (lab, k, _) err -> - let err = - let k = field_kind_repr k in - begin match k with - Fvar _ -> err - | _ -> CM_Hide_public lab::err - end - in - if Concr.mem lab sign1.csig_concr then err - else CM_Hide_virtual ("method", lab) :: err) - miss1 [] - in - let missing_method = List.map (fun (m, _, _) -> m) miss2 in - let error = - (List.map (fun m -> CM_Missing_method m) missing_method) @ error - in - (* Always succeeds *) - eqtype true type_pairs subst env rest1 rest2; - let error = - List.fold_right - (fun (lab, k1, _t1, k2, _t2) err -> - let k1 = field_kind_repr k1 in - let k2 = field_kind_repr k2 in - match k1, k2 with - (Fvar _, Fvar _) - | (Fpresent, Fpresent) -> err - | (Fvar _, Fpresent) -> CM_Private_method lab::err - | (Fpresent, Fvar _) -> CM_Public_method lab::err - | _ -> assert false) - pairs error - in - let error = - Vars.fold - (fun lab (mut, vr, _ty) err -> - try - let (mut', vr', _ty') = Vars.find lab sign1.csig_vars in - if mut = Mutable && mut' <> Mutable then - CM_Non_mutable_value lab::err - else if vr = Concrete && vr' <> Concrete then - CM_Non_concrete_value lab::err - else - err - with Not_found -> - CM_Missing_value lab::err) - sign2.csig_vars error - in - let error = - Vars.fold - (fun lab (_,vr,_) err -> - if vr = Virtual && not (Vars.mem lab sign2.csig_vars) then - CM_Hide_virtual ("instance variable", lab) :: err - else err) - sign1.csig_vars error - in - let error = - List.fold_right - (fun e l -> - if List.mem e missing_method then l else CM_Virtual_method e::l) - (Concr.elements (Concr.diff sign2.csig_concr sign1.csig_concr)) - error - in - match error with - [] -> - begin try - let lp = List.length patt_params in - let ls = List.length subj_params in - if lp <> ls then - raise (Failure [CM_Parameter_arity_mismatch (lp, ls)]); - List.iter2 (fun p s -> - try eqtype true type_pairs subst env p s with Unify trace -> - raise (Failure [CM_Type_parameter_mismatch - (env, expand_trace env trace)])) - patt_params subj_params; - (* old code: equal_clty false type_pairs subst env patt_type subj_type; *) - equal_clty false type_pairs subst env - (Cty_signature sign1) (Cty_signature sign2); - (* Use moregeneral for class parameters, need to recheck everything to - keeps relationships (PR#4824) *) - let clty_params = - List.fold_right (fun ty cty -> Cty_arrow (Labelled "*",ty,cty)) in - match_class_types ~trace:false env - (clty_params patt_params patt_type) - (clty_params subj_params subj_type) - with - Failure r -> r - end - | error -> - error (***************) @@ -4538,62 +4189,6 @@ let nondep_extension_constructor env mid ext = raise Not_found -(* Preserve sharing inside class types. *) -let nondep_class_signature env id sign = - { csig_self = nondep_type_rec env id sign.csig_self; - csig_vars = - Vars.map (function (m, v, t) -> (m, v, nondep_type_rec env id t)) - sign.csig_vars; - csig_concr = sign.csig_concr; - csig_inher = - List.map (fun (p,tl) -> (p, List.map (nondep_type_rec env id) tl)) - sign.csig_inher } - -let rec nondep_class_type env id = - function - Cty_constr (p, _, cty) when Path.isfree id p -> - nondep_class_type env id cty - | Cty_constr (p, tyl, cty) -> - Cty_constr (p, List.map (nondep_type_rec env id) tyl, - nondep_class_type env id cty) - | Cty_signature sign -> - Cty_signature (nondep_class_signature env id sign) - | Cty_arrow (l, ty, cty) -> - Cty_arrow (l, nondep_type_rec env id ty, nondep_class_type env id cty) - -let nondep_class_declaration env id decl = - assert (not (Path.isfree id decl.cty_path)); - let decl = - { cty_params = List.map (nondep_type_rec env id) decl.cty_params; - cty_variance = decl.cty_variance; - cty_type = nondep_class_type env id decl.cty_type; - cty_path = decl.cty_path; - cty_new = - begin match decl.cty_new with - None -> None - | Some ty -> Some (nondep_type_rec env id ty) - end; - cty_loc = decl.cty_loc; - cty_attributes = decl.cty_attributes; - } - in - clear_hash (); - decl - -let nondep_cltype_declaration env id decl = - assert (not (Path.isfree id decl.clty_path)); - let decl = - { clty_params = List.map (nondep_type_rec env id) decl.clty_params; - clty_variance = decl.clty_variance; - clty_type = nondep_class_type env id decl.clty_type; - clty_path = decl.clty_path; - clty_loc = decl.clty_loc; - clty_attributes = decl.clty_attributes; - } - in - clear_hash (); - decl - (* collapse conjunctive types in class parameters *) let rec collapse_conj env visited ty = let ty = repr ty in diff --git a/jscomp/ml/ctype.mli b/jscomp/ml/ctype.mli index 7b68649e46..0fae1711bd 100644 --- a/jscomp/ml/ctype.mli +++ b/jscomp/ml/ctype.mli @@ -129,8 +129,6 @@ val instance_parameterized_type_2: type_expr list -> type_expr list -> type_expr -> type_expr list * type_expr list * type_expr val instance_declaration: type_declaration -> type_declaration -val instance_class: - type_expr list -> class_type -> type_expr list * class_type val instance_poly: ?keep_names:bool -> bool -> type_expr list -> type_expr -> type_expr list * type_expr @@ -196,7 +194,6 @@ type class_match_failure = CM_Virtual_class | CM_Parameter_arity_mismatch of int * int | CM_Type_parameter_mismatch of Env.t * (type_expr * type_expr) list - | CM_Class_type_mismatch of Env.t * class_type * class_type | CM_Parameter_mismatch of Env.t * (type_expr * type_expr) list | CM_Val_type_mismatch of string * Env.t * (type_expr * type_expr) list | CM_Meth_type_mismatch of string * Env.t * (type_expr * type_expr) list @@ -209,17 +206,10 @@ type class_match_failure = | CM_Public_method of string | CM_Private_method of string | CM_Virtual_method of string -val match_class_types: - ?trace:bool -> Env.t -> class_type -> class_type -> class_match_failure list - (* Check if the first class type is more general than the second. *) val equal: Env.t -> bool -> type_expr list -> type_expr list -> bool (* [equal env [x1...xn] tau [y1...yn] sigma] checks whether the parameterized types [/\x1.../\xn.tau] and [/\y1.../\yn.sigma] are equivalent. *) -val match_class_declarations: - Env.t -> type_expr list -> class_type -> type_expr list -> - class_type -> class_match_failure list - (* Check if the first class type is more general than the second. *) val enlarge_type: Env.t -> type_expr -> type_expr * bool (* Make a type larger, flag is true if some pruning had to be done *) @@ -241,12 +231,6 @@ val nondep_extension_constructor: Env.t -> Ident.t -> extension_constructor -> extension_constructor (* Same for extension constructor *) -val nondep_class_declaration: - Env.t -> Ident.t -> class_declaration -> class_declaration - (* Same for class declarations. *) -val nondep_cltype_declaration: - Env.t -> Ident.t -> class_type_declaration -> class_type_declaration - (* Same for class type declarations. *) (*val correct_abbrev: Env.t -> Path.t -> type_expr list -> type_expr -> unit*) val cyclic_abbrev: Env.t -> Ident.t -> type_expr -> bool val is_contractive: Env.t -> Path.t -> bool @@ -263,14 +247,8 @@ val closed_extension_constructor: extension_constructor -> type_expr option type closed_class_failure = CC_Method of type_expr * bool * string * type_expr | CC_Value of type_expr * bool * string * type_expr -val closed_class: - type_expr list -> class_signature -> closed_class_failure option - (* Check whether all type variables are bound *) val unalias: type_expr -> type_expr -val signature_of_class_type: class_type -> class_signature -val self_type: class_type -> type_expr -val class_type_arity: class_type -> int val arity: type_expr -> int (* Return the arity (as for curried functions) of the given type. *) diff --git a/jscomp/ml/depend.ml b/jscomp/ml/depend.ml index 5a4a336a16..1d2c46279d 100644 --- a/jscomp/ml/depend.ml +++ b/jscomp/ml/depend.ml @@ -108,7 +108,7 @@ let rec add_type bv ty = List.iter (function Otag (_, _, t) -> add_type bv t | Oinherit t -> add_type bv t) fl - | Ptyp_class(c, tl) -> add bv c; List.iter (add_type bv) tl + | Ptyp_class() -> () | Ptyp_alias(t, _) -> add_type bv t | Ptyp_variant(fl, _, _) -> List.iter @@ -160,33 +160,6 @@ let add_type_extension bv te = add bv te.ptyext_path; List.iter (add_extension_constructor bv) te.ptyext_constructors -let rec add_class_type bv cty = - match cty.pcty_desc with - Pcty_constr(l, tyl) -> - add bv l; List.iter (add_type bv) tyl - | Pcty_signature { pcsig_self = ty; pcsig_fields = fieldl } -> - add_type bv ty; - List.iter (add_class_type_field bv) fieldl - | Pcty_arrow(_, ty1, cty2) -> - add_type bv ty1; add_class_type bv cty2 - | Pcty_extension e -> handle_extension e - | Pcty_open (_ovf, m, e) -> - let bv = open_module bv m.txt in add_class_type bv e - -and add_class_type_field bv pctf = - match pctf.pctf_desc with - Pctf_inherit cty -> add_class_type bv cty - | Pctf_val(_, _, _, ty) -> add_type bv ty - | Pctf_method(_, _, _, ty) -> add_type bv ty - | Pctf_constraint(ty1, ty2) -> add_type bv ty1; add_type bv ty2 - | Pctf_attribute _ -> () - | Pctf_extension e -> handle_extension e - -let add_class_description bv infos = - add_class_type bv infos.pci_expr - -let add_class_type_declaration = add_class_description - let pattern_bv = ref StringMap.empty let rec add_pattern bv pat = @@ -263,8 +236,7 @@ let rec add_expr bv exp = | Pexp_assert (e) -> add_expr bv e | Pexp_lazy (e) -> add_expr bv e | Pexp_poly (e, t) -> add_expr bv e; add_opt add_type bv t - | Pexp_object { pcstr_self = pat; pcstr_fields = fieldl } -> - let bv = add_pattern bv pat in List.iter (add_class_field bv) fieldl + | Pexp_object () -> () | Pexp_newtype (_, e) -> add_expr bv e | Pexp_pack m -> add_module bv m | Pexp_open (_ovf, m, e) -> @@ -378,8 +350,8 @@ and add_sig_item (bv, m) item = (add bv, add m) | Psig_class () -> (bv, m) - | Psig_class_type cdtl -> - List.iter (add_class_type_declaration bv) cdtl; (bv, m) + | Psig_class_type () -> + (bv, m) | Psig_attribute _ -> (bv, m) | Psig_extension (e, _) -> handle_extension e; @@ -464,8 +436,8 @@ and add_struct_item (bv, m) item : _ StringMap.t * _ StringMap.t = (open_module bv od.popen_lid.txt, m) | Pstr_class () -> (bv,m) - | Pstr_class_type cdtl -> - List.iter (add_class_type_declaration bv) cdtl; (bv, m) + | Pstr_class_type () -> + (bv, m) | Pstr_include incl -> let Node (s, m') = add_module_binding bv incl.pincl_mod in add_names s; @@ -485,17 +457,3 @@ and add_implementation bv l = and add_implementation_binding bv l = snd (add_structure_binding bv l) - - -and add_class_field bv pcf = - match pcf.pcf_desc with - Pcf_inherit() -> () - | Pcf_val(_, _, Cfk_concrete (_, e)) - | Pcf_method(_, _, Cfk_concrete (_, e)) -> add_expr bv e - | Pcf_val(_, _, Cfk_virtual ty) - | Pcf_method(_, _, Cfk_virtual ty) -> add_type bv ty - | Pcf_constraint(ty1, ty2) -> add_type bv ty1; add_type bv ty2 - | Pcf_initializer e -> add_expr bv e - | Pcf_attribute _ -> () - | Pcf_extension e -> handle_extension e - diff --git a/jscomp/ml/env.ml b/jscomp/ml/env.ml index 8a914c825a..af9308691a 100644 --- a/jscomp/ml/env.ml +++ b/jscomp/ml/env.ml @@ -159,7 +159,7 @@ type summary = | Env_module of summary * Ident.t * module_declaration | Env_modtype of summary * Ident.t * modtype_declaration | Env_class of unit - | Env_cltype of summary * Ident.t * class_type_declaration + | Env_cltype of unit | Env_open of summary * Path.t | Env_functor_arg of summary * Ident.t | Env_constraints of summary * type_declaration PathMap.t @@ -445,8 +445,6 @@ type t = { modules: (Subst.t * module_declaration, module_declaration) EnvLazy.t IdTbl.t; modtypes: modtype_declaration IdTbl.t; components: module_components IdTbl.t; - classes: class_declaration IdTbl.t; - cltypes: class_type_declaration IdTbl.t; functor_args: unit Ident.tbl; summary: summary; local_constraints: type_declaration PathMap.t; @@ -477,9 +475,7 @@ and structure_components = { mutable comp_modules: (Subst.t * module_declaration, module_declaration) EnvLazy.t comp_tbl; mutable comp_modtypes: modtype_declaration comp_tbl; - mutable comp_components: module_components comp_tbl; - comp_classes: class_declaration comp_tbl; (* warning -69*) - mutable comp_cltypes: class_type_declaration comp_tbl; + mutable comp_components: module_components comp_tbl; (* warning -69*) } and functor_components = { @@ -516,11 +512,9 @@ let check_shadowing env = function | `Type (Some _) -> Some "type" | `Module (Some _) | `Component (Some _) -> Some "module" | `Module_type (Some _) -> Some "module type" - | `Class (Some _) -> Some "class" - | `Class_type (Some _) -> Some "class type" | `Constructor _ | `Label _ | `Value None | `Type None | `Module None | `Module_type None - | `Class None | `Class_type None | `Component None -> + | `Component None -> None let subst_modtype_maker (subst, md) = @@ -531,8 +525,7 @@ let empty = { values = IdTbl.empty; constrs = TycompTbl.empty; labels = TycompTbl.empty; types = IdTbl.empty; modules = IdTbl.empty; modtypes = IdTbl.empty; - components = IdTbl.empty; classes = IdTbl.empty; - cltypes = IdTbl.empty; + components = IdTbl.empty; summary = Env_empty; local_constraints = PathMap.empty; gadt_instances = []; flags = 0; functor_args = Ident.empty; @@ -562,8 +555,7 @@ let is_local_ext = function let diff env1 env2 = IdTbl.diff_keys env1.values env2.values @ TycompTbl.diff_keys is_local_ext env1.constrs env2.constrs @ - IdTbl.diff_keys env1.modules env2.modules @ - IdTbl.diff_keys env1.classes env2.classes + IdTbl.diff_keys env1.modules env2.modules type can_load_cmis = | Can_load_cmis @@ -620,8 +612,8 @@ let empty_structure = comp_labels = Tbl.empty; comp_types = Tbl.empty; comp_modules = Tbl.empty; comp_modtypes = Tbl.empty; - comp_components = Tbl.empty; comp_classes = Tbl.empty; - comp_cltypes = Tbl.empty } + comp_components = Tbl.empty; + } let get_components c = match get_components_opt c with @@ -877,10 +869,6 @@ and find_type_full = find (fun env -> env.types) (fun sc -> sc.comp_types) and find_modtype = find (fun env -> env.modtypes) (fun sc -> sc.comp_modtypes) -and find_class = - find (fun env -> env.classes) (fun sc -> sc.comp_classes) -and find_cltype = - find (fun env -> env.cltypes) (fun sc -> sc.comp_cltypes) let type_of_cstr path = function | {cstr_inlined = Some d; _} -> @@ -1238,10 +1226,6 @@ let lookup_type = lookup (fun env -> env.types) (fun sc -> sc.comp_types) let lookup_modtype = lookup (fun env -> env.modtypes) (fun sc -> sc.comp_modtypes) -let lookup_class = - lookup (fun env -> env.classes) (fun sc -> sc.comp_classes) -let lookup_cltype = - lookup (fun env -> env.cltypes) (fun sc -> sc.comp_cltypes) let copy_types l env = let f desc = {desc with val_type = Subst.type_expr Subst.identity desc.val_type} in @@ -1370,19 +1354,6 @@ let lookup_all_labels ?loc lid env = with Not_found when is_lident lid -> [] -let lookup_class ?loc lid env = - let (_, desc) as r = lookup_class ?loc lid env in - (* special support for Typeclass.unbound_class *) - if Path.name desc.cty_path = "" then ignore (lookup_type ?loc lid env) - else mark_type_path env desc.cty_path; - r - -let lookup_cltype ?loc lid env = - let (_, desc) as r = lookup_cltype ?loc lid env in - if Path.name desc.clty_path = "" then ignore (lookup_type ?loc lid env) - else mark_type_path env desc.clty_path; - mark_type_path env desc.clty_path; - r (* Iter on an environment (ignoring the body of functors and not yet evaluated structures) *) @@ -1588,12 +1559,9 @@ let rec prefix_idents root pos sub = function (Subst.add_modtype id (Mty_ident p) sub) rem in (p::pl, final_sub) | Sig_class _ :: _ -> - assert false - | Sig_class_type(id, _, _) :: rem -> - let p = Pdot(root, Ident.name id, nopos) in - let (pl, final_sub) = - prefix_idents root pos (Subst.add_type id p sub) rem in - (p::pl, final_sub) + assert false + | Sig_class_type _ :: _ -> + assert false let prefix_idents root sub sg = if sub = Subst.identity then @@ -1636,8 +1604,8 @@ and components_of_module_maker (env, sub, path, mty) = comp_constrs = Tbl.empty; comp_labels = Tbl.empty; comp_types = Tbl.empty; comp_modules = Tbl.empty; comp_modtypes = Tbl.empty; - comp_components = Tbl.empty; comp_classes = Tbl.empty; - comp_cltypes = Tbl.empty } in + comp_components = Tbl.empty; + } in let pl, sub = prefix_idents path sub sg in let env = ref env in let pos = ref 0 in @@ -1699,10 +1667,7 @@ and components_of_module_maker (env, sub, path, mty) = Tbl.add (Ident.name id) (decl', nopos) c.comp_modtypes; env := store_modtype id decl !env | Sig_class () -> assert false - | Sig_class_type(id, decl, _) -> - let decl' = Subst.cltype_declaration sub decl in - c.comp_cltypes <- - Tbl.add (Ident.name id) (decl', !pos) c.comp_cltypes) + | Sig_class_type () -> assert false) sg pl; Some (Structure_comps c) | Mty_functor(param, ty_arg, ty_res) -> @@ -1856,12 +1821,6 @@ and store_modtype id info env = modtypes = IdTbl.add id info env.modtypes; summary = Env_modtype(env.summary, id, info) } - -and store_cltype id desc env = - { env with - cltypes = IdTbl.add id desc env.cltypes; - summary = Env_cltype(env.summary, id, desc) } - (* Compute the components of a functor application in a path. *) let components_of_functor_appl f env p1 p2 = @@ -1908,10 +1867,6 @@ and add_modtype id info env = store_modtype id info env - -and add_cltype id ty env = - store_cltype id ty env - let add_module ?arg id mty env = add_module_declaration ~check:false ?arg id (md mty) env @@ -1942,7 +1897,6 @@ and enter_module_declaration ?arg id md env = (id, add_functor_arg ?arg id env) *) and enter_modtype = enter store_modtype -and enter_cltype = enter store_cltype let enter_module ?arg s mty env = let id = Ident.create s in @@ -1957,8 +1911,8 @@ let add_item comp env = | Sig_typext(id, ext, _) -> add_extension ~check:false id ext env | Sig_module(id, md, _) -> add_module_declaration ~check:false id md env | Sig_modtype(id, decl) -> add_modtype id decl env - | Sig_class() -> env - | Sig_class_type(id, decl, _) -> add_cltype id decl env + | Sig_class () -> env + | Sig_class_type () -> env let rec add_signature sg env = match sg with @@ -1990,12 +1944,6 @@ let add_components slot root env0 comps = let modtypes = add (fun x -> `Module_type x) comps.comp_modtypes env0.modtypes in - let classes = - add (fun x -> `Class x) comps.comp_classes env0.classes - in - let cltypes = - add (fun x -> `Class_type x) comps.comp_cltypes env0.cltypes - in let components = add (fun x -> `Component x) comps.comp_components env0.components in @@ -2011,8 +1959,6 @@ let add_components slot root env0 comps = values; types; modtypes; - classes; - cltypes; components; modules; } @@ -2226,10 +2172,6 @@ and fold_types f = find_all (fun env -> env.types) (fun sc -> sc.comp_types) f and fold_modtypes f = find_all (fun env -> env.modtypes) (fun sc -> sc.comp_modtypes) f -and fold_classs f = - find_all (fun env -> env.classes) (fun sc -> sc.comp_classes) f -and fold_cltypes f = - find_all (fun env -> env.cltypes) (fun sc -> sc.comp_cltypes) f (* Make the initial environment *) diff --git a/jscomp/ml/env.mli b/jscomp/ml/env.mli index dfa1027de5..d1d1b5028e 100644 --- a/jscomp/ml/env.mli +++ b/jscomp/ml/env.mli @@ -28,7 +28,7 @@ type summary = | Env_module of summary * Ident.t * module_declaration | Env_modtype of summary * Ident.t * modtype_declaration | Env_class of unit - | Env_cltype of summary * Ident.t * class_type_declaration + | Env_cltype of unit | Env_open of summary * Path.t | Env_functor_arg of summary * Ident.t | Env_constraints of summary * type_declaration PathMap.t @@ -65,8 +65,6 @@ val find_type: Path.t -> t -> type_declaration val find_type_descrs: Path.t -> t -> type_descriptions val find_module: Path.t -> t -> module_declaration val find_modtype: Path.t -> t -> modtype_declaration -val find_class: Path.t -> t -> class_declaration -val find_cltype: Path.t -> t -> class_type_declaration val find_type_expansion: Path.t -> t -> type_expr list * type_expr * int option @@ -119,10 +117,6 @@ val lookup_module: load:bool -> ?loc:Location.t -> Longident.t -> t -> Path.t val lookup_modtype: ?loc:Location.t -> Longident.t -> t -> Path.t * modtype_declaration -val lookup_class: - ?loc:Location.t -> Longident.t -> t -> Path.t * class_declaration -val lookup_cltype: - ?loc:Location.t -> Longident.t -> t -> Path.t * class_type_declaration val copy_types: string list -> t -> t (* Used only in Typecore.duplicate_ident_types. *) @@ -143,7 +137,6 @@ val add_module_declaration: ?arg:bool -> check:bool -> Ident.t -> module_declaration -> t -> t val add_modtype: Ident.t -> modtype_declaration -> t -> t -val add_cltype: Ident.t -> class_type_declaration -> t -> t val add_local_constraint: Path.t -> type_declaration -> int -> t -> t val add_local_type: Path.t -> type_declaration -> t -> t @@ -174,7 +167,6 @@ val enter_module_declaration: ?arg:bool -> Ident.t -> module_declaration -> t -> t val enter_modtype: string -> modtype_declaration -> t -> Ident.t * t -val enter_cltype: string -> class_type_declaration -> t -> Ident.t * t (* Initialize the cache of in-core module interfaces. *) val reset_cache: unit -> unit @@ -300,12 +292,6 @@ val fold_modules: val fold_modtypes: (string -> Path.t -> modtype_declaration -> 'a -> 'a) -> Longident.t option -> t -> 'a -> 'a -val fold_classs: - (string -> Path.t -> class_declaration -> 'a -> 'a) -> - Longident.t option -> t -> 'a -> 'a -val fold_cltypes: - (string -> Path.t -> class_type_declaration -> 'a -> 'a) -> - Longident.t option -> t -> 'a -> 'a (** Utilities *) val scrape_alias: t -> module_type -> module_type diff --git a/jscomp/ml/envaux.ml b/jscomp/ml/envaux.ml index 5fd5020465..51818b5003 100644 --- a/jscomp/ml/envaux.ml +++ b/jscomp/ml/envaux.ml @@ -54,9 +54,7 @@ let rec env_from_summary sum subst = | Env_modtype(s, id, desc) -> Env.add_modtype id (Subst.modtype_declaration subst desc) (env_from_summary s subst) - | Env_cltype (s, id, desc) -> - Env.add_cltype id (Subst.cltype_declaration subst desc) - (env_from_summary s subst) + | Env_cltype () -> assert false | Env_open(s, path) -> let env = env_from_summary s subst in let path' = Subst.module_path subst path in diff --git a/jscomp/ml/includeclass.ml b/jscomp/ml/includeclass.ml deleted file mode 100644 index 7f1b1bdd8f..0000000000 --- a/jscomp/ml/includeclass.ml +++ /dev/null @@ -1,116 +0,0 @@ -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 1997 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -(* Inclusion checks for the class language *) - -open Types - -let class_types env cty1 cty2 = - Ctype.match_class_types env cty1 cty2 - -let class_type_declarations ~loc env cty1 cty2 = - Builtin_attributes.check_deprecated_inclusion - ~def:cty1.clty_loc - ~use:cty2.clty_loc - loc - cty1.clty_attributes cty2.clty_attributes - (Path.last cty1.clty_path); - Ctype.match_class_declarations env - cty1.clty_params cty1.clty_type - cty2.clty_params cty2.clty_type - -let class_declarations env cty1 cty2 = - match cty1.cty_new, cty2.cty_new with - None, Some _ -> - [Ctype.CM_Virtual_class] - | _ -> - Ctype.match_class_declarations env - cty1.cty_params cty1.cty_type - cty2.cty_params cty2.cty_type - -open Format -open Ctype - -(* -let rec hide_params = function - Tcty_arrow ("*", _, cty) -> hide_params cty - | cty -> cty -*) - -let include_err ppf = - function - | CM_Virtual_class -> - fprintf ppf "A class cannot be changed from virtual to concrete" - | CM_Parameter_arity_mismatch _ -> - fprintf ppf - "The classes do not have the same number of type parameters" - | CM_Type_parameter_mismatch (env, trace) -> - Printtyp.report_unification_error ppf env ~unif:false trace - (function ppf -> - fprintf ppf "A type parameter has type") - (function ppf -> - fprintf ppf "but is expected to have type") - | CM_Class_type_mismatch (env, cty1, cty2) -> - Printtyp.wrap_printing_env env (fun () -> - fprintf ppf - "@[The class type@;<1 2>%a@ %s@;<1 2>%a@]" - Printtyp.class_type cty1 - "is not matched by the class type" - Printtyp.class_type cty2) - | CM_Parameter_mismatch (env, trace) -> - Printtyp.report_unification_error ppf env ~unif:false trace - (function ppf -> - fprintf ppf "A parameter has type") - (function ppf -> - fprintf ppf "but is expected to have type") - | CM_Val_type_mismatch (lab, env, trace) -> - Printtyp.report_unification_error ppf env ~unif:false trace - (function ppf -> - fprintf ppf "The instance variable %s@ has type" lab) - (function ppf -> - fprintf ppf "but is expected to have type") - | CM_Meth_type_mismatch (lab, env, trace) -> - Printtyp.report_unification_error ppf env ~unif:false trace - (function ppf -> - fprintf ppf "The method %s@ has type" lab) - (function ppf -> - fprintf ppf "but is expected to have type") - | CM_Non_mutable_value lab -> - fprintf ppf - "@[The non-mutable instance variable %s cannot become mutable@]" lab - | CM_Non_concrete_value lab -> - fprintf ppf - "@[The virtual instance variable %s cannot become concrete@]" lab - | CM_Missing_value lab -> - fprintf ppf "@[The first class type has no instance variable %s@]" lab - | CM_Missing_method lab -> - fprintf ppf "@[The first class type has no field %s@]" lab - | CM_Hide_public lab -> - fprintf ppf "@[The public method %s cannot be hidden@]" lab - | CM_Hide_virtual (k, lab) -> - fprintf ppf "@[The virtual %s %s cannot be hidden@]" k lab - | CM_Public_method lab -> - fprintf ppf "@[The public method %s cannot become private" lab - | CM_Virtual_method lab -> - fprintf ppf "@[The virtual method %s cannot become concrete" lab - | CM_Private_method lab -> - fprintf ppf "The private method %s cannot become public" lab - -let report_error ppf = function - | [] -> () - | err :: errs -> - let print_errs ppf errs = - List.iter (fun err -> fprintf ppf "@ %a" include_err err) errs in - fprintf ppf "@[%a%a@]" include_err err print_errs errs diff --git a/jscomp/ml/includeclass.mli b/jscomp/ml/includeclass.mli deleted file mode 100644 index ebfa97897f..0000000000 --- a/jscomp/ml/includeclass.mli +++ /dev/null @@ -1,32 +0,0 @@ -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 1997 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -(* Inclusion checks for the class language *) - -open Types -open Ctype -open Format - -val class_types: - Env.t -> class_type -> class_type -> class_match_failure list -val class_type_declarations: - loc:Location.t -> - Env.t -> class_type_declaration -> class_type_declaration -> - class_match_failure list -val class_declarations: - Env.t -> class_declaration -> class_declaration -> - class_match_failure list - -val report_error: formatter -> class_match_failure list -> unit diff --git a/jscomp/ml/includemod.ml b/jscomp/ml/includemod.ml index 1f73880917..4f02122d90 100644 --- a/jscomp/ml/includemod.ml +++ b/jscomp/ml/includemod.ml @@ -31,9 +31,6 @@ type symptom = | Modtype_infos of Ident.t * modtype_declaration * modtype_declaration | Modtype_permutation | Interface_mismatch of string * string - | Class_type_declarations of - Ident.t * class_type_declaration * class_type_declaration * - Ctype.class_match_failure list | Unbound_modtype_path of Path.t | Unbound_module_path of Path.t | Invalid_module_alias of Path.t @@ -78,16 +75,6 @@ let extension_constructors ~loc env cxt subst id ext1 ext2 = then () else raise(Error[cxt, env, Extension_constructors(id, ext1, ext2)]) -(* Inclusion between class declarations *) - -let class_type_declarations ~loc ~old_env env cxt subst id decl1 decl2 = - let decl2 = Subst.cltype_declaration subst decl2 in - match Includeclass.class_type_declarations ~loc env decl1 decl2 with - [] -> () - | reason -> - raise(Error[cxt, old_env, - Class_type_declarations(id, decl1, decl2, reason)]) - (* Expand a module type identifier when possible *) @@ -123,7 +110,6 @@ type field_desc = | Field_typext of string | Field_module of string | Field_modtype of string - | Field_classtype of string let kind_of_field_desc = function | Field_value _ -> "value" @@ -131,7 +117,6 @@ let kind_of_field_desc = function | Field_typext _ -> "extension constructor" | Field_module _ -> "module" | Field_modtype _ -> "module type" - | Field_classtype _ -> "class type" let item_ident_name = function Sig_value(id, d) -> (id, d.val_loc, Field_value(Ident.name id)) @@ -140,13 +125,13 @@ let item_ident_name = function | Sig_module(id, d, _) -> (id, d.md_loc, Field_module(Ident.name id)) | Sig_modtype(id, d) -> (id, d.mtd_loc, Field_modtype(Ident.name id)) | Sig_class () -> assert false - | Sig_class_type(id, d, _) -> (id, d.clty_loc, Field_classtype(Ident.name id)) + | Sig_class_type () -> assert false let is_runtime_component = function | Sig_value(_,{val_kind = Val_prim _}) | Sig_type(_,_,_) | Sig_modtype(_,_) - | Sig_class_type(_,_,_) -> false + | Sig_class_type() -> false | Sig_value(_,_) | Sig_typext(_,_,_) | Sig_module(_,_,_) @@ -315,9 +300,9 @@ and signatures ~loc env cxt subst sig1 sig2 = | Sig_module (i,_,_) | Sig_typext (i,_,_) | Sig_modtype(i,_) - | Sig_class_type(i,_,_) | Sig_type(i,_,_) -> Ident.name i - | Sig_class () -> assert false in + | Sig_class () + | Sig_class_type () -> assert false in List.fold_right (fun item fields -> if is_runtime_component item then get_id item :: fields else fields) sig2 [] in @@ -379,7 +364,7 @@ and signatures ~loc env cxt subst sig1 sig2 = | Sig_modtype _ -> Subst.add_modtype id2 (Mty_ident (Pident id1)) subst | Sig_value _ | Sig_typext _ - | Sig_class _ | Sig_class_type _ -> + | Sig_class _ | Sig_class_type () -> subst in pair_components new_subst @@ -420,11 +405,9 @@ and signature_components ~loc old_env env cxt subst paired = | (Sig_modtype(id1, info1), Sig_modtype(_id2, info2), _pos) :: rem -> modtype_infos ~loc env cxt subst id1 info1 info2; comps_rec rem - | (Sig_class _, Sig_class _ , _) :: _ -> assert false - | (Sig_class_type(id1, info1, _), - Sig_class_type(_id2, info2, _), _pos) :: rem -> - class_type_declarations ~loc ~old_env env cxt subst id1 info1 info2; - comps_rec rem + | (Sig_class (), Sig_class () , _) :: _ -> assert false + | (Sig_class_type(), + Sig_class_type(), _pos) :: _ -> assert false | _ -> assert false @@ -583,13 +566,6 @@ let include_err ~env ppf = function | Interface_mismatch(impl_name, intf_name) -> fprintf ppf "@[The implementation %s@ does not match the interface %s:" impl_name intf_name - | Class_type_declarations(id, d1, d2, reason) -> - fprintf ppf - "@[Class type declarations do not match:@ \ - %a@;<1 -2>does not match@ %a@]@ %a" - (Printtyp.cltype_declaration id) d1 - (Printtyp.cltype_declaration id) d2 - Includeclass.report_error reason | Unbound_modtype_path path -> fprintf ppf "Unbound module type %a" Printtyp.path path | Unbound_module_path path -> diff --git a/jscomp/ml/includemod.mli b/jscomp/ml/includemod.mli index 731baf780e..bd3f37bc13 100644 --- a/jscomp/ml/includemod.mli +++ b/jscomp/ml/includemod.mli @@ -45,9 +45,6 @@ type symptom = | Modtype_infos of Ident.t * modtype_declaration * modtype_declaration | Modtype_permutation | Interface_mismatch of string * string - | Class_type_declarations of - Ident.t * class_type_declaration * class_type_declaration * - Ctype.class_match_failure list | Unbound_modtype_path of Path.t | Unbound_module_path of Path.t | Invalid_module_alias of Path.t diff --git a/jscomp/ml/mtype.ml b/jscomp/ml/mtype.ml index 74aaeddde7..5f6b798bf6 100644 --- a/jscomp/ml/mtype.ml +++ b/jscomp/ml/mtype.ml @@ -162,10 +162,8 @@ let nondep_supertype env mid mty = mtd_attributes=[]}) :: rem' | _ -> raise Not_found end - | Sig_class _ -> assert false - | Sig_class_type(id, d, rs) -> - Sig_class_type(id, Ctype.nondep_cltype_declaration env mid d, rs) - :: rem' + | Sig_class () -> assert false + | Sig_class_type () -> assert false and nondep_modtype_decl env mtd = {mtd with mtd_type = Misc.may_map (nondep_mty env Strict) mtd.mtd_type} diff --git a/jscomp/ml/parser.ml b/jscomp/ml/parser.ml index 31527ccc9c..44a14d728b 100644 --- a/jscomp/ml/parser.ml +++ b/jscomp/ml/parser.ml @@ -136,11 +136,9 @@ let mkmty ?attrs d = Mty.mk ~loc:(symbol_rloc()) ?attrs d let mksig d = Sig.mk ~loc:(symbol_rloc()) d let mkmod ?attrs d = Mod.mk ~loc:(symbol_rloc()) ?attrs d let mkstr d = Str.mk ~loc:(symbol_rloc()) d -let mkcty ?attrs d = Cty.mk ~loc:(symbol_rloc()) ?attrs d -let mkctf ?attrs ?docs d = - Ctf.mk ~loc:(symbol_rloc()) ?attrs ?docs d -let mkcf ?attrs ?docs d = - Cf.mk ~loc:(symbol_rloc()) ?attrs ?docs d +let mkcty ?attrs _d = let _ = attrs in assert false +let mkctf ?attrs ?docs _d = let _ = (attrs, docs) in assert false +let mkcf ?attrs ?docs _d = let _ = (attrs, docs) in assert false let mkrhs rhs pos = mkloc rhs (rhs_loc pos) @@ -321,8 +319,7 @@ let wrap_pat_attrs pat (ext, attrs) = let mkpat_attrs d attrs = wrap_pat_attrs (mkpat d) attrs -let wrap_class_type_attrs body attrs = - {body with pcty_attributes = attrs @ body.pcty_attributes} +let wrap_class_type_attrs _body _attrs = assert false let wrap_mod_attrs body attrs = {body with pmod_attributes = attrs @ body.pmod_attributes} let wrap_mty_attrs body attrs = @@ -346,8 +343,8 @@ let mksig_ext d ext = let text_str pos = Str.text (rhs_text pos) let text_sig pos = Sig.text (rhs_text pos) -let text_cstr pos = Cf.text (rhs_text pos) -let text_csig pos = Ctf.text (rhs_text pos) +let text_cstr _pos = assert false +let text_csig _pos = assert false let extra_text text pos items = @@ -357,8 +354,6 @@ let extra_text text pos items = let extra_str pos items = extra_text Str.text pos items let extra_sig pos items = extra_text Sig.text pos items -let extra_cstr pos items = extra_text Cf.text pos items -let extra_csig pos items = extra_text Ctf.text pos items let extra_rhs_core_type ct ~pos = let docs = rhs_info pos in @@ -6710,7 +6705,7 @@ let yyact = [| let _1 = (Parsing.peek_val __caml_parser_env 0 : 'class_type_declarations) in Obj.repr( # 697 "ml/parser.mly" - ( let (l, ext) = _1 in mkstr_ext (Pstr_class_type (List.rev l)) ext ) + ( let (_l, ext) = _1 in mkstr_ext (Pstr_class_type ()) ext ) # 6715 "ml/parser.ml" : 'structure_item)) ; (fun __caml_parser_env -> @@ -7014,7 +7009,7 @@ let yyact = [| let _1 = (Parsing.peek_val __caml_parser_env 0 : 'class_type_declarations) in Obj.repr( # 809 "ml/parser.mly" - ( let (l, ext) = _1 in mksig_ext (Psig_class_type (List.rev l)) ext ) + ( let (_l, ext) = _1 in mksig_ext (Psig_class_type ()) ext ) # 7019 "ml/parser.ml" : 'signature_item)) ; (fun __caml_parser_env -> @@ -7191,7 +7186,7 @@ let yyact = [| let _2 = (Parsing.peek_val __caml_parser_env 0 : 'class_fields) in Obj.repr( # 891 "ml/parser.mly" - ( Cstr.mk _1 (extra_cstr 2 (List.rev _2)) ) + ( assert false ) # 7196 "ml/parser.ml" : 'class_structure)) ; (fun __caml_parser_env -> @@ -7234,8 +7229,8 @@ let yyact = [| let _3 = (Parsing.peek_val __caml_parser_env 0 : 'post_item_attributes) in Obj.repr( # 909 "ml/parser.mly" - ( let v, attrs = _2 in - mkcf (Pcf_val v) ~attrs:(attrs@_3) ~docs:(symbol_docs ()) ) + ( let _v, attrs = _2 in + mkcf (assert false) ~attrs:(attrs@_3) ~docs:(symbol_docs ()) ) # 7240 "ml/parser.ml" : 'class_field)) ; (fun __caml_parser_env -> @@ -7243,8 +7238,8 @@ let yyact = [| let _3 = (Parsing.peek_val __caml_parser_env 0 : 'post_item_attributes) in Obj.repr( # 912 "ml/parser.mly" - ( let meth, attrs = _2 in - mkcf (Pcf_method meth) ~attrs:(attrs@_3) ~docs:(symbol_docs ()) ) + ( let _meth, attrs = _2 in + mkcf (assert false) ~attrs:(attrs@_3) ~docs:(symbol_docs ()) ) # 7249 "ml/parser.ml" : 'class_field)) ; (fun __caml_parser_env -> @@ -7253,7 +7248,7 @@ let yyact = [| let _4 = (Parsing.peek_val __caml_parser_env 0 : 'post_item_attributes) in Obj.repr( # 915 "ml/parser.mly" - ( mkcf (Pcf_constraint _3) ~attrs:(_2@_4) ~docs:(symbol_docs ()) ) + ( mkcf (assert false) ~attrs:(_2@_4) ~docs:(symbol_docs ()) ) # 7258 "ml/parser.ml" : 'class_field)) ; (fun __caml_parser_env -> @@ -7262,7 +7257,7 @@ let yyact = [| let _4 = (Parsing.peek_val __caml_parser_env 0 : 'post_item_attributes) in Obj.repr( # 917 "ml/parser.mly" - ( mkcf (Pcf_initializer _3) ~attrs:(_2@_4) ~docs:(symbol_docs ()) ) + ( mkcf (assert false) ~attrs:(_2@_4) ~docs:(symbol_docs ()) ) # 7267 "ml/parser.ml" : 'class_field)) ; (fun __caml_parser_env -> @@ -7270,7 +7265,7 @@ let yyact = [| let _2 = (Parsing.peek_val __caml_parser_env 0 : 'post_item_attributes) in Obj.repr( # 919 "ml/parser.mly" - ( mkcf (Pcf_extension _1) ~attrs:_2 ~docs:(symbol_docs ()) ) + ( mkcf (assert false) ~attrs:_2 ~docs:(symbol_docs ()) ) # 7275 "ml/parser.ml" : 'class_field)) ; (fun __caml_parser_env -> @@ -7278,7 +7273,7 @@ let yyact = [| Obj.repr( # 921 "ml/parser.mly" ( mark_symbol_docs (); - mkcf (Pcf_attribute _1) ) + mkcf (assert false) ) # 7283 "ml/parser.ml" : 'class_field)) ; (fun __caml_parser_env -> @@ -7289,7 +7284,7 @@ let yyact = [| Obj.repr( # 927 "ml/parser.mly" ( if _1 = Override then syntax_error (); - (mkloc _5 (rhs_loc 5), Mutable, Cfk_virtual _7), _2 ) + (mkloc _5 (rhs_loc 5), Mutable, assert false), _2 ) # 7294 "ml/parser.ml" : 'value)) ; (fun __caml_parser_env -> @@ -7301,7 +7296,7 @@ let yyact = [| Obj.repr( # 930 "ml/parser.mly" ( if _1 = Override then syntax_error (); - (mkrhs _5 5, _4, Cfk_virtual _7), _2 ) + (mkrhs _5 5, _4, assert false), _2 ) # 7306 "ml/parser.ml" : 'value)) ; (fun __caml_parser_env -> @@ -7312,7 +7307,7 @@ let yyact = [| let _6 = (Parsing.peek_val __caml_parser_env 0 : 'seq_expr) in Obj.repr( # 933 "ml/parser.mly" - ( (mkrhs _4 4, _3, Cfk_concrete (_1, _6)), _2 ) + ( (mkrhs _4 4, _3, assert false), _2 ) # 7317 "ml/parser.ml" : 'value)) ; (fun __caml_parser_env -> @@ -7325,8 +7320,8 @@ let yyact = [| Obj.repr( # 935 "ml/parser.mly" ( - let e = mkexp_constraint _7 _5 in - (mkrhs _4 4, _3, Cfk_concrete (_1, e)), _2 + let _e = mkexp_constraint _7 _5 in + (mkrhs _4 4, _3, assert false), _2 ) # 7332 "ml/parser.ml" : 'value)) @@ -7338,7 +7333,7 @@ let yyact = [| Obj.repr( # 943 "ml/parser.mly" ( if _1 = Override then syntax_error (); - (mkloc _5 (rhs_loc 5), Private, Cfk_virtual _7), _2 ) + (mkloc _5 (rhs_loc 5), Private, assert false), _2 ) # 7343 "ml/parser.ml" : 'method_)) ; (fun __caml_parser_env -> @@ -7350,7 +7345,7 @@ let yyact = [| Obj.repr( # 946 "ml/parser.mly" ( if _1 = Override then syntax_error (); - (mkloc _5 (rhs_loc 5), _4, Cfk_virtual _7), _2 ) + (mkloc _5 (rhs_loc 5), _4, assert false), _2 ) # 7355 "ml/parser.ml" : 'method_)) ; (fun __caml_parser_env -> @@ -7362,7 +7357,7 @@ let yyact = [| Obj.repr( # 949 "ml/parser.mly" ( (mkloc _4 (rhs_loc 4), _3, - Cfk_concrete (_1, ghexp(Pexp_poly (_5, None)))), _2 ) + assert false), _2 ) # 7367 "ml/parser.ml" : 'method_)) ; (fun __caml_parser_env -> @@ -7375,7 +7370,7 @@ let yyact = [| Obj.repr( # 952 "ml/parser.mly" ( (mkloc _4 (rhs_loc 4), _3, - Cfk_concrete (_1, ghexp(Pexp_poly(_8, Some _6)))), _2 ) + assert false), _2 ) # 7380 "ml/parser.ml" : 'method_)) ; (fun __caml_parser_env -> @@ -7388,9 +7383,9 @@ let yyact = [| let _11 = (Parsing.peek_val __caml_parser_env 0 : 'seq_expr) in Obj.repr( # 956 "ml/parser.mly" - ( let exp, poly = wrap_type_annotation _7 _9 _11 in + ( let _exp, _poly = wrap_type_annotation _7 _9 _11 in (mkloc _4 (rhs_loc 4), _3, - Cfk_concrete (_1, ghexp(Pexp_poly(exp, Some poly)))), _2 ) + assert false), _2 ) # 7395 "ml/parser.ml" : 'method_)) ; (fun __caml_parser_env -> @@ -7398,14 +7393,14 @@ let yyact = [| let _4 = (Parsing.peek_val __caml_parser_env 0 : 'clty_longident) in Obj.repr( # 965 "ml/parser.mly" - ( mkcty(Pcty_constr (mkloc _4 (rhs_loc 4), List.rev _2)) ) + ( mkcty(assert false) ) # 7403 "ml/parser.ml" : 'class_signature)) ; (fun __caml_parser_env -> let _1 = (Parsing.peek_val __caml_parser_env 0 : 'clty_longident) in Obj.repr( # 967 "ml/parser.mly" - ( mkcty(Pcty_constr (mkrhs _1 1, [])) ) + ( mkcty(assert false) ) # 7410 "ml/parser.ml" : 'class_signature)) ; (fun __caml_parser_env -> @@ -7413,7 +7408,7 @@ let yyact = [| let _3 = (Parsing.peek_val __caml_parser_env 1 : 'class_sig_body) in Obj.repr( # 969 "ml/parser.mly" - ( mkcty ~attrs:_2 (Pcty_signature _3) ) + ( mkcty ~attrs:_2 (assert false) ) # 7418 "ml/parser.ml" : 'class_signature)) ; (fun __caml_parser_env -> @@ -7429,14 +7424,14 @@ let yyact = [| let _2 = (Parsing.peek_val __caml_parser_env 0 : 'attribute) in Obj.repr( # 973 "ml/parser.mly" - ( Cty.attr _1 _2 ) + ( assert false ) # 7434 "ml/parser.ml" : 'class_signature)) ; (fun __caml_parser_env -> let _1 = (Parsing.peek_val __caml_parser_env 0 : 'extension) in Obj.repr( # 975 "ml/parser.mly" - ( mkcty(Pcty_extension _1) ) + ( mkcty(assert false) ) # 7441 "ml/parser.ml" : 'class_signature)) ; (fun __caml_parser_env -> @@ -7446,7 +7441,7 @@ let yyact = [| let _7 = (Parsing.peek_val __caml_parser_env 0 : 'class_signature) in Obj.repr( # 977 "ml/parser.mly" - ( wrap_class_type_attrs (mkcty(Pcty_open(_3, mkrhs _5 5, _7))) _4 ) + ( wrap_class_type_attrs (mkcty(assert false)) _4 ) # 7451 "ml/parser.ml" : 'class_signature)) ; (fun __caml_parser_env -> @@ -7454,7 +7449,7 @@ let yyact = [| let _2 = (Parsing.peek_val __caml_parser_env 0 : 'class_sig_fields) in Obj.repr( # 981 "ml/parser.mly" - ( Csig.mk _1 (extra_csig 2 (List.rev _2)) ) + ( assert false ) # 7459 "ml/parser.ml" : 'class_sig_body)) ; (fun __caml_parser_env -> @@ -7490,7 +7485,7 @@ let yyact = [| let _4 = (Parsing.peek_val __caml_parser_env 0 : 'post_item_attributes) in Obj.repr( # 995 "ml/parser.mly" - ( mkctf (Pctf_inherit _3) ~attrs:(_2@_4) ~docs:(symbol_docs ()) ) + ( mkctf (assert false) ~attrs:(_2@_4) ~docs:(symbol_docs ()) ) # 7495 "ml/parser.ml" : 'class_sig_field)) ; (fun __caml_parser_env -> @@ -7499,7 +7494,7 @@ let yyact = [| let _4 = (Parsing.peek_val __caml_parser_env 0 : 'post_item_attributes) in Obj.repr( # 997 "ml/parser.mly" - ( mkctf (Pctf_val _3) ~attrs:(_2@_4) ~docs:(symbol_docs ()) ) + ( mkctf (assert false) ~attrs:(_2@_4) ~docs:(symbol_docs ()) ) # 7504 "ml/parser.ml" : 'class_sig_field)) ; (fun __caml_parser_env -> @@ -7511,8 +7506,8 @@ let yyact = [| Obj.repr( # 1000 "ml/parser.mly" ( - let (p, v) = _3 in - mkctf (Pctf_method (mkrhs _4 4, p, v, _6)) ~attrs:(_2@_7) ~docs:(symbol_docs ()) + let (_p, _v) = _3 in + mkctf (assert false) ~attrs:(_2@_7) ~docs:(symbol_docs ()) ) # 7518 "ml/parser.ml" : 'class_sig_field)) @@ -7522,7 +7517,7 @@ let yyact = [| let _4 = (Parsing.peek_val __caml_parser_env 0 : 'post_item_attributes) in Obj.repr( # 1005 "ml/parser.mly" - ( mkctf (Pctf_constraint _3) ~attrs:(_2@_4) ~docs:(symbol_docs ()) ) + ( mkctf (assert false) ~attrs:(_2@_4) ~docs:(symbol_docs ()) ) # 7527 "ml/parser.ml" : 'class_sig_field)) ; (fun __caml_parser_env -> @@ -7530,7 +7525,7 @@ let yyact = [| let _2 = (Parsing.peek_val __caml_parser_env 0 : 'post_item_attributes) in Obj.repr( # 1007 "ml/parser.mly" - ( mkctf (Pctf_extension _1) ~attrs:_2 ~docs:(symbol_docs ()) ) + ( mkctf (assert false) ~attrs:_2 ~docs:(symbol_docs ()) ) # 7535 "ml/parser.ml" : 'class_sig_field)) ; (fun __caml_parser_env -> @@ -7538,7 +7533,7 @@ let yyact = [| Obj.repr( # 1009 "ml/parser.mly" ( mark_symbol_docs (); - mkctf(Pctf_attribute _1) ) + mkctf(assert false) ) # 7543 "ml/parser.ml" : 'class_sig_field)) ; (fun __caml_parser_env -> @@ -7607,9 +7602,8 @@ let yyact = [| let _9 = (Parsing.peek_val __caml_parser_env 0 : 'post_item_attributes) in Obj.repr( # 1035 "ml/parser.mly" - ( let (ext, attrs) = _3 in - Ci.mk (mkrhs _6 6) _8 ~virt:_4 ~params:_5 ~attrs:(attrs@_9) - ~loc:(symbol_rloc ()) ~docs:(symbol_docs ()) + ( let (ext, _attrs) = _3 in + assert false , ext) # 7615 "ml/parser.ml" : 'class_type_declaration)) @@ -7622,9 +7616,7 @@ let yyact = [| let _8 = (Parsing.peek_val __caml_parser_env 0 : 'post_item_attributes) in Obj.repr( # 1043 "ml/parser.mly" - ( Ci.mk (mkrhs _5 5) _7 ~virt:_3 ~params:_4 - ~attrs:(_2@_8) ~loc:(symbol_rloc ()) - ~text:(symbol_text ()) ~docs:(symbol_docs ()) ) + ( assert false ) # 7629 "ml/parser.ml" : 'and_class_type_declaration)) ; (fun __caml_parser_env -> @@ -8271,7 +8263,7 @@ let yyact = [| let _3 = (Parsing.peek_val __caml_parser_env 1 : 'class_structure) in Obj.repr( # 1220 "ml/parser.mly" - ( mkexp_attrs (Pexp_object _3) _2 ) + ( mkexp_attrs (Pexp_object ()) _2 ) # 8276 "ml/parser.ml" : 'expr)) ; (fun __caml_parser_env -> @@ -10687,7 +10679,7 @@ let yyact = [| let _2 = (Parsing.peek_val __caml_parser_env 0 : 'class_longident) in Obj.repr( # 2049 "ml/parser.mly" - ( mktyp(Ptyp_class(mkrhs _2 2, [])) ) + ( mktyp(Ptyp_class()) ) # 10692 "ml/parser.ml" : 'simple_core_type2)) ; (fun __caml_parser_env -> @@ -10695,7 +10687,7 @@ let yyact = [| let _3 = (Parsing.peek_val __caml_parser_env 0 : 'class_longident) in Obj.repr( # 2051 "ml/parser.mly" - ( mktyp(Ptyp_class(mkrhs _3 3, [_1])) ) + ( mktyp(Ptyp_class()) ) # 10700 "ml/parser.ml" : 'simple_core_type2)) ; (fun __caml_parser_env -> @@ -10703,7 +10695,7 @@ let yyact = [| let _5 = (Parsing.peek_val __caml_parser_env 0 : 'class_longident) in Obj.repr( # 2053 "ml/parser.mly" - ( mktyp(Ptyp_class(mkrhs _5 5, List.rev _2)) ) + ( mktyp(Ptyp_class()) ) # 10708 "ml/parser.ml" : 'simple_core_type2)) ; (fun __caml_parser_env -> diff --git a/jscomp/ml/parser.mly b/jscomp/ml/parser.mly index fe4ace9a4e..515605979f 100644 --- a/jscomp/ml/parser.mly +++ b/jscomp/ml/parser.mly @@ -30,11 +30,9 @@ let mkmty ?attrs d = Mty.mk ~loc:(symbol_rloc()) ?attrs d let mksig d = Sig.mk ~loc:(symbol_rloc()) d let mkmod ?attrs d = Mod.mk ~loc:(symbol_rloc()) ?attrs d let mkstr d = Str.mk ~loc:(symbol_rloc()) d -let mkcty ?attrs d = Cty.mk ~loc:(symbol_rloc()) ?attrs d -let mkctf ?attrs ?docs d = - Ctf.mk ~loc:(symbol_rloc()) ?attrs ?docs d -let mkcf ?attrs ?docs d = - Cf.mk ~loc:(symbol_rloc()) ?attrs ?docs d +let mkcty ?attrs _d = let _ = attrs in assert false +let mkctf ?attrs ?docs d = let _ = (attrs, docs) in assert false +let mkcf ?attrs ?docs d = assert false let mkrhs rhs pos = mkloc rhs (rhs_loc pos) @@ -215,8 +213,7 @@ let wrap_pat_attrs pat (ext, attrs) = let mkpat_attrs d attrs = wrap_pat_attrs (mkpat d) attrs -let wrap_class_type_attrs body attrs = - {body with pcty_attributes = attrs @ body.pcty_attributes} +let wrap_class_type_attrs _body _attrs = assert false let wrap_mod_attrs body attrs = {body with pmod_attributes = attrs @ body.pmod_attributes} let wrap_mty_attrs body attrs = @@ -240,8 +237,8 @@ let mksig_ext d ext = let text_str pos = Str.text (rhs_text pos) let text_sig pos = Sig.text (rhs_text pos) -let text_cstr pos = Cf.text (rhs_text pos) -let text_csig pos = Ctf.text (rhs_text pos) +let text_cstr pos = assert false +let text_csig _pos = assert false let extra_text text pos items = @@ -251,8 +248,6 @@ let extra_text text pos items = let extra_str pos items = extra_text Str.text pos items let extra_sig pos items = extra_text Sig.text pos items -let extra_cstr pos items = extra_text Cf.text pos items -let extra_csig pos items = extra_text Ctf.text pos items let extra_rhs_core_type ct ~pos = let docs = rhs_info pos in @@ -694,7 +689,7 @@ structure_item: | open_statement { let (body, ext) = $1 in mkstr_ext (Pstr_open body) ext } | class_type_declarations - { let (l, ext) = $1 in mkstr_ext (Pstr_class_type (List.rev l)) ext } + { let (_l, ext) = $1 in mkstr_ext (Pstr_class_type ()) ext } | str_include_statement { let (body, ext) = $1 in mkstr_ext (Pstr_include body) ext } | item_extension post_item_attributes @@ -806,7 +801,7 @@ signature_item: | sig_include_statement { let (body, ext) = $1 in mksig_ext (Psig_include body) ext } | class_type_declarations - { let (l, ext) = $1 in mksig_ext (Psig_class_type (List.rev l)) ext } + { let (l, ext) = $1 in mksig_ext (Psig_class_type ()) ext } | item_extension post_item_attributes { mksig(Psig_extension ($1, (add_docs_attrs (symbol_docs ()) $2))) } | floating_attribute @@ -888,7 +883,7 @@ class_type_parameters: ; class_structure: | class_self_pattern class_fields - { Cstr.mk $1 (extra_cstr 2 (List.rev $2)) } + { assert false } ; class_self_pattern: LPAREN pattern RPAREN @@ -970,7 +965,7 @@ class_signature: | OBJECT attributes class_sig_body error { unclosed "object" 1 "end" 4 } | class_signature attribute - { Cty.attr $1 $2 } + { assert false } | extension { mkcty(Pcty_extension $1) } | LET OPEN override_flag attributes mod_longident IN class_signature @@ -978,7 +973,7 @@ class_signature: ; class_sig_body: class_self_type class_sig_fields - { Csig.mk $1 (extra_csig 2 (List.rev $2)) } + { assert false } ; class_self_type: LPAREN core_type RPAREN @@ -1033,16 +1028,13 @@ class_type_declaration: CLASS TYPE ext_attributes virtual_flag class_type_parameters LIDENT EQUAL class_signature post_item_attributes { let (ext, attrs) = $3 in - Ci.mk (mkrhs $6 6) $8 ~virt:$4 ~params:$5 ~attrs:(attrs@$9) - ~loc:(symbol_rloc ()) ~docs:(symbol_docs ()) + assert false , ext} ; and_class_type_declaration: AND attributes virtual_flag class_type_parameters LIDENT EQUAL class_signature post_item_attributes - { Ci.mk (mkrhs $5 5) $7 ~virt:$3 ~params:$4 - ~attrs:($2@$8) ~loc:(symbol_rloc ()) - ~text:(symbol_text ()) ~docs:(symbol_docs ()) } + { assert false } ; /* Core expressions */ @@ -1217,7 +1209,7 @@ expr: | LAZY ext_attributes simple_expr %prec below_HASH { mkexp_attrs (Pexp_lazy $3) $2 } | OBJECT ext_attributes class_structure END - { mkexp_attrs (Pexp_object $3) $2 } + { mkexp_attrs (Pexp_object ()) $2 } | OBJECT ext_attributes class_structure error { unclosed "object" 1 "end" 4 } | expr attribute @@ -2046,11 +2038,11 @@ simple_core_type2: | LESS GREATER { mktyp(Ptyp_object ([], Closed)) } | HASH class_longident - { mktyp(Ptyp_class(mkrhs $2 2, [])) } + { mktyp(Ptyp_class()) } | simple_core_type2 HASH class_longident - { mktyp(Ptyp_class(mkrhs $3 3, [$1])) } + { mktyp(Ptyp_class()) } | LPAREN core_type_comma_list RPAREN HASH class_longident - { mktyp(Ptyp_class(mkrhs $5 5, List.rev $2)) } + { mktyp(Ptyp_class()) } | LBRACKET tag_field RBRACKET { mktyp(Ptyp_variant([$2], Closed, None)) } /* PR#3835: this is not LR(1), would need lookahead=2 diff --git a/jscomp/ml/parsetree.ml b/jscomp/ml/parsetree.ml index 159a832aa9..726273d8a8 100644 --- a/jscomp/ml/parsetree.ml +++ b/jscomp/ml/parsetree.ml @@ -97,11 +97,8 @@ and core_type_desc = (* < l1:T1; ...; ln:Tn > (flag = Closed) < l1:T1; ...; ln:Tn; .. > (flag = Open) *) - | Ptyp_class of Longident.t loc * core_type list - (* #tconstr - T #tconstr - (T1, ..., Tn) #tconstr - *) + | Ptyp_class of unit + (* dummy AST node *) | Ptyp_alias of core_type * string (* T as 'a *) | Ptyp_variant of row_field list * closed_flag * label list option @@ -337,8 +334,8 @@ and expression_desc = Can only be used as the expression under Cfk_concrete for methods (not values). *) - | Pexp_object of class_structure - (* object ... end *) + | Pexp_object of unit + (* dummy AST node *) | Pexp_newtype of string loc * expression (* fun (type t) -> E *) | Pexp_pack of module_expr @@ -481,171 +478,6 @@ and extension_constructor_kind = | C = D *) -(** {1 Class language} *) - -(* Type expressions for the class language *) - -and class_type = - { - pcty_desc: class_type_desc; - pcty_loc: Location.t; - pcty_attributes: attributes; (* ... [@id1] [@id2] *) - } - -and class_type_desc = - | Pcty_constr of Longident.t loc * core_type list - (* c - ['a1, ..., 'an] c *) - | Pcty_signature of class_signature - (* object ... end *) - | Pcty_arrow of arg_label * core_type * class_type - (* T -> CT Simple - ~l:T -> CT Labelled l - ?l:T -> CT Optional l - *) - | Pcty_extension of extension - (* [%id] *) - | Pcty_open of override_flag * Longident.t loc * class_type - (* let open M in CT *) - -and class_signature = - { - pcsig_self: core_type; - pcsig_fields: class_type_field list; - } -(* object('selfpat) ... end - object ... end (self = Ptyp_any) - *) - -and class_type_field = - { - pctf_desc: class_type_field_desc; - pctf_loc: Location.t; - pctf_attributes: attributes; (* ... [@@id1] [@@id2] *) - } - -and class_type_field_desc = - | Pctf_inherit of class_type - (* inherit CT *) - | Pctf_val of (label loc * mutable_flag * virtual_flag * core_type) - (* val x: T *) - | Pctf_method of (label loc * private_flag * virtual_flag * core_type) - (* method x: T - - Note: T can be a Ptyp_poly. - *) - | Pctf_constraint of (core_type * core_type) - (* constraint T1 = T2 *) - | Pctf_attribute of attribute - (* [@@@id] *) - | Pctf_extension of extension - (* [%%id] *) - -and 'a class_infos = - { - pci_virt: virtual_flag; - pci_params: (core_type * variance) list; - pci_name: string loc; - pci_expr: 'a; - pci_loc: Location.t; - pci_attributes: attributes; (* ... [@@id1] [@@id2] *) - } -(* class c = ... - class ['a1,...,'an] c = ... - class virtual c = ... - - Also used for "class type" declaration. -*) - - - -and class_type_declaration = class_type class_infos - -(* Value expressions for the class language *) - -and class_expr = - { - pcl_desc: class_expr_desc; - pcl_loc: Location.t; - pcl_attributes: attributes; (* ... [@id1] [@id2] *) - } - -and class_expr_desc = - | Pcl_constr of Longident.t loc * core_type list - (* c - ['a1, ..., 'an] c *) - | Pcl_structure of class_structure - (* object ... end *) - | Pcl_fun of arg_label * expression option * pattern * class_expr - (* fun P -> CE (Simple, None) - fun ~l:P -> CE (Labelled l, None) - fun ?l:P -> CE (Optional l, None) - fun ?l:(P = E0) -> CE (Optional l, Some E0) - *) - | Pcl_apply of class_expr * (arg_label * expression) list - (* CE ~l1:E1 ... ~ln:En - li can be empty (non labeled argument) or start with '?' - (optional argument). - - Invariant: n > 0 - *) - | Pcl_let of rec_flag * value_binding list * class_expr - (* let P1 = E1 and ... and Pn = EN in CE (flag = Nonrecursive) - let rec P1 = E1 and ... and Pn = EN in CE (flag = Recursive) - *) - | Pcl_constraint of class_expr * class_type - (* (CE : CT) *) - | Pcl_extension of extension - (* [%id] *) - | Pcl_open of override_flag * Longident.t loc * class_expr - (* let open M in CE *) - - -and class_structure = - { - pcstr_self: pattern; - pcstr_fields: class_field list; - } -(* object(selfpat) ... end - object ... end (self = Ppat_any) - *) - -and class_field = - { - pcf_desc: class_field_desc; - pcf_loc: Location.t; - pcf_attributes: attributes; (* ... [@@id1] [@@id2] *) - } - -and class_field_desc = - | Pcf_inherit of unit - (* inherit CE - inherit CE as x - inherit! CE - inherit! CE as x - *) - | Pcf_val of (label loc * mutable_flag * class_field_kind) - (* val x = E - val virtual x: T - *) - | Pcf_method of (label loc * private_flag * class_field_kind) - (* method x = E (E can be a Pexp_poly) - method virtual x: T (T can be a Ptyp_poly) - *) - | Pcf_constraint of (core_type * core_type) - (* constraint T1 = T2 *) - | Pcf_initializer of expression - (* initializer E *) - | Pcf_attribute of attribute - (* [@@@id] *) - | Pcf_extension of extension - (* [%%id] *) - -and class_field_kind = - | Cfk_virtual of core_type - | Cfk_concrete of override_flag * expression - - (** {1 Module language} *) @@ -706,9 +538,9 @@ and signature_item_desc = | Psig_include of include_description (* include MT *) | Psig_class of unit - (* class c1 : ... and ... and cn : ... *) - | Psig_class_type of class_type_declaration list - (* class type ct1 = ... and ... and ctn = ... *) + (* Dummy AST node *) + | Psig_class_type of unit + (* Dummy AST node *) | Psig_attribute of attribute (* [@@@id] *) | Psig_extension of extension * attributes @@ -832,8 +664,8 @@ and structure_item_desc = (* open X *) | Pstr_class of unit (* Dummy AST node *) - | Pstr_class_type of class_type_declaration list - (* class type ct1 = ... and ... and ctn = ... *) + | Pstr_class_type of unit + (* Dummy AST node *) | Pstr_include of include_declaration (* include ME *) | Pstr_attribute of attribute diff --git a/jscomp/ml/pprintast.ml b/jscomp/ml/pprintast.ml index b531404ef6..3adcf44f59 100644 --- a/jscomp/ml/pprintast.ml +++ b/jscomp/ml/pprintast.ml @@ -208,9 +208,6 @@ let constant f = function let mutable_flag f = function | Immutable -> () | Mutable -> pp f "mutable@;" -let virtual_flag f = function - | Concrete -> () - | Virtual -> pp f "virtual@;" (* trailing space added *) let rec_flag f rf = @@ -233,14 +230,8 @@ let tyvar f str = pp f "'%s" str let tyvar_loc f str = pp f "'%s" str.txt let string_quot f x = pp f "`%s" x -(* c ['a,'b] *) -let rec class_params_def ctxt f = function - | [] -> () - | l -> - pp f "[%a] " (* space *) - (list (type_param ctxt) ~sep:",") l -and type_with_label ctxt f (label, c) = +let rec type_with_label ctxt f (label, c) = match label with | Nolabel -> core_type1 ctxt f c (* otherwise parenthesize *) | Labelled s -> pp f "%s:%a" s (core_type1 ctxt) c @@ -330,10 +321,7 @@ and core_type1 ctxt f x = in pp f "@[<@ %a%a@ > @]" (list core_field_type ~sep:";") l field_var o (* Cf #7200 *) - | Ptyp_class (li, l) -> (*FIXME*) - pp f "@[%a#%a@]" - (list (core_type ctxt) ~sep:"," ~first:"(" ~last:")") l - longident_loc li + | Ptyp_class () -> () | Ptyp_package (lid, cstrs) -> let aux f (s, ct) = pp f "type %a@ =@ %a" longident_loc s (core_type ctxt) ct in @@ -680,7 +668,7 @@ and expression ctxt f x = and expression1 ctxt f x = if x.pexp_attributes <> [] then expression ctxt f x else match x.pexp_desc with - | Pexp_object cs -> pp f "%a" (class_structure ctxt) cs + | Pexp_object () -> assert false | _ -> expression2 ctxt f x (* used in [Pexp_apply] *) @@ -797,138 +785,6 @@ and item_extension ctxt f (s, e) = and exception_declaration ctxt f ext = pp f "@[exception@ %a@]" (extension_constructor ctxt) ext -and class_signature ctxt f { pcsig_self = ct; pcsig_fields = l ;_} = - let class_type_field f x = - match x.pctf_desc with - | Pctf_inherit (ct) -> - pp f "@[<2>inherit@ %a@]%a" (class_type ctxt) ct - (item_attributes ctxt) x.pctf_attributes - | Pctf_val (s, mf, vf, ct) -> - pp f "@[<2>val @ %a%a%s@ :@ %a@]%a" - mutable_flag mf virtual_flag vf s.txt (core_type ctxt) ct - (item_attributes ctxt) x.pctf_attributes - | Pctf_method (s, pf, vf, ct) -> - pp f "@[<2>method %a %a%s :@;%a@]%a" - private_flag pf virtual_flag vf s.txt (core_type ctxt) ct - (item_attributes ctxt) x.pctf_attributes - | Pctf_constraint (ct1, ct2) -> - pp f "@[<2>constraint@ %a@ =@ %a@]%a" - (core_type ctxt) ct1 (core_type ctxt) ct2 - (item_attributes ctxt) x.pctf_attributes - | Pctf_attribute a -> floating_attribute ctxt f a - | Pctf_extension e -> - item_extension ctxt f e; - item_attributes ctxt f x.pctf_attributes - in - pp f "@[@[object@[<1>%a@]@ %a@]@ end@]" - (fun f -> function - {ptyp_desc=Ptyp_any; ptyp_attributes=[]; _} -> () - | ct -> pp f " (%a)" (core_type ctxt) ct) ct - (list class_type_field ~sep:"@;") l - -(* call [class_signature] called by [class_signature] *) -and class_type ctxt f x = - match x.pcty_desc with - | Pcty_signature cs -> - class_signature ctxt f cs; - attributes ctxt f x.pcty_attributes - | Pcty_constr (li, l) -> - pp f "%a%a%a" - (fun f l -> match l with - | [] -> () - | _ -> pp f "[%a]@ " (list (core_type ctxt) ~sep:"," ) l) l - longident_loc li - (attributes ctxt) x.pcty_attributes - | Pcty_arrow (l, co, cl) -> - pp f "@[<2>%a@;->@;%a@]" (* FIXME remove parens later *) - (type_with_label ctxt) (l,co) - (class_type ctxt) cl - | Pcty_extension e -> - extension ctxt f e; - attributes ctxt f x.pcty_attributes - | Pcty_open (ovf, lid, e) -> - pp f "@[<2>let open%s %a in@;%a@]" (override ovf) longident_loc lid - (class_type ctxt) e - -(* [class type a = object end] *) -and class_type_declaration_list ctxt f l = - let class_type_declaration kwd f x = - let { pci_params=ls; pci_name={ txt; _ }; _ } = x in - pp f "@[<2>%s %a%a%s@ =@ %a@]%a" kwd - virtual_flag x.pci_virt - (class_params_def ctxt) ls txt - (class_type ctxt) x.pci_expr - (item_attributes ctxt) x.pci_attributes - in - match l with - | [] -> () - | [x] -> class_type_declaration "class type" f x - | x :: xs -> - pp f "@[%a@,%a@]" - (class_type_declaration "class type") x - (list ~sep:"@," (class_type_declaration "and")) xs - -and class_field ctxt f x = - match x.pcf_desc with - | Pcf_inherit () -> () - | Pcf_val (s, mf, Cfk_concrete (ovf, e)) -> - pp f "@[<2>val%s %a%s =@;%a@]%a" (override ovf) - mutable_flag mf s.txt - (expression ctxt) e - (item_attributes ctxt) x.pcf_attributes - | Pcf_method (s, pf, Cfk_virtual ct) -> - pp f "@[<2>method virtual %a %s :@;%a@]%a" - private_flag pf s.txt - (core_type ctxt) ct - (item_attributes ctxt) x.pcf_attributes - | Pcf_val (s, mf, Cfk_virtual ct) -> - pp f "@[<2>val virtual %a%s :@ %a@]%a" - mutable_flag mf s.txt - (core_type ctxt) ct - (item_attributes ctxt) x.pcf_attributes - | Pcf_method (s, pf, Cfk_concrete (ovf, e)) -> - let bind e = - binding ctxt f - {pvb_pat= - {ppat_desc=Ppat_var s;ppat_loc=Location.none;ppat_attributes=[]}; - pvb_expr=e; - pvb_attributes=[]; - pvb_loc=Location.none; - } - in - pp f "@[<2>method%s %a%a@]%a" - (override ovf) - private_flag pf - (fun f -> function - | {pexp_desc=Pexp_poly (e, Some ct); pexp_attributes=[]; _} -> - pp f "%s :@;%a=@;%a" - s.txt (core_type ctxt) ct (expression ctxt) e - | {pexp_desc=Pexp_poly (e, None); pexp_attributes=[]; _} -> - bind e - | _ -> bind e) e - (item_attributes ctxt) x.pcf_attributes - | Pcf_constraint (ct1, ct2) -> - pp f "@[<2>constraint %a =@;%a@]%a" - (core_type ctxt) ct1 - (core_type ctxt) ct2 - (item_attributes ctxt) x.pcf_attributes - | Pcf_initializer (e) -> - pp f "@[<2>initializer@ %a@]%a" - (expression ctxt) e - (item_attributes ctxt) x.pcf_attributes - | Pcf_attribute a -> floating_attribute ctxt f a - | Pcf_extension e -> - item_extension ctxt f e; - item_attributes ctxt f x.pcf_attributes - -and class_structure ctxt f { pcstr_self = p; pcstr_fields = l } = - pp f "@[@[object%a@;%a@]@;end@]" - (fun f p -> match p.ppat_desc with - | Ppat_any -> () - | Ppat_constraint _ -> pp f " %a" (pattern ctxt) p - | _ -> pp f " (%a)" (pattern ctxt) p) p - (list (class_field ctxt)) l - and module_type ctxt f x = if x.pmty_attributes <> [] then begin pp f "((%a)%a)" (module_type ctxt) {x with pmty_attributes=[]} @@ -1023,7 +879,7 @@ and signature_item ctxt f x : unit = pp f "@ =@ %a" (module_type ctxt) mt ) md (item_attributes ctxt) attrs - | Psig_class_type (l) -> class_type_declaration_list ctxt f l + | Psig_class_type () -> () | Psig_recmodule decls -> let rec string_x_module_type_list f ?(first=true) l = match l with @@ -1222,7 +1078,7 @@ and structure_item ctxt f x = ) md (item_attributes ctxt) attrs | Pstr_class () -> () - | Pstr_class_type l -> class_type_declaration_list ctxt f l + | Pstr_class_type () -> () | Pstr_primitive vd -> pp f "@[external@ %a@ :@ %a@]%a" protect_ident vd.pval_name.txt diff --git a/jscomp/ml/printast.ml b/jscomp/ml/printast.ml index eee7a90517..04d7d96b86 100644 --- a/jscomp/ml/printast.ml +++ b/jscomp/ml/printast.ml @@ -73,12 +73,6 @@ let fmt_mutable_flag f x = | Mutable -> fprintf f "Mutable"; ;; -let fmt_virtual_flag f x = - match x with - | Virtual -> fprintf f "Virtual"; - | Concrete -> fprintf f "Concrete"; -;; - let fmt_override_flag f x = match x with | Override -> fprintf f "Override"; @@ -174,9 +168,7 @@ let rec core_type i ppf x = line i ppf "Oinherit\n"; core_type (i + 1) ppf ct ) l - | Ptyp_class (li, l) -> - line i ppf "Ptyp_class %a\n" fmt_longident_loc li; - list i core_type ppf l + | Ptyp_class () -> () | Ptyp_alias (ct, s) -> line i ppf "Ptyp_alias \"%s\"\n" s; core_type i ppf ct; @@ -362,9 +354,7 @@ and expression i ppf x = line i ppf "Pexp_poly\n"; expression i ppf e; option i core_type ppf cto; - | Pexp_object s -> - line i ppf "Pexp_object\n"; - class_structure i ppf s + | Pexp_object () -> () | Pexp_newtype (s, e) -> line i ppf "Pexp_newtype \"%s\"\n" s.txt; expression i ppf e @@ -467,114 +457,6 @@ and extension_constructor_kind i ppf x = line i ppf "Pext_rebind\n"; line (i+1) ppf "%a\n" fmt_longident_loc li; -and class_type i ppf x = - line i ppf "class_type %a\n" fmt_location x.pcty_loc; - attributes i ppf x.pcty_attributes; - let i = i+1 in - match x.pcty_desc with - | Pcty_constr (li, l) -> - line i ppf "Pcty_constr %a\n" fmt_longident_loc li; - list i core_type ppf l; - | Pcty_signature (cs) -> - line i ppf "Pcty_signature\n"; - class_signature i ppf cs; - | Pcty_arrow (l, co, cl) -> - line i ppf "Pcty_arrow\n"; - arg_label i ppf l; - core_type i ppf co; - class_type i ppf cl; - | Pcty_extension (s, arg) -> - line i ppf "Pcty_extension \"%s\"\n" s.txt; - payload i ppf arg - | Pcty_open (ovf, m, e) -> - line i ppf "Pcty_open %a \"%a\"\n" fmt_override_flag ovf - fmt_longident_loc m; - class_type i ppf e - -and class_signature i ppf cs = - line i ppf "class_signature\n"; - core_type (i+1) ppf cs.pcsig_self; - list (i+1) class_type_field ppf cs.pcsig_fields; - -and class_type_field i ppf x = - line i ppf "class_type_field %a\n" fmt_location x.pctf_loc; - let i = i+1 in - attributes i ppf x.pctf_attributes; - match x.pctf_desc with - | Pctf_inherit (ct) -> - line i ppf "Pctf_inherit\n"; - class_type i ppf ct; - | Pctf_val (s, mf, vf, ct) -> - line i ppf "Pctf_val \"%s\" %a %a\n" s.txt fmt_mutable_flag mf - fmt_virtual_flag vf; - core_type (i+1) ppf ct; - | Pctf_method (s, pf, vf, ct) -> - line i ppf "Pctf_method \"%s\" %a %a\n" s.txt fmt_private_flag pf - fmt_virtual_flag vf; - core_type (i+1) ppf ct; - | Pctf_constraint (ct1, ct2) -> - line i ppf "Pctf_constraint\n"; - core_type (i+1) ppf ct1; - core_type (i+1) ppf ct2; - | Pctf_attribute (s, arg) -> - line i ppf "Pctf_attribute \"%s\"\n" s.txt; - payload i ppf arg - | Pctf_extension (s, arg) -> - line i ppf "Pctf_extension \"%s\"\n" s.txt; - payload i ppf arg - - -and class_type_declaration i ppf x = - line i ppf "class_type_declaration %a\n" fmt_location x.pci_loc; - attributes i ppf x.pci_attributes; - let i = i+1 in - line i ppf "pci_virt = %a\n" fmt_virtual_flag x.pci_virt; - line i ppf "pci_params =\n"; - list (i+1) type_parameter ppf x.pci_params; - line i ppf "pci_name = %a\n" fmt_string_loc x.pci_name; - line i ppf "pci_expr =\n"; - class_type (i+1) ppf x.pci_expr; - -and class_structure i ppf { pcstr_self = p; pcstr_fields = l } = - line i ppf "class_structure\n"; - pattern (i+1) ppf p; - list (i+1) class_field ppf l; - -and class_field i ppf x = - line i ppf "class_field %a\n" fmt_location x.pcf_loc; - let i = i + 1 in - attributes i ppf x.pcf_attributes; - match x.pcf_desc with - | Pcf_inherit () -> () - | Pcf_val (s, mf, k) -> - line i ppf "Pcf_val %a\n" fmt_mutable_flag mf; - line (i+1) ppf "%a\n" fmt_string_loc s; - class_field_kind (i+1) ppf k - | Pcf_method (s, pf, k) -> - line i ppf "Pcf_method %a\n" fmt_private_flag pf; - line (i+1) ppf "%a\n" fmt_string_loc s; - class_field_kind (i+1) ppf k - | Pcf_constraint (ct1, ct2) -> - line i ppf "Pcf_constraint\n"; - core_type (i+1) ppf ct1; - core_type (i+1) ppf ct2; - | Pcf_initializer (e) -> - line i ppf "Pcf_initializer\n"; - expression (i+1) ppf e; - | Pcf_attribute (s, arg) -> - line i ppf "Pcf_attribute \"%s\"\n" s.txt; - payload i ppf arg - | Pcf_extension (s, arg) -> - line i ppf "Pcf_extension \"%s\"\n" s.txt; - payload i ppf arg - -and class_field_kind i ppf = function - | Cfk_concrete (o, e) -> - line i ppf "Concrete %a\n" fmt_override_flag o; - expression i ppf e - | Cfk_virtual t -> - line i ppf "Virtual\n"; - core_type i ppf t and module_type i ppf x = line i ppf "module_type %a\n" fmt_location x.pmty_loc; @@ -640,9 +522,7 @@ and signature_item i ppf x = module_type i ppf incl.pincl_mod; attributes i ppf incl.pincl_attributes | Psig_class () -> () - | Psig_class_type (l) -> - line i ppf "Psig_class_type\n"; - list i class_type_declaration ppf l; + | Psig_class_type () -> () | Psig_extension ((s, arg), attrs) -> line i ppf "Psig_extension \"%s\"\n" s.txt; attributes i ppf attrs; @@ -741,9 +621,7 @@ and structure_item i ppf x = fmt_longident_loc od.popen_lid; attributes i ppf od.popen_attributes | Pstr_class () -> () - | Pstr_class_type (l) -> - line i ppf "Pstr_class_type\n"; - list i class_type_declaration ppf l; + | Pstr_class_type () -> () | Pstr_include incl -> line i ppf "Pstr_include"; attributes i ppf incl.pincl_attributes; diff --git a/jscomp/ml/printtyp.ml b/jscomp/ml/printtyp.ml index 7f89f03766..2e7fd26a0e 100644 --- a/jscomp/ml/printtyp.ml +++ b/jscomp/ml/printtyp.ml @@ -1035,169 +1035,6 @@ let value_description id ppf decl = (* Print a class type *) -let method_type (_, kind, ty) = - match field_kind_repr kind, repr ty with - Fpresent, {desc=Tpoly(ty, tyl)} -> (ty, tyl) - | _ , ty -> (ty, []) - -let tree_of_metho sch concrete csil (lab, kind, ty) = - if lab <> dummy_method then begin - let kind = field_kind_repr kind in - let priv = kind <> Fpresent in - let virt = not (Concr.mem lab concrete) in - let (ty, tyl) = method_type (lab, kind, ty) in - let tty = tree_of_typexp sch ty in - remove_names tyl; - Ocsg_method (lab, priv, virt, tty) :: csil - end - else csil - -let rec prepare_class_type params = function - | Cty_constr (_p, tyl, cty) -> - let sty = Ctype.self_type cty in - if List.memq (proxy sty) !visited_objects - || not (List.for_all is_Tvar params) - || List.exists (deep_occur sty) tyl - then prepare_class_type params cty - else List.iter mark_loops tyl - | Cty_signature sign -> - let sty = repr sign.csig_self in - (* Self may have a name *) - let px = proxy sty in - if List.memq px !visited_objects then add_alias sty - else visited_objects := px :: !visited_objects; - let (fields, _) = - Ctype.flatten_fields (Ctype.object_fields sign.csig_self) - in - List.iter (fun met -> mark_loops (fst (method_type met))) fields; - Vars.iter (fun _ (_, _, ty) -> mark_loops ty) sign.csig_vars - | Cty_arrow (_, ty, cty) -> - mark_loops ty; - prepare_class_type params cty - -let rec tree_of_class_type sch params = - function - | Cty_constr (p', tyl, cty) -> - let sty = Ctype.self_type cty in - if List.memq (proxy sty) !visited_objects - || not (List.for_all is_Tvar params) - then - tree_of_class_type sch params cty - else - Octy_constr (tree_of_path p', tree_of_typlist true tyl) - | Cty_signature sign -> - let sty = repr sign.csig_self in - let self_ty = - if is_aliased sty then - Some (Otyp_var (false, name_of_type new_name (proxy sty))) - else None - in - let (fields, _) = - Ctype.flatten_fields (Ctype.object_fields sign.csig_self) - in - let csil = [] in - let csil = - List.fold_left - (fun csil (ty1, ty2) -> Ocsg_constraint (ty1, ty2) :: csil) - csil (tree_of_constraints params) - in - let all_vars = - Vars.fold (fun l (m, v, t) all -> (l, m, v, t) :: all) sign.csig_vars [] - in - (* Consequence of PR#3607: order of Map.fold has changed! *) - let all_vars = List.rev all_vars in - let csil = - List.fold_left - (fun csil (l, m, v, t) -> - Ocsg_value (l, m = Mutable, v = Virtual, tree_of_typexp sch t) - :: csil) - csil all_vars - in - let csil = - List.fold_left (tree_of_metho sch sign.csig_concr) csil fields - in - Octy_signature (self_ty, List.rev csil) - | Cty_arrow (l, ty, cty) -> - let lab = - string_of_label l - in - let ty = - if is_optional l then - match (repr ty).desc with - | Tconstr(path, [ty], _) when Path.same path Predef.path_option -> ty - | _ -> newconstr (Path.Pident(Ident.create "")) [] - else ty in - let tr = tree_of_typexp sch ty in - Octy_arrow (lab, tr, tree_of_class_type sch params cty) - -let class_type ppf cty = - reset (); - prepare_class_type [] cty; - !Oprint.out_class_type ppf (tree_of_class_type false [] cty) - -let tree_of_class_param param variance = - (match tree_of_typexp true param with - Otyp_var (_, s) -> s - | _ -> "?"), - if is_Tvar (repr param) then (true, true) else variance - -let class_variance = - List.map Variance.(fun v -> mem May_pos v, mem May_neg v) - -let tree_of_class_declaration id cl rs = - let params = filter_params cl.cty_params in - - reset (); - List.iter add_alias params; - prepare_class_type params cl.cty_type; - let sty = Ctype.self_type cl.cty_type in - List.iter mark_loops params; - - List.iter check_name_of_type (List.map proxy params); - if is_aliased sty then check_name_of_type (proxy sty); - - let vir_flag = cl.cty_new = None in - Osig_class - (vir_flag, Ident.name id, - List.map2 tree_of_class_param params (class_variance cl.cty_variance), - tree_of_class_type true params cl.cty_type, - tree_of_rec rs) - -let class_declaration id ppf cl = - !Oprint.out_sig_item ppf (tree_of_class_declaration id cl Trec_first) - -let tree_of_cltype_declaration id cl rs = - let params = List.map repr cl.clty_params in - - reset (); - List.iter add_alias params; - prepare_class_type params cl.clty_type; - let sty = Ctype.self_type cl.clty_type in - List.iter mark_loops params; - - List.iter check_name_of_type (List.map proxy params); - if is_aliased sty then check_name_of_type (proxy sty); - - let sign = Ctype.signature_of_class_type cl.clty_type in - - let virt = - let (fields, _) = - Ctype.flatten_fields (Ctype.object_fields sign.csig_self) in - List.exists - (fun (lab, _, _) -> - not (lab = dummy_method || Concr.mem lab sign.csig_concr)) - fields - || Vars.fold (fun _ (_,vr,_) b -> vr = Virtual || b) sign.csig_vars false - in - - Osig_class_type - (virt, Ident.name id, - List.map2 tree_of_class_param params (class_variance cl.clty_variance), - tree_of_class_type true params cl.clty_type, - tree_of_rec rs) - -let cltype_declaration id ppf cl = - !Oprint.out_sig_item ppf (tree_of_cltype_declaration id cl Trec_first) (* Print a module type *) @@ -1295,8 +1132,7 @@ and trees_of_sigitem = function [tree_of_modtype_declaration id decl] | Sig_class() -> [] - | Sig_class_type(id, decl, rs) -> - [tree_of_cltype_declaration id decl rs] + | Sig_class_type() -> [] and tree_of_modtype_declaration id decl = let mty = diff --git a/jscomp/ml/printtyp.mli b/jscomp/ml/printtyp.mli index af92ffa01c..5d402b6e11 100644 --- a/jscomp/ml/printtyp.mli +++ b/jscomp/ml/printtyp.mli @@ -64,13 +64,6 @@ val tree_of_modtype_declaration: val tree_of_signature: Types.signature -> out_sig_item list val tree_of_typexp: bool -> type_expr -> out_type val modtype_declaration: Ident.t -> formatter -> modtype_declaration -> unit -val class_type: formatter -> class_type -> unit -val tree_of_class_declaration: - Ident.t -> class_declaration -> rec_status -> out_sig_item -val class_declaration: Ident.t -> formatter -> class_declaration -> unit -val tree_of_cltype_declaration: - Ident.t -> class_type_declaration -> rec_status -> out_sig_item -val cltype_declaration: Ident.t -> formatter -> class_type_declaration -> unit val type_expansion: type_expr -> Format.formatter -> type_expr -> unit val prepare_expansion: type_expr * type_expr -> type_expr * type_expr val trace: diff --git a/jscomp/ml/printtyped.ml b/jscomp/ml/printtyped.ml index e38d17d2df..a6527a6275 100644 --- a/jscomp/ml/printtyped.ml +++ b/jscomp/ml/printtyped.ml @@ -74,12 +74,6 @@ let fmt_mutable_flag f x = | Mutable -> fprintf f "Mutable"; ;; -let fmt_virtual_flag f x = - match x with - | Virtual -> fprintf f "Virtual"; - | Concrete -> fprintf f "Concrete"; -;; - let fmt_override_flag f x = match x with | Override -> fprintf f "Override"; @@ -201,9 +195,7 @@ let rec core_type i ppf x = line i ppf "OTinherit\n"; core_type (i + 1) ppf ct ) l - | Ttyp_class (li, _, l) -> - line i ppf "Ttyp_class %a\n" fmt_path li; - list i core_type ppf l; + | Ttyp_class () -> () | Ttyp_alias (ct, s) -> line i ppf "Ttyp_alias \"%s\"\n" s; core_type i ppf ct; @@ -474,67 +466,6 @@ and extension_constructor_kind i ppf x = line i ppf "Text_rebind\n"; line (i+1) ppf "%a\n" fmt_path p; -and class_type i ppf x = - line i ppf "class_type %a\n" fmt_location x.cltyp_loc; - attributes i ppf x.cltyp_attributes; - let i = i+1 in - match x.cltyp_desc with - | Tcty_constr (li, _, l) -> - line i ppf "Tcty_constr %a\n" fmt_path li; - list i core_type ppf l; - | Tcty_signature (cs) -> - line i ppf "Tcty_signature\n"; - class_signature i ppf cs; - | Tcty_arrow (l, co, cl) -> - line i ppf "Tcty_arrow\n"; - arg_label i ppf l; - core_type i ppf co; - class_type i ppf cl; - | Tcty_open (ovf, m, _, _, e) -> - line i ppf "Tcty_open %a \"%a\"\n" fmt_override_flag ovf fmt_path m; - class_type i ppf e - -and class_signature i ppf { csig_self = ct; csig_fields = l } = - line i ppf "class_signature\n"; - core_type (i+1) ppf ct; - list (i+1) class_type_field ppf l; - -and class_type_field i ppf x = - line i ppf "class_type_field %a\n" fmt_location x.ctf_loc; - let i = i+1 in - attributes i ppf x.ctf_attributes; - match x.ctf_desc with - | Tctf_inherit (ct) -> - line i ppf "Tctf_inherit\n"; - class_type i ppf ct; - | Tctf_val (s, mf, vf, ct) -> - line i ppf "Tctf_val \"%s\" %a %a\n" s fmt_mutable_flag mf - fmt_virtual_flag vf; - core_type (i+1) ppf ct; - | Tctf_method (s, pf, vf, ct) -> - line i ppf "Tctf_method \"%s\" %a %a\n" s fmt_private_flag pf - fmt_virtual_flag vf; - core_type (i+1) ppf ct; - | Tctf_constraint (ct1, ct2) -> - line i ppf "Tctf_constraint\n"; - core_type (i+1) ppf ct1; - core_type (i+1) ppf ct2; - | Tctf_attribute (s, arg) -> - line i ppf "Tctf_attribute \"%s\"\n" s.txt; - Printast.payload i ppf arg - - -and class_type_declaration i ppf x = - line i ppf "class_type_declaration %a\n" fmt_location x.ci_loc; - let i = i+1 in - line i ppf "pci_virt = %a\n" fmt_virtual_flag x.ci_virt; - line i ppf "pci_params =\n"; - list (i+1) type_parameter ppf x.ci_params; - line i ppf "pci_name = \"%s\"\n" x.ci_id_name.txt; - line i ppf "pci_expr =\n"; - class_type (i+1) ppf x.ci_expr; - - and module_type i ppf x = line i ppf "module_type %a\n" fmt_location x.mty_loc; attributes i ppf x.mty_attributes; @@ -597,9 +528,8 @@ and signature_item i ppf x = module_type i ppf incl.incl_mod | Tsig_class () -> () - | Tsig_class_type (l) -> - line i ppf "Tsig_class_type\n"; - list i class_type_declaration ppf l; + | Tsig_class_type () -> + () | Tsig_attribute (s, arg) -> line i ppf "Tsig_attribute \"%s\"\n" s.txt; Printast.payload i ppf arg @@ -696,9 +626,7 @@ and structure_item i ppf x = fmt_path od.open_path; attributes i ppf od.open_attributes | Tstr_class () -> () - | Tstr_class_type (l) -> - line i ppf "Tstr_class_type\n"; - list i class_type_declaration ppf (List.map (fun (_, _, cl) -> cl) l); + | Tstr_class_type () -> () | Tstr_include incl -> line i ppf "Tstr_include"; attributes i ppf incl.incl_attributes; diff --git a/jscomp/ml/subst.ml b/jscomp/ml/subst.ml index f30b7a1f24..686aac5f8e 100644 --- a/jscomp/ml/subst.ml +++ b/jscomp/ml/subst.ml @@ -309,45 +309,6 @@ let type_declaration s decl = cleanup_types (); decl -let class_signature s sign = - { csig_self = typexp s sign.csig_self; - csig_vars = - Vars.map (function (m, v, t) -> (m, v, typexp s t)) sign.csig_vars; - csig_concr = sign.csig_concr; - csig_inher = - List.map (fun (p, tl) -> (type_path s p, List.map (typexp s) tl)) - sign.csig_inher; - } - -let rec class_type s = - function - Cty_constr (p, tyl, cty) -> - Cty_constr (type_path s p, List.map (typexp s) tyl, class_type s cty) - | Cty_signature sign -> - Cty_signature (class_signature s sign) - | Cty_arrow (l, ty, cty) -> - Cty_arrow (l, typexp s ty, class_type s cty) - - - -let cltype_declaration s decl = - let decl = - { clty_params = List.map (typexp s) decl.clty_params; - clty_variance = decl.clty_variance; - clty_type = class_type s decl.clty_type; - clty_path = type_path s decl.clty_path; - clty_loc = loc s decl.clty_loc; - clty_attributes = attrs s decl.clty_attributes; - } - in - (* Do clean up even if saving: type_declaration may be recursive *) - cleanup_types (); - decl - -let class_type s cty = - let cty = class_type s cty in - cleanup_types (); - cty let value_description s descr = { val_type = type_expr s descr.val_type; @@ -381,10 +342,7 @@ let rec rename_bound_idents s idents = function let id' = Ident.rename id in rename_bound_idents (add_modtype id (Mty_ident(Pident id')) s) (id' :: idents) sg - | Sig_class_type(id, _, _) :: sg -> - (* cheat and pretend they are types cf. PR#6650 *) - let id' = Ident.rename id in - rename_bound_idents (add_type id (Pident id') s) (id' :: idents) sg + | Sig_class_type () :: _ -> assert false | (Sig_value(id, _) | Sig_typext(id, _, _)) :: sg -> let id' = Ident.rename id in rename_bound_idents s (id' :: idents) sg @@ -430,8 +388,8 @@ and signature_component s comp newid = Sig_modtype(newid, modtype_declaration s d) | Sig_class() -> Sig_class() - | Sig_class_type(_id, d, rs) -> - Sig_class_type(newid, cltype_declaration s d, rs) + | Sig_class_type () -> + Sig_class_type () and module_declaration s decl = { diff --git a/jscomp/ml/subst.mli b/jscomp/ml/subst.mli index 3f975b48dd..50ee2ad934 100644 --- a/jscomp/ml/subst.mli +++ b/jscomp/ml/subst.mli @@ -47,19 +47,16 @@ val module_path: t -> Path.t -> Path.t val type_path: t -> Path.t -> Path.t val type_expr: t -> type_expr -> type_expr -val class_type: t -> class_type -> class_type val value_description: t -> value_description -> value_description val type_declaration: t -> type_declaration -> type_declaration val extension_constructor: t -> extension_constructor -> extension_constructor -val cltype_declaration: t -> class_type_declaration -> class_type_declaration val modtype: t -> module_type -> module_type val signature: t -> signature -> signature val modtype_declaration: t -> modtype_declaration -> modtype_declaration val module_declaration: t -> module_declaration -> module_declaration val typexp : t -> Types.type_expr -> Types.type_expr -val class_signature: t -> class_signature -> class_signature (* Composition of substitutions: apply (compose s1 s2) x = apply s2 (apply s1 x) *) diff --git a/jscomp/ml/tast_mapper.ml b/jscomp/ml/tast_mapper.ml index eaf6aa49e7..cae78def91 100644 --- a/jscomp/ml/tast_mapper.ml +++ b/jscomp/ml/tast_mapper.ml @@ -23,13 +23,6 @@ type mapper = { case: mapper -> case -> case; cases: mapper -> case list -> case list; - class_description: mapper -> class_description -> class_description; - - class_signature: mapper -> class_signature -> class_signature; - 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; env: mapper -> Env.t -> Env.t; expr: mapper -> expression -> expression; extension_constructor: mapper -> extension_constructor -> @@ -74,12 +67,6 @@ let structure sub {str_items; str_type; str_final_env} = str_type; } -let class_infos sub f x = - {x with - ci_params = List.map (tuple2 (sub.typ sub) id) x.ci_params; - ci_expr = f x.ci_expr; - } - let module_type_declaration sub x = let mtd_type = opt (sub.module_type sub) x.mtd_type in {x with mtd_type} @@ -90,9 +77,6 @@ let module_declaration sub x = let include_infos f x = {x with incl_mod = f x.incl_mod} -let class_type_declaration sub x = - class_infos sub (sub.class_type sub) x - let structure_item sub {str_desc; str_loc; str_env} = let str_env = sub.env sub str_env in @@ -113,9 +97,7 @@ let structure_item sub {str_desc; str_loc; str_env} = Tstr_recmodule (List.map (sub.module_binding sub) list) | Tstr_modtype x -> Tstr_modtype (sub.module_type_declaration sub x) | Tstr_class () -> Tstr_class () - | Tstr_class_type list -> - Tstr_class_type - (List.map (tuple3 id id (sub.class_type_declaration sub)) list) + | Tstr_class_type () -> Tstr_class_type () | Tstr_include incl -> Tstr_include (include_infos (sub.module_expr sub) incl) | Tstr_open _ @@ -367,17 +349,13 @@ let signature_item sub x = Tsig_modtype (sub.module_type_declaration sub x) | Tsig_include incl -> Tsig_include (include_infos (sub.module_type sub) incl) - | Tsig_class_type list -> - Tsig_class_type - (List.map (sub.class_type_declaration sub) list) + | Tsig_class_type _ | Tsig_class _ | Tsig_open _ | Tsig_attribute _ as d -> d in {x with sig_desc; sig_env} -let class_description sub x = - class_infos sub (sub.class_type sub) x let module_type sub x = let mty_env = sub.env sub x.mty_env in @@ -466,49 +444,6 @@ let module_binding sub x = let mb_expr = sub.module_expr sub x.mb_expr in {x with mb_expr} - -let class_type sub x = - let cltyp_env = sub.env sub x.cltyp_env in - let cltyp_desc = - match x.cltyp_desc with - | Tcty_signature csg -> Tcty_signature (sub.class_signature sub csg) - | Tcty_constr (path, lid, list) -> - Tcty_constr ( - path, - lid, - List.map (sub.typ sub) list - ) - | Tcty_arrow (label, ct, cl) -> - Tcty_arrow - (label, - sub.typ sub ct, - sub.class_type sub cl - ) - | Tcty_open (ovf, p, lid, env, e) -> - Tcty_open (ovf, p, lid, sub.env sub env, sub.class_type sub e) - in - {x with cltyp_desc; cltyp_env} - -let class_signature sub x = - let csig_self = sub.typ sub x.csig_self in - let csig_fields = List.map (sub.class_type_field sub) x.csig_fields in - {x with csig_self; csig_fields} - -let class_type_field sub x = - let ctf_desc = - match x.ctf_desc with - | Tctf_inherit ct -> - Tctf_inherit (sub.class_type sub ct) - | Tctf_val (s, mut, virt, ct) -> - Tctf_val (s, mut, virt, sub.typ sub ct) - | Tctf_method (s, priv, virt, ct) -> - Tctf_method (s, priv, virt, sub.typ sub ct) - | Tctf_constraint (ct1, ct2) -> - Tctf_constraint (sub.typ sub ct1, sub.typ sub ct2) - | Tctf_attribute _ as d -> d - in - {x with ctf_desc} - let typ sub x = let ctyp_env = sub.env sub x.ctyp_env in let ctyp_desc = @@ -522,12 +457,7 @@ let typ sub x = Ttyp_constr (path, lid, List.map (sub.typ sub) list) | Ttyp_object (list, closed) -> Ttyp_object ((List.map (sub.object_field sub) list), closed) - | Ttyp_class (path, lid, list) -> - Ttyp_class - (path, - lid, - List.map (sub.typ sub) list - ) + | Ttyp_class () -> Ttyp_class () | Ttyp_alias (ct, s) -> Ttyp_alias (sub.typ sub ct, s) | Ttyp_variant (list, closed, labels) -> @@ -576,11 +506,6 @@ let default = { case; cases; - class_description; - class_signature; - class_type; - class_type_declaration; - class_type_field; env; expr; extension_constructor; diff --git a/jscomp/ml/tast_mapper.mli b/jscomp/ml/tast_mapper.mli index 4fd87b6935..f22f8aeac2 100644 --- a/jscomp/ml/tast_mapper.mli +++ b/jscomp/ml/tast_mapper.mli @@ -22,12 +22,6 @@ type mapper = { case: mapper -> case -> case; cases: mapper -> case list -> case list; - class_description: mapper -> class_description -> class_description; - class_signature: mapper -> class_signature -> class_signature; - 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; env: mapper -> Env.t -> Env.t; expr: mapper -> expression -> expression; extension_constructor: mapper -> extension_constructor -> diff --git a/jscomp/ml/typeclass.ml b/jscomp/ml/typeclass.ml deleted file mode 100644 index 00ea7dfcc1..0000000000 --- a/jscomp/ml/typeclass.ml +++ /dev/null @@ -1,1105 +0,0 @@ -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 1996 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -open Parsetree -open Asttypes -open Types -open Typetexp -open Format - -type 'a class_info = { - cls_id : Ident.t; - cls_id_loc : string loc; - cls_decl : class_declaration; - cls_ty_id : Ident.t; - cls_ty_decl : class_type_declaration; - cls_obj_id : Ident.t; - cls_obj_abbr : type_declaration; - cls_typesharp_id : Ident.t; - cls_abbr : type_declaration; - cls_arity : int; - cls_pub_methods : string list; - cls_info : 'a; -} - -type class_type_info = { - clsty_ty_id : Ident.t; - clsty_id_loc : string loc; - clsty_ty_decl : class_type_declaration; - clsty_obj_id : Ident.t; - clsty_obj_abbr : type_declaration; - clsty_typesharp_id : Ident.t; - clsty_abbr : type_declaration; - clsty_info : Typedtree.class_type_declaration; -} - -type error = - Unconsistent_constraint of (type_expr * type_expr) list - | Field_type_mismatch of string * string * (type_expr * type_expr) list - | Structure_expected of class_type - | Pattern_type_clash of type_expr - | Repeated_parameter - | Unbound_class_type_2 of Longident.t - | Abbrev_type_clash of type_expr * type_expr * type_expr - | Constructor_type_mismatch of string * (type_expr * type_expr) list - | Virtual_class of bool * bool * string list * string list - | Parameter_arity_mismatch of Longident.t * int * int - | Parameter_mismatch of (type_expr * type_expr) list - | Bad_parameters of Ident.t * type_expr * type_expr - - | Unbound_type_var of (formatter -> unit) * Ctype.closed_class_failure - | Non_generalizable_class of Ident.t * Types.class_declaration - | Cannot_coerce_self of type_expr - | Non_collapsable_conjunction of - Ident.t * Types.class_declaration * (type_expr * type_expr) list - | No_overriding of string * string - - -exception Error of Location.t * Env.t * error -exception Error_forward of Location.error - -open Typedtree - -let ctyp desc typ env loc = - { ctyp_desc = desc; ctyp_type = typ; ctyp_loc = loc; ctyp_env = env; - ctyp_attributes = [] } - - (**********************) - (* Useful constants *) - (**********************) - - -(* - Self type have a dummy private method, thus preventing it to become - closed. -*) -let dummy_method = Btype.dummy_method - -(* - Path associated to the temporary class type of a class being typed - (its constructor is not available). -*) -let unbound_class = Path.Pident (Ident.create "*undef*") - - - (************************************) - (* Some operations on class types *) - (************************************) - - -(* Fully expand the head of a class type *) -let rec scrape_class_type = - function - Cty_constr (_, _, cty) -> scrape_class_type cty - | cty -> cty - -(* Generalize a class type *) -let rec generalize_class_type gen = - function - Cty_constr (_, params, cty) -> - List.iter gen params; - generalize_class_type gen cty - | Cty_signature {csig_self = sty; csig_vars = vars; csig_inher = inher} -> - gen sty; - Vars.iter (fun _ (_, _, ty) -> gen ty) vars; - List.iter (fun (_,tl) -> List.iter gen tl) inher - | Cty_arrow (_, ty, cty) -> - gen ty; - generalize_class_type gen cty - -let generalize_class_type vars = - let gen = if vars then Ctype.generalize else Ctype.generalize_structure in - generalize_class_type gen - -(* Return the virtual methods of a class type *) -let virtual_methods sign = - let (fields, _) = - Ctype.flatten_fields (Ctype.object_fields sign.Types.csig_self) - in - List.fold_left - (fun virt (lab, _, _) -> - if lab = dummy_method then virt else - if Concr.mem lab sign.csig_concr then virt else - lab::virt) - [] fields - -(* Return the constructor type associated to a class type *) -let rec constructor_type constr cty = - match cty with - Cty_constr (_, _, cty) -> - constructor_type constr cty - | Cty_signature _ -> - constr - | Cty_arrow (l, ty, cty) -> - Ctype.newty (Tarrow (l, ty, constructor_type constr cty, Cok)) - -let rec class_body cty = - match cty with - Cty_constr _ -> - cty (* Only class bodies can be abbreviated *) - | Cty_signature _ -> - cty - | Cty_arrow (_, _, cty) -> - class_body cty - - -(* Check that all type variables are generalizable *) -(* Use Env.empty to prevent expansion of recursively defined object types; - cf. typing-poly/poly.ml *) -let rec closed_class_type = - function - Cty_constr (_, params, _) -> - List.for_all (Ctype.closed_schema Env.empty) params - | Cty_signature sign -> - Ctype.closed_schema Env.empty sign.csig_self - && - Vars.fold (fun _ (_, _, ty) cc -> Ctype.closed_schema Env.empty ty && cc) - sign.csig_vars - true - | Cty_arrow (_, ty, cty) -> - Ctype.closed_schema Env.empty ty - && - closed_class_type cty - -let closed_class cty = - List.for_all (Ctype.closed_schema Env.empty) cty.cty_params - && - closed_class_type cty.cty_type - -let rec limited_generalize rv = - function - Cty_constr (_path, params, cty) -> - List.iter (Ctype.limited_generalize rv) params; - limited_generalize rv cty - | Cty_signature sign -> - Ctype.limited_generalize rv sign.csig_self; - Vars.iter (fun _ (_, _, ty) -> Ctype.limited_generalize rv ty) - sign.csig_vars; - List.iter (fun (_, tl) -> List.iter (Ctype.limited_generalize rv) tl) - sign.csig_inher - | Cty_arrow (_, ty, cty) -> - Ctype.limited_generalize rv ty; - limited_generalize rv cty - - - - (***********************************) - (* Primitives for typing classes *) - (***********************************) - - - -(* Enter an instance variable in the environment *) -let concr_vals vars = - Vars.fold - (fun id (_, vf, _) s -> if vf = Virtual then s else Concr.add id s) - vars Concr.empty - -let inheritance self_type env ovf concr_meths warn_vals loc parent = - match scrape_class_type parent with - Cty_signature cl_sig -> - - (* Methods *) - begin try - Ctype.unify env self_type cl_sig.csig_self - with Ctype.Unify trace -> - match trace with - _::_::_::({desc = Tfield(n, _, _, _)}, _)::rem -> - raise(Error(loc, env, Field_type_mismatch ("method", n, rem))) - | _ -> - assert false - end; - - (* Overriding *) - let over_meths = Concr.inter cl_sig.csig_concr concr_meths in - let concr_vals = concr_vals cl_sig.csig_vars in - let over_vals = Concr.inter concr_vals warn_vals in - begin match ovf with - Some Fresh -> - let cname = - match parent with - Cty_constr (p, _, _) -> Path.name p - | _ -> "inherited" - in - if not (Concr.is_empty over_meths) then - Location.prerr_warning loc - (Warnings.Method_override (cname :: Concr.elements over_meths)); - if not (Concr.is_empty over_vals) then - Location.prerr_warning loc - (Warnings.Instance_variable_override - (cname :: Concr.elements over_vals)); - | Some Override - when Concr.is_empty over_meths && Concr.is_empty over_vals -> - raise (Error(loc, env, No_overriding ("",""))) - | _ -> () - end; - - let concr_meths = Concr.union cl_sig.csig_concr concr_meths - and warn_vals = Concr.union concr_vals warn_vals in - - (cl_sig, concr_meths, warn_vals) - - | _ -> - raise(Error(loc, env, Structure_expected parent)) - - -let delayed_meth_specs = ref [] - -let declare_method val_env meths self_type lab priv sty loc = - let (_, ty') = - Ctype.filter_self_method val_env lab priv meths self_type - in - let unif ty = - try Ctype.unify val_env ty ty' with Ctype.Unify trace -> - raise(Error(loc, val_env, Field_type_mismatch ("method", lab, trace))) - in - let sty = Ast_helper.Typ.force_poly sty in - match sty.ptyp_desc, priv with - Ptyp_poly ([],sty'), Public -> -(* TODO: we moved the [transl_simple_type_univars] outside of the lazy, -so that we can get an immediate value. Is that correct ? Ask Jacques. *) - let returned_cty = ctyp Ttyp_any (Ctype.newty Tnil) val_env loc in - delayed_meth_specs := - Warnings.mk_lazy (fun () -> - let cty = transl_simple_type_univars val_env sty' in - let ty = cty.ctyp_type in - unif ty; - returned_cty.ctyp_desc <- Ttyp_poly ([], cty); - returned_cty.ctyp_type <- ty; - ) :: - !delayed_meth_specs; - returned_cty - | _ -> - let cty = transl_simple_type val_env false sty in - let ty = cty.ctyp_type in - unif ty; - cty - -let type_constraint val_env sty sty' loc = - let cty = transl_simple_type val_env false sty in - let ty = cty.ctyp_type in - let cty' = transl_simple_type val_env false sty' in - let ty' = cty'.ctyp_type in - begin - try Ctype.unify val_env ty ty' with Ctype.Unify trace -> - raise(Error(loc, val_env, Unconsistent_constraint trace)); - end; - (cty, cty') - - -(*******************************) - -let add_val lab (mut, virt, ty) val_sig = - let virt = - try - let (_mut', virt', _ty') = Vars.find lab val_sig in - if virt' = Concrete then virt' else virt - with Not_found -> virt - in - Vars.add lab (mut, virt, ty) val_sig - -let rec class_type_field env self_type meths arg ctf = - Builtin_attributes.warning_scope ctf.pctf_attributes - (fun () -> class_type_field_aux env self_type meths arg ctf) - -and class_type_field_aux env self_type meths - (fields, val_sig, concr_meths, inher) ctf = - - let loc = ctf.pctf_loc in - let mkctf desc = - { ctf_desc = desc; ctf_loc = loc; ctf_attributes = ctf.pctf_attributes } - in - match ctf.pctf_desc with - Pctf_inherit sparent -> - let parent = class_type env sparent in - let inher = - match parent.cltyp_type with - Cty_constr (p, tl, _) -> (p, tl) :: inher - | _ -> inher - in - let (cl_sig, concr_meths, _) = - inheritance self_type env None concr_meths Concr.empty sparent.pcty_loc - parent.cltyp_type - in - let val_sig = - Vars.fold add_val cl_sig.csig_vars val_sig in - (mkctf (Tctf_inherit parent) :: fields, - val_sig, concr_meths, inher) - - | Pctf_val ({txt=lab}, mut, virt, sty) -> - let cty = transl_simple_type env false sty in - let ty = cty.ctyp_type in - (mkctf (Tctf_val (lab, mut, virt, cty)) :: fields, - add_val lab (mut, virt, ty) val_sig, concr_meths, inher) - - | Pctf_method ({txt=lab}, priv, virt, sty) -> - let cty = - declare_method env meths self_type lab priv sty ctf.pctf_loc in - let concr_meths = - match virt with - | Concrete -> Concr.add lab concr_meths - | Virtual -> concr_meths - in - (mkctf (Tctf_method (lab, priv, virt, cty)) :: fields, - val_sig, concr_meths, inher) - - | Pctf_constraint (sty, sty') -> - let (cty, cty') = type_constraint env sty sty' ctf.pctf_loc in - (mkctf (Tctf_constraint (cty, cty')) :: fields, - val_sig, concr_meths, inher) - - | Pctf_attribute x -> - Builtin_attributes.warning_attribute x; - (mkctf (Tctf_attribute x) :: fields, - val_sig, concr_meths, inher) - - | Pctf_extension ext -> - raise (Error_forward (Builtin_attributes.error_of_extension ext)) - -and class_signature env {pcsig_self=sty; pcsig_fields=sign} = - let meths = ref Meths.empty in - let self_cty = transl_simple_type env false sty in - let self_cty = { self_cty with - ctyp_type = Ctype.expand_head env self_cty.ctyp_type } in - let self_type = self_cty.ctyp_type in - - (* Check that the binder is a correct type, and introduce a dummy - method preventing self type from being closed. *) - let dummy_obj = Ctype.newvar () in - Ctype.unify env (Ctype.filter_method env dummy_method Private dummy_obj) - (Ctype.newty (Ttuple [])); - begin try - Ctype.unify env self_type dummy_obj - with Ctype.Unify _ -> - raise(Error(sty.ptyp_loc, env, Pattern_type_clash self_type)) - end; - - (* Class type fields *) - let (rev_fields, val_sig, concr_meths, inher) = - Builtin_attributes.warning_scope [] - (fun () -> - List.fold_left (class_type_field env self_type meths) - ([], Vars.empty, Concr.empty, []) - sign - ) - in - let cty = {csig_self = self_type; - csig_vars = val_sig; - csig_concr = concr_meths; - csig_inher = inher} - in - { csig_self = self_cty; - csig_fields = List.rev rev_fields; - csig_type = cty; - } - -and class_type env scty = - Builtin_attributes.warning_scope scty.pcty_attributes - (fun () -> class_type_aux env scty) - -and class_type_aux env scty = - let cltyp desc typ = - { - cltyp_desc = desc; - cltyp_type = typ; - cltyp_loc = scty.pcty_loc; - cltyp_env = env; - cltyp_attributes = scty.pcty_attributes; - } - in - match scty.pcty_desc with - Pcty_constr (lid, styl) -> - let (path, decl) = Typetexp.find_class_type env scty.pcty_loc lid.txt in - if Path.same decl.clty_path unbound_class then - raise(Error(scty.pcty_loc, env, Unbound_class_type_2 lid.txt)); - let (params, clty) = - Ctype.instance_class decl.clty_params decl.clty_type - in - if List.length params <> List.length styl then - raise(Error(scty.pcty_loc, env, - Parameter_arity_mismatch (lid.txt, List.length params, - List.length styl))); - let ctys = List.map2 - (fun sty ty -> - let cty' = transl_simple_type env false sty in - let ty' = cty'.ctyp_type in - begin - try Ctype.unify env ty' ty with Ctype.Unify trace -> - raise(Error(sty.ptyp_loc, env, Parameter_mismatch trace)) - end; - cty' - ) styl params - in - let typ = Cty_constr (path, params, clty) in - cltyp (Tcty_constr ( path, lid , ctys)) typ - - | Pcty_signature pcsig -> - let clsig = class_signature env pcsig in - let typ = Cty_signature clsig.csig_type in - cltyp (Tcty_signature clsig) typ - - | Pcty_arrow (l, sty, scty) -> - let cty = transl_simple_type env false sty in - let ty = cty.ctyp_type in - let ty = - if Btype.is_optional l - then Ctype.newty (Tconstr(Predef.path_option,[ty], ref Mnil)) - else ty in - let clty = class_type env scty in - let typ = Cty_arrow (l, ty, clty.cltyp_type) in - cltyp (Tcty_arrow (l, cty, clty)) typ - - | Pcty_open (ovf, lid, e) -> - let (path, newenv) = !Typecore.type_open ovf env scty.pcty_loc lid in - let clty = class_type newenv e in - cltyp (Tcty_open (ovf, path, lid, newenv, clty)) clty.cltyp_type - - | Pcty_extension ext -> - raise (Error_forward (Builtin_attributes.error_of_extension ext)) - -let class_type env scty = - delayed_meth_specs := []; - let cty = class_type env scty in - List.iter Lazy.force (List.rev !delayed_meth_specs); - delayed_meth_specs := []; - cty - -(*******************************) - - -(*******************************) - -(* Approximate the type of the constructor to allow recursive use *) -(* of optional parameters *) - -let var_option = Predef.type_option (Btype.newgenvar ()) - - -let rec approx_description ct = - match ct.pcty_desc with - Pcty_arrow (l, _, ct) -> - let arg = - if Btype.is_optional l then Ctype.instance_def var_option - else Ctype.newvar () in - Ctype.newty (Tarrow (l, arg, approx_description ct, Cok)) - | _ -> Ctype.newvar () - -(*******************************) - -let temp_abbrev loc env id arity = - let params = ref [] in - for _i = 1 to arity do - params := Ctype.newvar () :: !params - done; - let ty = Ctype.newobj (Ctype.newvar ()) in - let env = - Env.add_type ~check:true id - {type_params = !params; - type_arity = arity; - type_kind = Type_abstract; - type_private = Public; - type_manifest = Some ty; - type_variance = Misc.replicate_list Variance.full arity; - type_newtype_level = None; - type_loc = loc; - type_attributes = []; (* or keep attrs from the class decl? *) - type_immediate = false; - type_unboxed = unboxed_false_default_false; - } - env - in - (!params, ty, env) - -let initial_env approx - (res, env) (cl, id, ty_id, obj_id, cl_id) = - (* Temporary abbreviations *) - let arity = List.length cl.pci_params in - let (obj_params, obj_ty, env) = temp_abbrev cl.pci_loc env obj_id arity in - let (cl_params, cl_ty, env) = temp_abbrev cl.pci_loc env cl_id arity in - - (* Temporary type for the class constructor *) - let constr_type = approx cl.pci_expr in - let dummy_cty = - Cty_signature - { csig_self = Ctype.newvar (); - csig_vars = Vars.empty; - csig_concr = Concr.empty; - csig_inher = [] } - in - let dummy_class = - {Types.cty_params = []; (* Dummy value *) - cty_variance = []; - cty_type = dummy_cty; (* Dummy value *) - cty_path = unbound_class; - cty_new = - begin match cl.pci_virt with - | Virtual -> None - | Concrete -> Some constr_type - end; - cty_loc = Location.none; - cty_attributes = []; - } - in - let env = - Env.add_cltype ty_id - {clty_params = []; (* Dummy value *) - clty_variance = []; - clty_type = dummy_cty; (* Dummy value *) - clty_path = unbound_class; - clty_loc = Location.none; - clty_attributes = []; - } env - in - ((cl, id, ty_id, - obj_id, obj_params, obj_ty, - cl_id, cl_params, cl_ty, - constr_type, dummy_class)::res, - env) - -let class_infos kind - (cl, id, ty_id, - obj_id, obj_params, obj_ty, - cl_id, cl_params, cl_ty, - constr_type, dummy_class) - (res, env) = - - reset_type_variables (); - Ctype.begin_class_def (); - - (* Introduce class parameters *) - let ci_params = - let make_param (sty, v) = - try - (transl_type_param env sty, v) - with Already_bound -> - raise(Error(sty.ptyp_loc, env, Repeated_parameter)) - in - List.map make_param cl.pci_params - in - let params = List.map (fun (cty, _) -> cty.ctyp_type) ci_params in - - (* Allow self coercions (only for class declarations) *) - let coercion_locs = ref [] in - - (* Type the class expression *) - let (expr, typ) = - try - Typecore.self_coercion := - (Path.Pident obj_id, coercion_locs) :: !Typecore.self_coercion; - let res = kind env cl.pci_expr in - Typecore.self_coercion := List.tl !Typecore.self_coercion; - res - with exn -> - Typecore.self_coercion := []; raise exn - in - - Ctype.end_def (); - - let sty = Ctype.self_type typ in - - (* First generalize the type of the dummy method (cf PR#6123) *) - let (fields, _) = Ctype.flatten_fields (Ctype.object_fields sty) in - List.iter (fun (met, _, ty) -> if met = dummy_method then Ctype.generalize ty) - fields; - (* Generalize the row variable *) - let rv = Ctype.row_variable sty in - List.iter (Ctype.limited_generalize rv) params; - limited_generalize rv typ; - - (* Check the abbreviation for the object type *) - let (obj_params', obj_type) = Ctype.instance_class params typ in - let constr = Ctype.newconstr (Path.Pident obj_id) obj_params in - begin - let ty = Ctype.self_type obj_type in - Ctype.hide_private_methods ty; - Ctype.close_object ty; - begin try - List.iter2 (Ctype.unify env) obj_params obj_params' - with Ctype.Unify _ -> - raise(Error(cl.pci_loc, env, - Bad_parameters (obj_id, constr, - Ctype.newconstr (Path.Pident obj_id) - obj_params'))) - end; - begin try - Ctype.unify env ty constr - with Ctype.Unify _ -> - raise(Error(cl.pci_loc, env, - Abbrev_type_clash (constr, ty, Ctype.expand_head env constr))) - end - end; - - (* Check the other temporary abbreviation (#-type) *) - begin - let (cl_params', cl_type) = Ctype.instance_class params typ in - let ty = Ctype.self_type cl_type in - Ctype.hide_private_methods ty; - Ctype.set_object_name obj_id (Ctype.row_variable ty) cl_params ty; - begin try - List.iter2 (Ctype.unify env) cl_params cl_params' - with Ctype.Unify _ -> - raise(Error(cl.pci_loc, env, - Bad_parameters (cl_id, - Ctype.newconstr (Path.Pident cl_id) - cl_params, - Ctype.newconstr (Path.Pident cl_id) - cl_params'))) - end; - begin try - Ctype.unify env ty cl_ty - with Ctype.Unify _ -> - let constr = Ctype.newconstr (Path.Pident cl_id) params in - raise(Error(cl.pci_loc, env, Abbrev_type_clash (constr, ty, cl_ty))) - end - end; - - (* Type of the class constructor *) - begin try - Ctype.unify env - (constructor_type constr obj_type) - (Ctype.instance env constr_type) - with Ctype.Unify trace -> - raise(Error(cl.pci_loc, env, - Constructor_type_mismatch (cl.pci_name.txt, trace))) - end; - - (* Class and class type temporary definitions *) - let cty_variance = List.map (fun _ -> Variance.full) params in - let cltydef = - {clty_params = params; clty_type = class_body typ; - clty_variance = cty_variance; - clty_path = Path.Pident obj_id; - clty_loc = cl.pci_loc; - clty_attributes = cl.pci_attributes; - } - in - dummy_class.cty_type <- typ; - let env = - Env.add_cltype ty_id cltydef ( - env) - in - - if cl.pci_virt = Concrete then begin - let sign = Ctype.signature_of_class_type typ in - let mets = virtual_methods sign in - let vals = - Vars.fold - (fun name (_mut, vr, _ty) l -> if vr = Virtual then name :: l else l) - sign.csig_vars [] in - if mets <> [] || vals <> [] then - raise(Error(cl.pci_loc, env, Virtual_class(false, false, mets, - vals))); - end; - - (* Misc. *) - let arity = Ctype.class_type_arity typ in - let pub_meths = - let (fields, _) = - Ctype.flatten_fields (Ctype.object_fields (Ctype.expand_head env obj_ty)) - in - List.map (function (lab, _, _) -> lab) fields - in - - (* Final definitions *) - let (params', typ') = Ctype.instance_class params typ in - let cltydef = - {clty_params = params'; clty_type = class_body typ'; - clty_variance = cty_variance; - clty_path = Path.Pident obj_id; - clty_loc = cl.pci_loc; - clty_attributes = cl.pci_attributes; - } - and clty = - {cty_params = params'; cty_type = typ'; - cty_variance = cty_variance; - cty_path = Path.Pident obj_id; - cty_new = - begin match cl.pci_virt with - | Virtual -> None - | Concrete -> Some (Ctype.instance env constr_type) - end; - cty_loc = cl.pci_loc; - cty_attributes = cl.pci_attributes; - } - in - let obj_abbr = - {type_params = obj_params; - type_arity = List.length obj_params; - type_kind = Type_abstract; - type_private = Public; - type_manifest = Some obj_ty; - type_variance = List.map (fun _ -> Variance.full) obj_params; - type_newtype_level = None; - type_loc = cl.pci_loc; - type_attributes = []; (* or keep attrs from cl? *) - type_immediate = false; - type_unboxed = unboxed_false_default_false; - } - in - let (cl_params, cl_ty) = - Ctype.instance_parameterized_type params (Ctype.self_type typ) - in - Ctype.hide_private_methods cl_ty; - Ctype.set_object_name obj_id (Ctype.row_variable cl_ty) cl_params cl_ty; - let cl_abbr = - {type_params = cl_params; - type_arity = List.length cl_params; - type_kind = Type_abstract; - type_private = Public; - type_manifest = Some cl_ty; - type_variance = List.map (fun _ -> Variance.full) cl_params; - type_newtype_level = None; - type_loc = cl.pci_loc; - type_attributes = []; (* or keep attrs from cl? *) - type_immediate = false; - type_unboxed = unboxed_false_default_false; - } - in - ((cl, id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, ci_params, - arity, pub_meths, List.rev !coercion_locs, expr) :: res, - env) - -let final_decl env - (cl, id, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, ci_params, - arity, pub_meths, coe, expr) = - - begin try Ctype.collapse_conj_params env clty.cty_params - with Ctype.Unify trace -> - raise(Error(cl.pci_loc, env, Non_collapsable_conjunction (id, clty, trace))) - end; - - List.iter Ctype.generalize clty.cty_params; - generalize_class_type true clty.cty_type; - Misc.may Ctype.generalize clty.cty_new; - List.iter Ctype.generalize obj_abbr.type_params; - Misc.may Ctype.generalize obj_abbr.type_manifest; - List.iter Ctype.generalize cl_abbr.type_params; - Misc.may Ctype.generalize cl_abbr.type_manifest; - - if not (closed_class clty) then - raise(Error(cl.pci_loc, env, Non_generalizable_class (id, clty))); - - begin match - Ctype.closed_class clty.cty_params - (Ctype.signature_of_class_type clty.cty_type) - with - None -> () - | Some reason -> - let printer = - function ppf -> Printtyp.cltype_declaration id ppf cltydef - in - raise(Error(cl.pci_loc, env, Unbound_type_var(printer, reason))) - end; - - (id, cl.pci_name, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, - arity, pub_meths, coe, expr, - { ci_loc = cl.pci_loc; - ci_virt = cl.pci_virt; - ci_params = ci_params; -(* TODO : check that we have the correct use of identifiers *) - ci_id_name = cl.pci_name; - ci_id_class = id; - ci_id_class_type = ty_id; - ci_id_object = obj_id; - ci_id_typehash = cl_id; - ci_expr = expr; - ci_decl = clty; - ci_type_decl = cltydef; - ci_attributes = cl.pci_attributes; - }) -(* (cl.pci_variance, cl.pci_loc)) *) - -let class_infos kind - (cl, id, ty_id, - obj_id, obj_params, obj_ty, - cl_id, cl_params, cl_ty, - constr_type, dummy_class) - (res, env) = - Builtin_attributes.warning_scope cl.pci_attributes - (fun () -> - class_infos kind - (cl, id, ty_id, - obj_id, obj_params, obj_ty, - cl_id, cl_params, cl_ty, - constr_type, dummy_class) - (res, env) - ) - -let extract_type_decls - (_id, _id_loc, clty, _ty_id, cltydef, obj_id, obj_abbr, _cl_id, cl_abbr, - _arity, _pub_meths, _coe, _expr, required) decls = - (obj_id, obj_abbr, cl_abbr, clty, cltydef, required) :: decls - -let merge_type_decls - (id, id_loc, _clty, ty_id, _cltydef, obj_id, _obj_abbr, cl_id, _cl_abbr, - arity, pub_meths, coe, expr, req) (obj_abbr, cl_abbr, clty, cltydef) = - (id, id_loc, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, - arity, pub_meths, coe, expr, req) - -let final_env env - (_id, _id_loc, _clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, - _arity, _pub_meths, _coe, _expr, _req) = - (* Add definitions after cleaning them *) - Env.add_type ~check:true obj_id - (Subst.type_declaration Subst.identity obj_abbr) ( - Env.add_type ~check:true cl_id - (Subst.type_declaration Subst.identity cl_abbr) ( - Env.add_cltype ty_id (Subst.cltype_declaration Subst.identity cltydef) - env)) - -(* Check that #c is coercible to c if there is a self-coercion *) -let check_coercions env - (id, id_loc, clty, ty_id, cltydef, obj_id, obj_abbr, cl_id, cl_abbr, - arity, pub_meths, coercion_locs, _expr, req) = - begin match coercion_locs with [] -> () - | loc :: _ -> - let cl_ty, obj_ty = - match cl_abbr.type_manifest, obj_abbr.type_manifest with - Some cl_ab, Some obj_ab -> - let cl_params, cl_ty = - Ctype.instance_parameterized_type cl_abbr.type_params cl_ab - and obj_params, obj_ty = - Ctype.instance_parameterized_type obj_abbr.type_params obj_ab - in - List.iter2 (Ctype.unify env) cl_params obj_params; - cl_ty, obj_ty - | _ -> assert false - in - begin try Ctype.subtype env cl_ty obj_ty () - with Ctype.Subtype (tr1, tr2) -> - raise(Typecore.Error(loc, env, Typecore.Not_subtype(tr1, tr2))) - end; - if not (Ctype.opened_object cl_ty) then - raise(Error(loc, env, Cannot_coerce_self obj_ty)) - end; - {cls_id = id; - cls_id_loc = id_loc; - cls_decl = clty; - cls_ty_id = ty_id; - cls_ty_decl = cltydef; - cls_obj_id = obj_id; - cls_obj_abbr = obj_abbr; - cls_typesharp_id = cl_id; - cls_abbr = cl_abbr; - cls_arity = arity; - cls_pub_methods = pub_meths; - cls_info=req} - -(*******************************) -(* FIXME: [define_class] is always [false] here *) -let type_classes approx kind env cls = - let cls = - List.map - (function cl -> - (cl, - Ident.create cl.pci_name.txt, Ident.create cl.pci_name.txt, - Ident.create cl.pci_name.txt, Ident.create ("#" ^ cl.pci_name.txt))) - cls - in - Ctype.init_def (Ident.current_time ()); - Ctype.begin_class_def (); - let (res, env) = - List.fold_left (initial_env approx) ([], env) cls - in - let (res, env) = - List.fold_right (class_infos kind) res ([], env) - in - Ctype.end_def (); - let res = List.rev_map (final_decl env ) res in - let decls = List.fold_right extract_type_decls res [] in - let decls = Typedecl.compute_variance_decls env decls in - let res = List.map2 merge_type_decls res decls in - let env = List.fold_left final_env env res in - let res = List.map (check_coercions env) res in - (res, env) - - -let class_description env sexpr = - let expr = class_type env sexpr in - (expr, expr.cltyp_type) - - - -let class_type_declarations env cls = - let (decls, env) = - type_classes approx_description class_description env cls - in - (List.map - (fun decl -> - {clsty_ty_id = decl.cls_ty_id; - clsty_id_loc = decl.cls_id_loc; - clsty_ty_decl = decl.cls_ty_decl; - clsty_obj_id = decl.cls_obj_id; - clsty_obj_abbr = decl.cls_obj_abbr; - clsty_typesharp_id = decl.cls_typesharp_id; - clsty_abbr = decl.cls_abbr; - clsty_info = decl.cls_info}) - decls, - env) - - - -(*******************************) - -(* Approximate the class declaration as class ['params] id = object end *) -let approx_class sdecl = - let open Ast_helper in - let self' = Typ.any () in - let clty' = Cty.signature ~loc:sdecl.pci_expr.pcty_loc (Csig.mk self' []) in - { sdecl with pci_expr = clty' } - -let approx_class_declarations env sdecls = - fst (class_type_declarations env (List.map approx_class sdecls)) - -(*******************************) - -(* Error report *) - -open Format - -let report_error env ppf = function - | Repeated_parameter -> - fprintf ppf "A type parameter occurs several times" - | Unconsistent_constraint trace -> - fprintf ppf "The class constraints are not consistent.@."; - Printtyp.report_unification_error ppf env trace - (fun ppf -> fprintf ppf "Type") - (fun ppf -> fprintf ppf "is not compatible with type") - | Field_type_mismatch (k, m, trace) -> - Printtyp.report_unification_error ppf env trace - (function ppf -> - fprintf ppf "The %s %s@ has type" k m) - (function ppf -> - fprintf ppf "but is expected to have type") - | Structure_expected clty -> - fprintf ppf - "@[This class expression is not a class structure; it has type@ %a@]" - Printtyp.class_type clty - | Pattern_type_clash ty -> - (* XXX Trace *) - (* XXX Revoir message d'erreur | Improve error message *) - Printtyp.reset_and_mark_loops ty; - fprintf ppf "@[%s@ %a@]" - "This pattern cannot match self: it only matches values of type" - Printtyp.type_expr ty - | Unbound_class_type_2 cl -> - fprintf ppf "@[The class type@ %a@ is not yet completely defined@]" - Printtyp.longident cl - | Abbrev_type_clash (abbrev, actual, expected) -> - (* XXX Afficher une trace ? | Print a trace? *) - Printtyp.reset_and_mark_loops_list [abbrev; actual; expected]; - fprintf ppf "@[The abbreviation@ %a@ expands to type@ %a@ \ - but is used with type@ %a@]" - Printtyp.type_expr abbrev - Printtyp.type_expr actual - Printtyp.type_expr expected - | Constructor_type_mismatch (c, trace) -> - Printtyp.report_unification_error ppf env trace - (function ppf -> - fprintf ppf "The expression \"new %s\" has type" c) - (function ppf -> - fprintf ppf "but is used with type") - | Virtual_class (cl, imm, mets, vals) -> - let print_mets ppf mets = - List.iter (function met -> fprintf ppf "@ %s" met) mets in - let missings = - match mets, vals with - [], _ -> "variables" - | _, [] -> "methods" - | _ -> "methods and variables" - in - let print_msg ppf = - if imm then fprintf ppf "This object has virtual %s" missings - else if cl then fprintf ppf "This class should be virtual" - else fprintf ppf "This class type should be virtual" - in - fprintf ppf - "@[%t.@ @[<2>The following %s are undefined :%a@]@]" - print_msg missings print_mets (mets @ vals) - | Parameter_arity_mismatch(lid, expected, provided) -> - fprintf ppf - "@[The class constructor %a@ expects %i type argument(s),@ \ - but is here applied to %i type argument(s)@]" - Printtyp.longident lid expected provided - | Parameter_mismatch trace -> - Printtyp.report_unification_error ppf env trace - (function ppf -> - fprintf ppf "The type parameter") - (function ppf -> - fprintf ppf "does not meet its constraint: it should be") - | Bad_parameters (id, params, cstrs) -> - Printtyp.reset_and_mark_loops_list [params; cstrs]; - fprintf ppf - "@[The abbreviation %a@ is used with parameters@ %a@ \ - which are incompatible with constraints@ %a@]" - Printtyp.ident id Printtyp.type_expr params Printtyp.type_expr cstrs - | Unbound_type_var (printer, reason) -> - let print_common ppf kind ty0 real lab ty = - let ty1 = - if real then ty0 else Btype.newgenty(Tobject(ty0, ref None)) in - List.iter Printtyp.mark_loops [ty; ty1]; - fprintf ppf - "The %s %s@ has type@;<1 2>%a@ where@ %a@ is unbound" - kind lab Printtyp.type_expr ty Printtyp.type_expr ty0 - in - let print_reason ppf = function - | Ctype.CC_Method (ty0, real, lab, ty) -> - print_common ppf "method" ty0 real lab ty - | Ctype.CC_Value (ty0, real, lab, ty) -> - print_common ppf "instance variable" ty0 real lab ty - in - Printtyp.reset (); - fprintf ppf - "@[@[Some type variables are unbound in this type:@;<1 2>%t@]@ \ - @[%a@]@]" - printer print_reason reason - | Non_generalizable_class (id, clty) -> - fprintf ppf - "@[The type of this class,@ %a,@ \ - contains type variables that cannot be generalized@]" - (Printtyp.class_declaration id) clty - | Cannot_coerce_self ty -> - fprintf ppf - "@[The type of self cannot be coerced to@ \ - the type of the current class:@ %a.@.\ - Some occurrences are contravariant@]" - Printtyp.type_scheme ty - | Non_collapsable_conjunction (id, clty, trace) -> - fprintf ppf - "@[The type of this class,@ %a,@ \ - contains non-collapsible conjunctive types in constraints@]" - (Printtyp.class_declaration id) clty; - Printtyp.report_unification_error ppf env trace - (fun ppf -> fprintf ppf "Type") - (fun ppf -> fprintf ppf "is not compatible with type") - | No_overriding (_, "") -> - fprintf ppf "@[This inheritance does not override any method@ %s@]" - "instance variable" - | No_overriding (kind, name) -> - fprintf ppf "@[The %s `%s'@ has no previous definition@]" kind name - -let report_error env ppf err = - Printtyp.wrap_printing_env env (fun () -> report_error env ppf err) - -let () = - Location.register_error_of_exn - (function - | Error (loc, env, err) -> - Some (Location.error_of_printer loc (report_error env) err) - | Error_forward err -> - Some err - | _ -> - None - ) diff --git a/jscomp/ml/typeclass.mli b/jscomp/ml/typeclass.mli deleted file mode 100644 index b31bff9192..0000000000 --- a/jscomp/ml/typeclass.mli +++ /dev/null @@ -1,65 +0,0 @@ -(**************************************************************************) -(* *) -(* OCaml *) -(* *) -(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 1996 Institut National de Recherche en Informatique et *) -(* en Automatique. *) -(* *) -(* All rights reserved. This file is distributed under the terms of *) -(* the GNU Lesser General Public License version 2.1, with the *) -(* special exception on linking described in the file LICENSE. *) -(* *) -(**************************************************************************) - -open Asttypes -open Types -open Format - -type 'a class_info = { - cls_id : Ident.t; - cls_id_loc : string loc; - cls_decl : class_declaration; - cls_ty_id : Ident.t; - cls_ty_decl : class_type_declaration; - cls_obj_id : Ident.t; - cls_obj_abbr : type_declaration; - cls_typesharp_id : Ident.t; - cls_abbr : type_declaration; - cls_arity : int; - cls_pub_methods : string list; - cls_info : 'a; -} - -type class_type_info = { - clsty_ty_id : Ident.t; - clsty_id_loc : string loc; - clsty_ty_decl : class_type_declaration; - clsty_obj_id : Ident.t; - clsty_obj_abbr : type_declaration; - clsty_typesharp_id : Ident.t; - clsty_abbr : type_declaration; - clsty_info : Typedtree.class_type_declaration; -} - - - - - -val class_type_declarations: - Env.t -> Parsetree.class_type_declaration list -> class_type_info list * Env.t - - -val approx_class_declarations: - Env.t -> Parsetree.class_type_declaration list -> class_type_info list - -val virtual_methods: Types.class_signature -> label list - - -type error - -exception Error of Location.t * Env.t * error -exception Error_forward of Location.error - -val report_error : Env.t -> formatter -> error -> unit diff --git a/jscomp/ml/typecore.ml b/jscomp/ml/typecore.ml index 499520e659..9972b08d4f 100644 --- a/jscomp/ml/typecore.ml +++ b/jscomp/ml/typecore.ml @@ -98,7 +98,7 @@ let type_open : let type_package = ref (fun _ -> assert false) -(* Forward declaration, to be filled in by Typeclass.class_structure *) +(* Forward declaration, to be filled in by Typemod.type_package *) (* Saving and outputting type information. @@ -200,7 +200,7 @@ let iter_expression f e = | Pstr_exception _ | Pstr_modtype _ | Pstr_open _ - | Pstr_class_type _ + | Pstr_class_type () | Pstr_attribute _ | Pstr_extension _ -> () | Pstr_include {pincl_mod = me} @@ -1638,7 +1638,7 @@ and is_nonexpansive_mod mexp = List.for_all (fun item -> match item.str_desc with | Tstr_eval _ | Tstr_primitive _ | Tstr_type _ - | Tstr_modtype _ | Tstr_open _ | Tstr_class_type _ -> true + | Tstr_modtype _ | Tstr_open _ | Tstr_class_type () -> true | Tstr_value (_, pat_exp_list) -> List.for_all (fun vb -> is_nonexpansive vb.vb_expr) pat_exp_list | Tstr_module {mb_expr=m;_} @@ -1654,7 +1654,7 @@ and is_nonexpansive_mod mexp = (function {ext_kind = Text_decl _} -> false | {ext_kind = Text_rebind _} -> true) te.tyext_constructors - | Tstr_class _ -> false (* could be more precise *) + | Tstr_class () -> assert false (* impossible *) | Tstr_attribute _ -> true ) str.str_items diff --git a/jscomp/ml/typecore.mli b/jscomp/ml/typecore.mli index 23cbeedb23..62206d0419 100644 --- a/jscomp/ml/typecore.mli +++ b/jscomp/ml/typecore.mli @@ -128,7 +128,7 @@ val type_open: (?used_slot:bool ref -> override_flag -> Env.t -> Location.t -> Longident.t loc -> Path.t * Env.t) ref -(* Forward declaration, to be filled in by Typeclass.class_structure *) +(* Forward declaration, to be filled in by Typemod.type_package *) val type_package: (Env.t -> Parsetree.module_expr -> Path.t -> Longident.t list -> Typedtree.module_expr * type_expr list) ref diff --git a/jscomp/ml/typedecl.ml b/jscomp/ml/typedecl.ml index f6fb1627b9..411e266974 100644 --- a/jscomp/ml/typedecl.ml +++ b/jscomp/ml/typedecl.ml @@ -1266,29 +1266,6 @@ let add_injectivity = | Invariant -> (false, false, false) ) -(* for typeclass.ml *) -let compute_variance_decls env cldecls = - let decls, required = - List.fold_right - (fun (obj_id, obj_abbr, _cl_abbr, _clty, _cltydef, ci) (decls, req) -> - let variance = List.map snd ci.ci_params in - (obj_id, obj_abbr) :: decls, - (add_injectivity variance, ci.ci_loc) :: req) - cldecls ([],[]) - in - let (decls, _) = - compute_properties_fixpoint env decls required - (List.map init_variance decls) - (List.map (fun _ -> false) decls) - in - List.map2 - (fun (_,decl) (_, _, cl_abbr, clty, cltydef, _) -> - let variance = decl.type_variance in - (decl, {cl_abbr with type_variance = variance}, - {clty with cty_variance = variance}, - {cltydef with clty_variance = variance})) - decls cldecls - (* Check multiple declarations of labels/constructors *) let check_duplicates sdecl_list = diff --git a/jscomp/ml/typedecl.mli b/jscomp/ml/typedecl.mli index 03f1b8bab2..7e76d3e32f 100644 --- a/jscomp/ml/typedecl.mli +++ b/jscomp/ml/typedecl.mli @@ -50,15 +50,6 @@ val check_coherence: (* for fixed types *) val is_fixed_type : Parsetree.type_declaration -> bool -(* for typeclass.ml *) -val compute_variance_decls: - Env.t -> - (Ident.t * Types.type_declaration * Types.type_declaration * - Types.class_declaration * Types.class_type_declaration * - 'a Typedtree.class_infos) list -> - (Types.type_declaration * Types.type_declaration * - Types.class_declaration * Types.class_type_declaration) list - (* for typeopt.ml *) val get_unboxed_type_representation: Env.t -> type_expr -> type_expr option diff --git a/jscomp/ml/typedtree.ml b/jscomp/ml/typedtree.ml index 5744f0dc60..7cb8d920ec 100644 --- a/jscomp/ml/typedtree.ml +++ b/jscomp/ml/typedtree.ml @@ -182,7 +182,7 @@ and structure_item_desc = | Tstr_modtype of module_type_declaration | Tstr_open of open_description | Tstr_class of unit - | Tstr_class_type of (Ident.t * string loc * class_type_declaration) list + | Tstr_class_type of unit | Tstr_include of include_declaration | Tstr_attribute of attribute @@ -260,7 +260,7 @@ and signature_item_desc = | Tsig_open of open_description | Tsig_include of include_description | Tsig_class of unit - | Tsig_class_type of class_type_declaration list + | Tsig_class_type of unit | Tsig_attribute of attribute and module_declaration = @@ -324,7 +324,7 @@ and core_type_desc = | Ttyp_tuple of core_type list | Ttyp_constr of Path.t * Longident.t loc * core_type list | Ttyp_object of object_field list * closed_flag - | Ttyp_class of Path.t * Longident.t loc * core_type list + | Ttyp_class of unit (* dummy AST node *) | Ttyp_alias of core_type * string | Ttyp_variant of row_field list * closed_flag * label list option | Ttyp_poly of string list * core_type @@ -422,62 +422,6 @@ and extension_constructor_kind = Text_decl of constructor_arguments * core_type option | Text_rebind of Path.t * Longident.t loc -and class_type = - { - cltyp_desc: class_type_desc; - cltyp_type: Types.class_type; - cltyp_env: Env.t; - cltyp_loc: Location.t; - cltyp_attributes: attribute list; - } - -and class_type_desc = - Tcty_constr of Path.t * Longident.t loc * core_type list - | Tcty_signature of class_signature - | Tcty_arrow of arg_label * core_type * class_type - | Tcty_open of override_flag * Path.t * Longident.t loc * Env.t * class_type - -and class_signature = { - csig_self: core_type; - csig_fields: class_type_field list; - csig_type: Types.class_signature; - } - -and class_type_field = { - ctf_desc: class_type_field_desc; - ctf_loc: Location.t; - ctf_attributes: attribute list; - } - -and class_type_field_desc = - | Tctf_inherit of class_type - | Tctf_val of (string * mutable_flag * virtual_flag * core_type) - | Tctf_method of (string * private_flag * virtual_flag * core_type) - | Tctf_constraint of (core_type * core_type) - | Tctf_attribute of attribute - - -and class_description = - class_type class_infos - -and class_type_declaration = - class_type class_infos - -and 'a class_infos = - { ci_virt: virtual_flag; - ci_params: (core_type * variance) list; - ci_id_name: string loc; - ci_id_class: Ident.t; - ci_id_class_type: Ident.t; - ci_id_object: Ident.t; - ci_id_typehash: Ident.t; - ci_expr: 'a; - ci_decl: Types.class_declaration; - ci_type_decl: Types.class_type_declaration; - ci_loc: Location.t; - ci_attributes: attribute list; - } - (* Auxiliary functions over the a.s.t. *) let iter_pattern_desc f = function diff --git a/jscomp/ml/typedtree.mli b/jscomp/ml/typedtree.mli index a4559f361e..80fc04c35b 100644 --- a/jscomp/ml/typedtree.mli +++ b/jscomp/ml/typedtree.mli @@ -299,7 +299,7 @@ and structure_item_desc = | Tstr_modtype of module_type_declaration | Tstr_open of open_description | Tstr_class of unit - | Tstr_class_type of (Ident.t * string loc * class_type_declaration) list + | Tstr_class_type of unit | Tstr_include of include_declaration | Tstr_attribute of attribute @@ -376,7 +376,7 @@ and signature_item_desc = | Tsig_open of open_description | Tsig_include of include_description | Tsig_class of unit - | Tsig_class_type of class_type_declaration list + | Tsig_class_type of unit | Tsig_attribute of attribute and module_declaration = @@ -441,7 +441,7 @@ and core_type_desc = | Ttyp_tuple of core_type list | Ttyp_constr of Path.t * Longident.t loc * core_type list | Ttyp_object of object_field list * closed_flag - | Ttyp_class of Path.t * Longident.t loc * core_type list + | Ttyp_class of unit (* dummy AST node *) | Ttyp_alias of core_type * string | Ttyp_variant of row_field list * closed_flag * label list option | Ttyp_poly of string list * core_type @@ -540,62 +540,6 @@ and extension_constructor_kind = Text_decl of constructor_arguments * core_type option | Text_rebind of Path.t * Longident.t loc -and class_type = - { - cltyp_desc: class_type_desc; - cltyp_type: Types.class_type; - cltyp_env: Env.t; - cltyp_loc: Location.t; - cltyp_attributes: attributes; - } - -and class_type_desc = - Tcty_constr of Path.t * Longident.t loc * core_type list - | Tcty_signature of class_signature - | Tcty_arrow of arg_label * core_type * class_type - | Tcty_open of override_flag * Path.t * Longident.t loc * Env.t * class_type - -and class_signature = { - csig_self : core_type; - csig_fields : class_type_field list; - csig_type : Types.class_signature; - } - -and class_type_field = { - ctf_desc: class_type_field_desc; - ctf_loc: Location.t; - ctf_attributes: attributes; - } - -and class_type_field_desc = - | Tctf_inherit of class_type - | Tctf_val of (string * mutable_flag * virtual_flag * core_type) - | Tctf_method of (string * private_flag * virtual_flag * core_type) - | Tctf_constraint of (core_type * core_type) - | Tctf_attribute of attribute - - -and class_description = - class_type class_infos - -and class_type_declaration = - class_type class_infos - -and 'a class_infos = - { ci_virt: virtual_flag; - ci_params: (core_type * variance) list; - ci_id_name : string loc; - ci_id_class: Ident.t; - ci_id_class_type : Ident.t; - ci_id_object : Ident.t; - ci_id_typehash : Ident.t; - ci_expr: 'a; - ci_decl: Types.class_declaration; - ci_type_decl : Types.class_type_declaration; - ci_loc: Location.t; - ci_attributes: attributes; - } - (* Auxiliary functions over the a.s.t. *) val iter_pattern_desc: (pattern -> unit) -> pattern_desc -> unit diff --git a/jscomp/ml/typedtreeIter.ml b/jscomp/ml/typedtreeIter.ml index 779a7c9276..6f37a07471 100644 --- a/jscomp/ml/typedtreeIter.ml +++ b/jscomp/ml/typedtreeIter.ml @@ -37,12 +37,7 @@ module type IteratorArgument = sig val enter_module_type : module_type -> unit val enter_module_expr : module_expr -> unit val enter_with_constraint : with_constraint -> unit - val enter_class_signature : class_signature -> unit - val enter_class_description : class_description -> unit - val enter_class_type_declaration : class_type_declaration -> unit - val enter_class_type : class_type -> unit - val enter_class_type_field : class_type_field -> unit val enter_core_type : core_type -> unit val enter_structure_item : structure_item -> unit @@ -60,12 +55,7 @@ module type IteratorArgument = sig val leave_module_type : module_type -> unit val leave_module_expr : module_expr -> unit val leave_with_constraint : with_constraint -> unit - val leave_class_signature : class_signature -> unit - val leave_class_description : class_description -> unit - val leave_class_type_declaration : class_type_declaration -> unit - val leave_class_type : class_type -> unit - val leave_class_type_field : class_type_field -> unit val leave_core_type : core_type -> unit val leave_structure_item : structure_item -> unit @@ -140,10 +130,7 @@ module MakeIterator(Iter : IteratorArgument) : sig | Tstr_modtype mtd -> iter_module_type_declaration mtd | Tstr_open _ -> () | Tstr_class () -> () - | Tstr_class_type list -> - List.iter - (fun (_, _, ct) -> iter_class_type_declaration ct) - list + | Tstr_class_type () -> () | Tstr_include incl -> iter_module_expr incl.incl_mod | Tstr_attribute _ -> () @@ -381,8 +368,7 @@ module MakeIterator(Iter : IteratorArgument) : sig | Tsig_open _ -> () | Tsig_include incl -> iter_module_type incl.incl_mod | Tsig_class () -> () - | Tsig_class_type list -> - List.iter iter_class_type_declaration list + | Tsig_class_type () -> () | Tsig_attribute _ -> () end; Iter.leave_signature_item item; @@ -397,13 +383,6 @@ module MakeIterator(Iter : IteratorArgument) : sig Iter.leave_module_type_declaration mtd - - and iter_class_type_declaration cd = - Iter.enter_class_type_declaration cd; - List.iter iter_type_parameter cd.ci_params; - iter_class_type cd.ci_expr; - Iter.leave_class_type_declaration cd; - and iter_module_type mty = Iter.enter_module_type mty; begin @@ -458,44 +437,6 @@ module MakeIterator(Iter : IteratorArgument) : sig Iter.leave_module_expr mexpr; - and iter_class_type ct = - Iter.enter_class_type ct; - begin - match ct.cltyp_desc with - Tcty_signature csg -> iter_class_signature csg - | Tcty_constr (_path, _, list) -> - List.iter iter_core_type list - | Tcty_arrow (_label, ct, cl) -> - iter_core_type ct; - iter_class_type cl - | Tcty_open (_, _, _, _, e) -> - iter_class_type e - end; - Iter.leave_class_type ct; - - and iter_class_signature cs = - Iter.enter_class_signature cs; - iter_core_type cs.csig_self; - List.iter iter_class_type_field cs.csig_fields; - Iter.leave_class_signature cs - - - and iter_class_type_field ctf = - Iter.enter_class_type_field ctf; - begin - match ctf.ctf_desc with - Tctf_inherit ct -> iter_class_type ct - | Tctf_val (_s, _mut, _virt, ct) -> - iter_core_type ct - | Tctf_method (_s, _priv, _virt, ct) -> - iter_core_type ct - | Tctf_constraint (ct1, ct2) -> - iter_core_type ct1; - iter_core_type ct2 - | Tctf_attribute _ -> () - end; - Iter.leave_class_type_field ctf - and iter_core_type ct = Iter.enter_core_type ct; begin @@ -510,8 +451,7 @@ module MakeIterator(Iter : IteratorArgument) : sig List.iter iter_core_type list | Ttyp_object (list, _o) -> List.iter iter_object_field list - | Ttyp_class (_path, _, list) -> - List.iter iter_core_type list + | Ttyp_class () -> () | Ttyp_alias (ct, _s) -> iter_core_type ct | Ttyp_variant (list, _bool, _labels) -> @@ -548,12 +488,7 @@ module DefaultIteratorArgument = struct let enter_module_type _ = () let enter_module_expr _ = () let enter_with_constraint _ = () - let enter_class_signature _ = () - let enter_class_description _ = () - let enter_class_type_declaration _ = () - let enter_class_type _ = () - let enter_class_type_field _ = () let enter_core_type _ = () let enter_structure_item _ = () @@ -571,12 +506,7 @@ module DefaultIteratorArgument = struct let leave_module_type _ = () let leave_module_expr _ = () let leave_with_constraint _ = () - let leave_class_signature _ = () - let leave_class_description _ = () - let leave_class_type_declaration _ = () - let leave_class_type _ = () - let leave_class_type_field _ = () let leave_core_type _ = () let leave_structure_item _ = () diff --git a/jscomp/ml/typedtreeIter.mli b/jscomp/ml/typedtreeIter.mli index b215c20d00..0d7461c0d8 100644 --- a/jscomp/ml/typedtreeIter.mli +++ b/jscomp/ml/typedtreeIter.mli @@ -31,11 +31,6 @@ module type IteratorArgument = sig val enter_module_type : module_type -> unit val enter_module_expr : module_expr -> unit val enter_with_constraint : with_constraint -> unit - val enter_class_signature : class_signature -> unit - val enter_class_description : class_description -> unit - val enter_class_type_declaration : class_type_declaration -> unit - val enter_class_type : class_type -> unit - val enter_class_type_field : class_type_field -> unit val enter_core_type : core_type -> unit val enter_structure_item : structure_item -> unit @@ -53,11 +48,6 @@ module type IteratorArgument = sig val leave_module_type : module_type -> unit val leave_module_expr : module_expr -> unit val leave_with_constraint : with_constraint -> unit - val leave_class_signature : class_signature -> unit - val leave_class_description : class_description -> unit - val leave_class_type_declaration : class_type_declaration -> unit - val leave_class_type : class_type -> unit - val leave_class_type_field : class_type_field -> unit val leave_core_type : core_type -> unit val leave_structure_item : structure_item -> unit diff --git a/jscomp/ml/typedtreeMap.ml b/jscomp/ml/typedtreeMap.ml index 7d4119b336..442968a69f 100644 --- a/jscomp/ml/typedtreeMap.ml +++ b/jscomp/ml/typedtreeMap.ml @@ -32,13 +32,7 @@ module type MapArgument = sig val enter_module_type : module_type -> module_type val enter_module_expr : module_expr -> module_expr val enter_with_constraint : with_constraint -> with_constraint - val enter_class_signature : class_signature -> class_signature - val enter_class_description : class_description -> class_description - val enter_class_type_declaration : - class_type_declaration -> class_type_declaration - val enter_class_type : class_type -> class_type - val enter_class_type_field : class_type_field -> class_type_field val enter_core_type : core_type -> core_type val enter_structure_item : structure_item -> structure_item @@ -58,13 +52,7 @@ module type MapArgument = sig val leave_module_type : module_type -> module_type val leave_module_expr : module_expr -> module_expr val leave_with_constraint : with_constraint -> with_constraint - val leave_class_signature : class_signature -> class_signature - val leave_class_description : class_description -> class_description - val leave_class_type_declaration : - class_type_declaration -> class_type_declaration - val leave_class_type : class_type -> class_type - val leave_class_type_field : class_type_field -> class_type_field val leave_core_type : core_type -> core_type val leave_structure_item : structure_item -> structure_item @@ -125,14 +113,7 @@ module MakeMap(Map : MapArgument) = struct Tstr_modtype (map_module_type_declaration mtd) | Tstr_open od -> Tstr_open od | Tstr_class () -> assert false - | Tstr_class_type list -> - let list = - List.map - (fun (id, name, ct) -> - id, name, map_class_type_declaration ct) - list - in - Tstr_class_type list + | Tstr_class_type () -> assert false | Tstr_include incl -> Tstr_include {incl with incl_mod = map_module_expr incl.incl_mod} | Tstr_attribute x -> Tstr_attribute x @@ -430,8 +411,7 @@ module MakeMap(Map : MapArgument) = struct | Tsig_include incl -> Tsig_include {incl with incl_mod = map_module_type incl.incl_mod} | Tsig_class () -> Tsig_class () - | Tsig_class_type list -> - Tsig_class_type (List.map map_class_type_declaration list) + | Tsig_class_type () -> Tsig_class_type () | Tsig_attribute _ as x -> x in Map.leave_signature_item { item with sig_desc = sig_desc } @@ -442,14 +422,6 @@ module MakeMap(Map : MapArgument) = struct Map.leave_module_type_declaration mtd - - and map_class_type_declaration cd = - let cd = Map.enter_class_type_declaration cd in - let ci_params = List.map map_type_parameter cd.ci_params in - let ci_expr = map_class_type cd.ci_expr in - Map.leave_class_type_declaration - { cd with ci_params = ci_params; ci_expr = ci_expr } - and map_module_type mty = let mty = Map.enter_module_type mty in let mty_desc = @@ -505,42 +477,6 @@ module MakeMap(Map : MapArgument) = struct in Map.leave_module_expr { mexpr with mod_desc = mod_desc } - and map_class_type ct = - let ct = Map.enter_class_type ct in - let cltyp_desc = - match ct.cltyp_desc with - Tcty_signature csg -> Tcty_signature (map_class_signature csg) - | Tcty_constr (path, lid, list) -> - Tcty_constr (path, lid, List.map map_core_type list) - | Tcty_arrow (label, ct, cl) -> - Tcty_arrow (label, map_core_type ct, map_class_type cl) - | Tcty_open (ovf, p, lid, env, e) -> - Tcty_open (ovf, p, lid, env, map_class_type e) - in - Map.leave_class_type { ct with cltyp_desc = cltyp_desc } - - and map_class_signature cs = - let cs = Map.enter_class_signature cs in - let csig_self = map_core_type cs.csig_self in - let csig_fields = List.map map_class_type_field cs.csig_fields in - Map.leave_class_signature { cs with - csig_self = csig_self; csig_fields = csig_fields } - - - and map_class_type_field ctf = - let ctf = Map.enter_class_type_field ctf in - let ctf_desc = - match ctf.ctf_desc with - Tctf_inherit ct -> Tctf_inherit (map_class_type ct) - | Tctf_val (s, mut, virt, ct) -> - Tctf_val (s, mut, virt, map_core_type ct) - | Tctf_method (s, priv, virt, ct) -> - Tctf_method (s, priv, virt, map_core_type ct) - | Tctf_constraint (ct1, ct2) -> - Tctf_constraint (map_core_type ct1, map_core_type ct2) - | Tctf_attribute _ as x -> x - in - Map.leave_class_type_field { ctf with ctf_desc = ctf_desc } and map_core_type ct = let ct = Map.enter_core_type ct in @@ -556,8 +492,8 @@ module MakeMap(Map : MapArgument) = struct | Ttyp_object (list, o) -> Ttyp_object (List.map map_object_field list, o) - | Ttyp_class (path, lid, list) -> - Ttyp_class (path, lid, List.map map_core_type list) + | Ttyp_class () -> + Ttyp_class () | Ttyp_alias (ct, s) -> Ttyp_alias (map_core_type ct, s) | Ttyp_variant (list, bool, labels) -> Ttyp_variant (List.map map_row_field list, bool, labels) @@ -597,12 +533,7 @@ module DefaultMapArgument = struct let enter_module_type t = t let enter_module_expr t = t let enter_with_constraint t = t - let enter_class_signature t = t - let enter_class_description t = t - let enter_class_type_declaration t = t - let enter_class_type t = t - let enter_class_type_field t = t let enter_core_type t = t let enter_structure_item t = t @@ -621,12 +552,7 @@ module DefaultMapArgument = struct let leave_module_type t = t let leave_module_expr t = t let leave_with_constraint t = t - let leave_class_signature t = t - let leave_class_description t = t - let leave_class_type_declaration t = t - let leave_class_type t = t - let leave_class_type_field t = t let leave_core_type t = t let leave_structure_item t = t diff --git a/jscomp/ml/typedtreeMap.mli b/jscomp/ml/typedtreeMap.mli index ca23e6210d..911d898ea8 100644 --- a/jscomp/ml/typedtreeMap.mli +++ b/jscomp/ml/typedtreeMap.mli @@ -32,12 +32,6 @@ module type MapArgument = sig val enter_module_type : module_type -> module_type val enter_module_expr : module_expr -> module_expr val enter_with_constraint : with_constraint -> with_constraint - val enter_class_signature : class_signature -> class_signature - val enter_class_description : class_description -> class_description - val enter_class_type_declaration : - class_type_declaration -> class_type_declaration - val enter_class_type : class_type -> class_type - val enter_class_type_field : class_type_field -> class_type_field val enter_core_type : core_type -> core_type val enter_structure_item : structure_item -> structure_item @@ -57,12 +51,6 @@ module type MapArgument = sig val leave_module_type : module_type -> module_type val leave_module_expr : module_expr -> module_expr val leave_with_constraint : with_constraint -> with_constraint - val leave_class_signature : class_signature -> class_signature - val leave_class_description : class_description -> class_description - val leave_class_type_declaration : - class_type_declaration -> class_type_declaration - val leave_class_type : class_type -> class_type - val leave_class_type_field : class_type_field -> class_type_field val leave_core_type : core_type -> core_type val leave_structure_item : structure_item -> structure_item diff --git a/jscomp/ml/typemod.ml b/jscomp/ml/typemod.ml index 76b9cf1e5a..0039f91583 100644 --- a/jscomp/ml/typemod.ml +++ b/jscomp/ml/typemod.ml @@ -577,17 +577,7 @@ and approx_sig env ssg = (extract_sig env smty.pmty_loc mty) in let newenv = Env.add_signature sg env in sg @ approx_sig newenv srem - | Psig_class_type sdecls -> - let decls = Typeclass.approx_class_declarations env sdecls in - let rem = approx_sig env srem in - List.flatten - (map_rec - (fun rs decl -> - let open Typeclass in - [Sig_class_type(decl.clsty_ty_id, decl.clsty_ty_decl, rs); - Sig_type(decl.clsty_obj_id, decl.clsty_obj_abbr, rs); - Sig_type(decl.clsty_typesharp_id, decl.clsty_abbr, rs)]) - decls [rem]) + | Psig_class_type () -> assert false | Psig_class () -> assert false | _ -> approx_sig env srem @@ -879,24 +869,7 @@ and transl_signature env sg = sg @ rem, final_env | Psig_class _ -> assert false - | Psig_class_type cl -> - List.iter - (fun {pci_name} -> check_name check_type names pci_name) - cl; - let (classes, newenv) = Typeclass.class_type_declarations env cl in - let (trem,rem, final_env) = transl_sig newenv srem in - mksig (Tsig_class_type - (List.map (fun decl -> decl.Typeclass.clsty_info) classes)) - env loc :: trem, - List.flatten - (map_rec - (fun rs decl -> - let open Typeclass in - [Sig_class_type(decl.clsty_ty_id, decl.clsty_ty_decl, rs); - Sig_type(decl.clsty_obj_id, decl.clsty_obj_abbr, rs); - Sig_type(decl.clsty_typesharp_id, decl.clsty_abbr, rs)]) - classes [rem]), - final_env + | Psig_class_type _ -> assert false | Psig_attribute x -> Builtin_attributes.warning_attribute x; let (trem,rem, final_env) = transl_sig env srem in @@ -1548,30 +1521,8 @@ and type_structure ?(toplevel = false) funct_body anchor env sstr scope = Tstr_open od, [], newenv | Pstr_class () -> assert false - | Pstr_class_type cl -> - List.iter - (fun {pci_name} -> check_name check_type names pci_name) - cl; - let (classes, new_env) = Typeclass.class_type_declarations env cl in - Tstr_class_type - (List.map (fun cl -> - (cl.Typeclass.clsty_ty_id, - cl.Typeclass.clsty_id_loc, - cl.Typeclass.clsty_info)) classes), -(* TODO: check with Jacques why this is here - Tstr_type - (List.map (fun (_, _, i, d, _, _) -> (i, d)) classes) :: - Tstr_type - (List.map (fun (_, _, _, _, i, d) -> (i, d)) classes) :: *) - List.flatten - (map_rec - (fun rs decl -> - let open Typeclass in - [Sig_class_type(decl.clsty_ty_id, decl.clsty_ty_decl, rs); - Sig_type(decl.clsty_obj_id, decl.clsty_obj_abbr, rs); - Sig_type(decl.clsty_typesharp_id, decl.clsty_abbr, rs)]) - classes []), - new_env + | Pstr_class_type () -> + assert false | Pstr_include sincl -> let smodl = sincl.pincl_mod in let modl = diff --git a/jscomp/ml/types.ml b/jscomp/ml/types.ml index 0c94b4bc67..9ecf09e178 100644 --- a/jscomp/ml/types.ml +++ b/jscomp/ml/types.ml @@ -209,37 +209,6 @@ and type_transparence = module Concr = Set.Make(OrderedString) -type class_type = - Cty_constr of Path.t * type_expr list * class_type - | Cty_signature of class_signature - | Cty_arrow of arg_label * type_expr * class_type - -and class_signature = - { csig_self: type_expr; - csig_vars: - (Asttypes.mutable_flag * Asttypes.virtual_flag * type_expr) Vars.t; - csig_concr: Concr.t; - csig_inher: (Path.t * type_expr list) list } - -type class_declaration = - { cty_params: type_expr list; - mutable cty_type: class_type; - cty_path: Path.t; - cty_new: type_expr option; - cty_variance: Variance.t list; - cty_loc: Location.t; - cty_attributes: Parsetree.attributes; - } - -type class_type_declaration = - { clty_params: type_expr list; - clty_type: class_type; - clty_path: Path.t; - clty_variance: Variance.t list; - clty_loc: Location.t; - clty_attributes: Parsetree.attributes; - } - (* Type expressions for the module language *) type module_type = @@ -261,7 +230,7 @@ and signature_item = | Sig_module of Ident.t * module_declaration * rec_status | Sig_modtype of Ident.t * modtype_declaration | Sig_class of unit - | Sig_class_type of Ident.t * class_type_declaration * rec_status + | Sig_class_type of unit (* Dummy AST node *) and module_declaration = { diff --git a/jscomp/ml/types.mli b/jscomp/ml/types.mli index eacf0b7d2b..213ae3b77b 100644 --- a/jscomp/ml/types.mli +++ b/jscomp/ml/types.mli @@ -361,37 +361,6 @@ and type_transparence = module Concr : Set.S with type elt = string -type class_type = - Cty_constr of Path.t * type_expr list * class_type - | Cty_signature of class_signature - | Cty_arrow of arg_label * type_expr * class_type - -and class_signature = - { csig_self: type_expr; - csig_vars: - (Asttypes.mutable_flag * Asttypes.virtual_flag * type_expr) Vars.t; - csig_concr: Concr.t; - csig_inher: (Path.t * type_expr list) list } - -type class_declaration = - { cty_params: type_expr list; - mutable cty_type: class_type; - cty_path: Path.t; - cty_new: type_expr option; - cty_variance: Variance.t list; - cty_loc: Location.t; - cty_attributes: Parsetree.attributes; - } - -type class_type_declaration = - { clty_params: type_expr list; - clty_type: class_type; - clty_path: Path.t; - clty_variance: Variance.t list; - clty_loc: Location.t; - clty_attributes: Parsetree.attributes; - } - (* Type expressions for the module language *) type module_type = @@ -413,7 +382,7 @@ and signature_item = | Sig_module of Ident.t * module_declaration * rec_status | Sig_modtype of Ident.t * modtype_declaration | Sig_class of unit - | Sig_class_type of Ident.t * class_type_declaration * rec_status + | Sig_class_type of unit (* Dummy AST node *) and module_declaration = { diff --git a/jscomp/ml/typetexp.ml b/jscomp/ml/typetexp.ml index 5e632574eb..fd97a71df9 100644 --- a/jscomp/ml/typetexp.ml +++ b/jscomp/ml/typetexp.ml @@ -18,7 +18,6 @@ (* Typechecking of type expressions for the core language *) open Asttypes -open Misc open Parsetree open Typedtree open Types @@ -49,9 +48,7 @@ type error = | Unbound_constructor of Longident.t | Unbound_label of Longident.t | Unbound_module of Longident.t - | Unbound_class of Longident.t | Unbound_modtype of Longident.t - | Unbound_cltype of Longident.t | Ill_typed_functor_application of Longident.t | Illegal_reference_to_recursive_module | Access_functor_as_structure of Longident.t @@ -145,12 +142,6 @@ let find_label = let find_all_labels = find_component Env.lookup_all_labels (fun lid -> Unbound_label lid) -let find_class env loc lid = - let (path, decl) as r = - find_component Env.lookup_class (fun lid -> Unbound_class lid) env loc lid - in - Builtin_attributes.check_deprecated loc decl.cty_attributes (Path.name path); - r let find_value env loc lid = Env.check_value_name (Longident.last lid) loc; @@ -178,14 +169,6 @@ let find_modtype env loc lid = Builtin_attributes.check_deprecated loc decl.mtd_attributes (Path.name path); r -let find_class_type env loc lid = - let (path, decl) as r = - find_component Env.lookup_cltype (fun lid -> Unbound_cltype lid) - env loc lid - in - Builtin_attributes.check_deprecated loc decl.clty_attributes (Path.name path); - r - let unbound_constructor_error env lid = narrow_unbound_lid_error env lid.loc lid.txt (fun lid -> Unbound_constructor lid) @@ -388,86 +371,7 @@ and transl_type_aux env policy styp = | Ptyp_object (fields, o) -> let ty, fields = transl_fields env policy o fields in ctyp (Ttyp_object (fields, o)) (newobj ty) - | Ptyp_class(lid, stl) -> - let (path, decl, _is_variant) = - try - let path = Env.lookup_type lid.txt env in - let decl = Env.find_type path env in - let rec check decl = - match decl.type_manifest with - None -> raise Not_found - | Some ty -> - match (repr ty).desc with - Tvariant row when Btype.static_row row -> () - | Tconstr (path, _, _) -> - check (Env.find_type path env) - | _ -> raise Not_found - in check decl; - Location.deprecated styp.ptyp_loc - "old syntax for polymorphic variant type"; - (path, decl,true) - with Not_found -> try - let lid2 = - match lid.txt with - Longident.Lident s -> Longident.Lident ("#" ^ s) - | Longident.Ldot(r, s) -> Longident.Ldot (r, "#" ^ s) - | Longident.Lapply(_, _) -> fatal_error "Typetexp.transl_type" - in - let path = Env.lookup_type lid2 env in - let decl = Env.find_type path env in - (path, decl, false) - with Not_found -> - ignore (find_class env lid.loc lid.txt); assert false - in - if List.length stl <> decl.type_arity then - raise(Error(styp.ptyp_loc, env, - Type_arity_mismatch(lid.txt, decl.type_arity, - List.length stl))); - let args = List.map (transl_type env policy) stl in - let params = instance_list decl.type_params in - List.iter2 - (fun (sty, cty) ty' -> - try unify_var env ty' cty.ctyp_type with Unify trace -> - raise (Error(sty.ptyp_loc, env, Type_mismatch (swap_list trace)))) - (List.combine stl args) params; - let ty_args = List.map (fun ctyp -> ctyp.ctyp_type) args in - let ty = - try Ctype.expand_head env (newconstr path ty_args) - with Unify trace -> - raise (Error(styp.ptyp_loc, env, Type_mismatch trace)) - in - let ty = match ty.desc with - Tvariant row -> - let row = Btype.row_repr row in - let fields = - List.map - (fun (l,f) -> l, - match Btype.row_field_repr f with - | Rpresent (Some ty) -> - Reither(false, [ty], false, ref None) - | Rpresent None -> - Reither (true, [], false, ref None) - | _ -> f) - row.row_fields - in - let row = { row_closed = true; row_fields = fields; - row_bound = (); row_name = Some (path, ty_args); - row_fixed = false; row_more = newvar () } in - let static = Btype.static_row row in - let row = - if static then { row with row_more = newty Tnil } - else if policy <> Univars then row - else { row with row_more = new_pre_univar () } - in - newty (Tvariant row) - | Tobject (fi, _) -> - let _, tv = flatten_fields fi in - if policy = Univars then pre_univars := tv :: !pre_univars; - ty - | _ -> - assert false - in - ctyp (Ttyp_class (path, lid, args)) ty + | Ptyp_class() -> assert false | Ptyp_alias(st, alias) -> let cty = try @@ -869,9 +773,7 @@ let fold_simple fold4 f = fold4 (fun name _path _descr acc -> f name acc) let fold_constructors = fold_descr Env.fold_constructors (fun d -> d.cstr_name) let fold_labels = fold_descr Env.fold_labels (fun d -> d.lbl_name) -let fold_classs = fold_simple Env.fold_classs let fold_modtypes = fold_simple Env.fold_modtypes -let fold_cltypes = fold_simple Env.fold_cltypes let report_error env ppf = function | Unbound_type_variable name -> @@ -1026,15 +928,9 @@ let report_error env ppf = function Printtyp.longident lid Printtyp.longident lid; spellcheck ppf fold_labels env lid; - | Unbound_class lid -> - fprintf ppf "Unbound class %a" longident lid; - spellcheck ppf fold_classs env lid; | Unbound_modtype lid -> fprintf ppf "Unbound module type %a" longident lid; spellcheck ppf fold_modtypes env lid; - | Unbound_cltype lid -> - fprintf ppf "Unbound class type %a" longident lid; - spellcheck ppf fold_cltypes env lid; | Ill_typed_functor_application lid -> fprintf ppf "Ill-typed functor application %a" longident lid | Illegal_reference_to_recursive_module -> diff --git a/jscomp/ml/typetexp.mli b/jscomp/ml/typetexp.mli index 165c17d45c..6b60749dc8 100644 --- a/jscomp/ml/typetexp.mli +++ b/jscomp/ml/typetexp.mli @@ -61,9 +61,7 @@ type error = | Unbound_constructor of Longident.t | Unbound_label of Longident.t | Unbound_module of Longident.t - | Unbound_class of Longident.t | Unbound_modtype of Longident.t - | Unbound_cltype of Longident.t | Ill_typed_functor_application of Longident.t | Illegal_reference_to_recursive_module | Access_functor_as_structure of Longident.t @@ -100,16 +98,12 @@ val find_all_labels: (label_description * (unit -> unit)) list val find_value: Env.t -> Location.t -> Longident.t -> Path.t * value_description -val find_class: - Env.t -> Location.t -> Longident.t -> Path.t * class_declaration val find_module: Env.t -> Location.t -> Longident.t -> Path.t * module_declaration val lookup_module: ?load:bool -> Env.t -> Location.t -> Longident.t -> Path.t val find_modtype: Env.t -> Location.t -> Longident.t -> Path.t * modtype_declaration -val find_class_type: - Env.t -> Location.t -> Longident.t -> Path.t * class_type_declaration val unbound_constructor_error: Env.t -> Longident.t Location.loc -> 'a val unbound_label_error: Env.t -> Longident.t Location.loc -> 'a diff --git a/jscomp/ml/untypeast.ml b/jscomp/ml/untypeast.ml index 17203b03dd..77823db52f 100644 --- a/jscomp/ml/untypeast.ml +++ b/jscomp/ml/untypeast.ml @@ -25,11 +25,6 @@ type mapper = { attributes: mapper -> T.attribute list -> attribute list; case: mapper -> T.case -> case; cases: mapper -> T.case list -> case list; - class_signature: mapper -> T.class_signature -> class_signature; - class_type: mapper -> T.class_type -> class_type; - class_type_declaration: mapper -> T.class_type_declaration - -> class_type_declaration; - class_type_field: mapper -> T.class_type_field -> class_type_field; constructor_declaration: mapper -> T.constructor_declaration -> constructor_declaration; expr: mapper -> T.expression -> expression; @@ -154,13 +149,10 @@ let structure_item sub item = Pstr_modtype (sub.module_type_declaration sub mtd) | Tstr_open od -> Pstr_open (sub.open_description sub od) - | Tstr_class _list -> + | Tstr_class () -> Pstr_class () - | Tstr_class_type list -> - Pstr_class_type - (List.map - (fun (_id, _name, ct) -> sub.class_type_declaration sub ct) - list) + | Tstr_class_type () -> + Pstr_class_type () | Tstr_include incl -> Pstr_include (sub.include_declaration sub incl) | Tstr_attribute x -> @@ -499,8 +491,8 @@ let signature_item sub item = Psig_include (sub.include_description sub incl) | Tsig_class () -> Psig_class () - | Tsig_class_type list -> - Psig_class_type (List.map (sub.class_type_declaration sub) list) + | Tsig_class_type () -> + Psig_class_type () | Tsig_attribute x -> Psig_attribute x in @@ -522,17 +514,6 @@ let include_infos f sub incl = let include_declaration sub = include_infos sub.module_expr sub let include_description sub = include_infos sub.module_type sub -let class_infos f sub ci = - let loc = sub.location sub ci.ci_loc in - let attrs = sub.attributes sub ci.ci_attributes in - Ci.mk ~loc ~attrs - ~virt:ci.ci_virt - ~params:(List.map (type_parameter sub) ci.ci_params) - (map_loc sub ci.ci_id_name) - (f sub ci.ci_expr) - -let class_type_declaration sub = class_infos sub.class_type sub - let module_type sub mty = let loc = sub.location sub mty.mty_loc in let attrs = sub.attributes sub mty.mty_attributes in @@ -589,42 +570,6 @@ let module_expr sub mexpr = Mod.mk ~loc ~attrs desc - -let class_type sub ct = - let loc = sub.location sub ct.cltyp_loc in - let attrs = sub.attributes sub ct.cltyp_attributes in - let desc = match ct.cltyp_desc with - Tcty_signature csg -> Pcty_signature (sub.class_signature sub csg) - | Tcty_constr (_path, lid, list) -> - Pcty_constr (map_loc sub lid, List.map (sub.typ sub) list) - | Tcty_arrow (label, ct, cl) -> - Pcty_arrow (label, sub.typ sub ct, sub.class_type sub cl) - | Tcty_open (ovf, _p, lid, _env, e) -> - Pcty_open (ovf, lid, sub.class_type sub e) - in - Cty.mk ~loc ~attrs desc - -let class_signature sub cs = - { - pcsig_self = sub.typ sub cs.csig_self; - pcsig_fields = List.map (sub.class_type_field sub) cs.csig_fields; - } - -let class_type_field sub ctf = - let loc = sub.location sub ctf.ctf_loc in - let attrs = sub.attributes sub ctf.ctf_attributes in - let desc = match ctf.ctf_desc with - Tctf_inherit ct -> Pctf_inherit (sub.class_type sub ct) - | Tctf_val (s, mut, virt, ct) -> - Pctf_val (mkloc s loc, mut, virt, sub.typ sub ct) - | Tctf_method (s, priv, virt, ct) -> - Pctf_method (mkloc s loc, priv, virt, sub.typ sub ct) - | Tctf_constraint (ct1, ct2) -> - Pctf_constraint (sub.typ sub ct1, sub.typ sub ct2) - | Tctf_attribute x -> Pctf_attribute x - in - Ctf.mk ~loc ~attrs desc - let core_type sub ct = let loc = sub.location sub ct.ctyp_loc in let attrs = sub.attributes sub ct.ctyp_attributes in @@ -640,8 +585,8 @@ let core_type sub ct = | Ttyp_object (list, o) -> Ptyp_object (List.map (sub.object_field sub) list, o) - | Ttyp_class (_path, lid, list) -> - Ptyp_class (map_loc sub lid, List.map (sub.typ sub) list) + | Ttyp_class () -> + Ptyp_class () | Ttyp_alias (ct, s) -> Ptyp_alias (sub.typ sub ct, s) | Ttyp_variant (list, bool, labels) -> @@ -681,10 +626,6 @@ let default_mapper = signature_item = signature_item; module_type = module_type; with_constraint = with_constraint; - class_type = class_type; - class_type_field = class_type_field; - class_signature = class_signature; - class_type_declaration = class_type_declaration; type_declaration = type_declaration; type_kind = type_kind; typ = core_type; diff --git a/jscomp/ml/untypeast.mli b/jscomp/ml/untypeast.mli index d6bfdd05c1..a47df546d4 100644 --- a/jscomp/ml/untypeast.mli +++ b/jscomp/ml/untypeast.mli @@ -22,11 +22,6 @@ type mapper = { attributes: mapper -> Typedtree.attribute list -> attribute list; case: mapper -> Typedtree.case -> case; cases: mapper -> Typedtree.case list -> case list; - class_signature: mapper -> Typedtree.class_signature -> class_signature; - class_type: mapper -> Typedtree.class_type -> class_type; - class_type_declaration: mapper -> Typedtree.class_type_declaration - -> class_type_declaration; - class_type_field: mapper -> Typedtree.class_type_field -> class_type_field; constructor_declaration: mapper -> Typedtree.constructor_declaration -> constructor_declaration; expr: mapper -> Typedtree.expression -> expression; diff --git a/jscomp/syntax/src/res_ast_debugger.ml b/jscomp/syntax/src/res_ast_debugger.ml index 569026d621..7c6b5d3237 100644 --- a/jscomp/syntax/src/res_ast_debugger.ml +++ b/jscomp/syntax/src/res_ast_debugger.ml @@ -883,13 +883,7 @@ module SexpAst = struct closed_flag flag; Sexp.list (map_empty ~f:object_field fields); ] - | Ptyp_class (longident_loc, types) -> - Sexp.list - [ - Sexp.atom "Ptyp_class"; - longident longident_loc.Location.txt; - Sexp.list (map_empty ~f:core_type types); - ] + | Ptyp_class () -> assert false | Ptyp_variant (fields, flag, opt_labels) -> Sexp.list [ diff --git a/jscomp/test/ocaml_re_test.js b/jscomp/test/ocaml_re_test.js index 6c26fe0756..86daf05311 100644 --- a/jscomp/test/ocaml_re_test.js +++ b/jscomp/test/ocaml_re_test.js @@ -3429,6 +3429,116 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { }; } }; + let regexp$p = function (_left) { + while(true) { + let left = _left; + if (!accept(/* '|' */124)) { + return left; + } + _left = alt$1({ + hd: left, + tl: { + hd: branch$p(/* [] */0), + tl: /* [] */0 + } + }); + continue; + }; + }; + let branch$p = function (_left) { + while(true) { + let left = _left; + if (i.contents === l || test(/* '|' */124) || test(/* ')' */41)) { + return seq$2(List.rev(left)); + } + _left = { + hd: piece(), + tl: left + }; + continue; + }; + }; + let bracket = function (_s) { + while(true) { + let s = _s; + if (s !== /* [] */0 && accept(/* ']' */93)) { + return s; + } + let match = $$char(); + if (match.NAME === "Char") { + let c = match.VAL; + if (accept(/* '-' */45)) { + if (accept(/* ']' */93)) { + return { + hd: { + TAG: "Set", + _0: single(c) + }, + tl: { + hd: { + TAG: "Set", + _0: { + hd: [ + /* '-' */45, + /* '-' */45 + ], + tl: /* [] */0 + } + }, + tl: s + } + }; + } + let match$1 = $$char(); + if (match$1.NAME !== "Char") { + return { + hd: { + TAG: "Set", + _0: single(c) + }, + tl: { + hd: { + TAG: "Set", + _0: { + hd: [ + /* '-' */45, + /* '-' */45 + ], + tl: /* [] */0 + } + }, + tl: { + hd: match$1.VAL, + tl: s + } + } + }; + } + _s = { + hd: { + TAG: "Set", + _0: seq(c, match$1.VAL) + }, + tl: s + }; + continue; + } + _s = { + hd: { + TAG: "Set", + _0: single(c) + }, + tl: s + }; + continue; + } + _s = { + hd: match.VAL, + tl: s + }; + continue; + }; + }; let atom = function (param) { if (accept(/* '.' */46)) { if (dotall) { @@ -3733,6 +3843,42 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { }; } }; + let piece = function (param) { + let r = atom(); + if (accept(/* '*' */42)) { + return greedy_mod(repn(r, 0, undefined)); + } + if (accept(/* '+' */43)) { + return greedy_mod(repn(r, 1, undefined)); + } + if (accept(/* '?' */63)) { + return greedy_mod(repn(r, 0, 1)); + } + if (!accept(/* '{' */123)) { + return r; + } + let i$1 = integer(); + if (i$1 !== undefined) { + let j = accept(/* ',' */44) ? integer() : i$1; + if (!accept(/* '}' */125)) { + throw new Error(Parse_error, { + cause: { + RE_EXN_ID: Parse_error + } + }); + } + if (j !== undefined && j < i$1) { + throw new Error(Parse_error, { + cause: { + RE_EXN_ID: Parse_error + } + }); + } + return greedy_mod(repn(r, i$1, j)); + } + i.contents = i.contents - 1 | 0; + return r; + }; let $$char = function (param) { if (i.contents === l) { throw new Error(Parse_error, { @@ -4039,152 +4185,6 @@ function parse(multiline, dollar_endonly, dotall, ungreedy, s) { }; } }; - let bracket = function (_s) { - while(true) { - let s = _s; - if (s !== /* [] */0 && accept(/* ']' */93)) { - return s; - } - let match = $$char(); - if (match.NAME === "Char") { - let c = match.VAL; - if (accept(/* '-' */45)) { - if (accept(/* ']' */93)) { - return { - hd: { - TAG: "Set", - _0: single(c) - }, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '-' */45, - /* '-' */45 - ], - tl: /* [] */0 - } - }, - tl: s - } - }; - } - let match$1 = $$char(); - if (match$1.NAME !== "Char") { - return { - hd: { - TAG: "Set", - _0: single(c) - }, - tl: { - hd: { - TAG: "Set", - _0: { - hd: [ - /* '-' */45, - /* '-' */45 - ], - tl: /* [] */0 - } - }, - tl: { - hd: match$1.VAL, - tl: s - } - } - }; - } - _s = { - hd: { - TAG: "Set", - _0: seq(c, match$1.VAL) - }, - tl: s - }; - continue; - } - _s = { - hd: { - TAG: "Set", - _0: single(c) - }, - tl: s - }; - continue; - } - _s = { - hd: match.VAL, - tl: s - }; - continue; - }; - }; - let piece = function (param) { - let r = atom(); - if (accept(/* '*' */42)) { - return greedy_mod(repn(r, 0, undefined)); - } - if (accept(/* '+' */43)) { - return greedy_mod(repn(r, 1, undefined)); - } - if (accept(/* '?' */63)) { - return greedy_mod(repn(r, 0, 1)); - } - if (!accept(/* '{' */123)) { - return r; - } - let i$1 = integer(); - if (i$1 !== undefined) { - let j = accept(/* ',' */44) ? integer() : i$1; - if (!accept(/* '}' */125)) { - throw new Error(Parse_error, { - cause: { - RE_EXN_ID: Parse_error - } - }); - } - if (j !== undefined && j < i$1) { - throw new Error(Parse_error, { - cause: { - RE_EXN_ID: Parse_error - } - }); - } - return greedy_mod(repn(r, i$1, j)); - } - i.contents = i.contents - 1 | 0; - return r; - }; - let branch$p = function (_left) { - while(true) { - let left = _left; - if (i.contents === l || test(/* '|' */124) || test(/* ')' */41)) { - return seq$2(List.rev(left)); - } - _left = { - hd: piece(), - tl: left - }; - continue; - }; - }; - let regexp$p = function (_left) { - while(true) { - let left = _left; - if (!accept(/* '|' */124)) { - return left; - } - _left = alt$1({ - hd: left, - tl: { - hd: branch$p(/* [] */0), - tl: /* [] */0 - } - }); - continue; - }; - }; let res = regexp$p(branch$p(/* [] */0)); if (i.contents !== l) { throw new Error(Parse_error, { diff --git a/jscomp/test/stream_parser_test.js b/jscomp/test/stream_parser_test.js index 0c00b53845..9a66bed2cd 100644 --- a/jscomp/test/stream_parser_test.js +++ b/jscomp/test/stream_parser_test.js @@ -168,28 +168,6 @@ function l_parse(token) { }; } }; - let parse_f_aux = function (_a) { - while(true) { - let a = _a; - let t = token$1(); - if (t.TAG === "Kwd") { - switch (t._0) { - case "*" : - _a = Math.imul(a, parse_f()); - continue; - case "/" : - _a = Caml_int32.div(a, parse_f()); - continue; - default: - Queue.push(t, look_ahead); - return a; - } - } else { - Queue.push(t, look_ahead); - return a; - } - }; - }; let parse_f = function (param) { let i = token$1(); switch (i.TAG) { @@ -232,6 +210,28 @@ function l_parse(token) { }); } }; + let parse_f_aux = function (_a) { + while(true) { + let a = _a; + let t = token$1(); + if (t.TAG === "Kwd") { + switch (t._0) { + case "*" : + _a = Math.imul(a, parse_f()); + continue; + case "/" : + _a = Caml_int32.div(a, parse_f()); + continue; + default: + Queue.push(t, look_ahead); + return a; + } + } else { + Queue.push(t, look_ahead); + return a; + } + }; + }; let parse_t_aux = function (_a) { while(true) { let a = _a; diff --git a/lib/es6/belt_internalBuckets.js b/lib/es6/belt_internalBuckets.js index c78b17f237..b53115008c 100644 --- a/lib/es6/belt_internalBuckets.js +++ b/lib/es6/belt_internalBuckets.js @@ -4,19 +4,6 @@ import * as Curry from "./curry.js"; import * as Belt_Array from "./belt_Array.js"; import * as Caml_option from "./caml_option.js"; -function copyBucket(c) { - if (c === undefined) { - return c; - } - let head = { - key: c.key, - value: c.value, - next: undefined - }; - copyAuxCont(c.next, head); - return head; -} - function copyAuxCont(_c, _prec) { while(true) { let prec = _prec; @@ -36,6 +23,19 @@ function copyAuxCont(_c, _prec) { }; } +function copyBucket(c) { + if (c === undefined) { + return c; + } + let head = { + key: c.key, + value: c.value, + next: undefined + }; + copyAuxCont(c.next, head); + return head; +} + function copyBuckets(buckets) { let len = buckets.length; let newBuckets = new Array(len); diff --git a/lib/es6/belt_internalSetBuckets.js b/lib/es6/belt_internalSetBuckets.js index 191dcb2d82..8361cd1676 100644 --- a/lib/es6/belt_internalSetBuckets.js +++ b/lib/es6/belt_internalSetBuckets.js @@ -3,6 +3,18 @@ import * as Curry from "./curry.js"; import * as Belt_Array from "./belt_Array.js"; +function copyBucket(c) { + if (c === undefined) { + return c; + } + let head = { + key: c.key, + next: undefined + }; + copyAuxCont(c.next, head); + return head; +} + function copyAuxCont(_c, _prec) { while(true) { let prec = _prec; @@ -21,18 +33,6 @@ function copyAuxCont(_c, _prec) { }; } -function copyBucket(c) { - if (c === undefined) { - return c; - } - let head = { - key: c.key, - next: undefined - }; - copyAuxCont(c.next, head); - return head; -} - function copyBuckets(buckets) { let len = buckets.length; let newBuckets = new Array(len); diff --git a/lib/js/belt_internalBuckets.js b/lib/js/belt_internalBuckets.js index eb5269f858..919160b77f 100644 --- a/lib/js/belt_internalBuckets.js +++ b/lib/js/belt_internalBuckets.js @@ -4,19 +4,6 @@ let Curry = require("./curry.js"); let Belt_Array = require("./belt_Array.js"); let Caml_option = require("./caml_option.js"); -function copyBucket(c) { - if (c === undefined) { - return c; - } - let head = { - key: c.key, - value: c.value, - next: undefined - }; - copyAuxCont(c.next, head); - return head; -} - function copyAuxCont(_c, _prec) { while(true) { let prec = _prec; @@ -36,6 +23,19 @@ function copyAuxCont(_c, _prec) { }; } +function copyBucket(c) { + if (c === undefined) { + return c; + } + let head = { + key: c.key, + value: c.value, + next: undefined + }; + copyAuxCont(c.next, head); + return head; +} + function copyBuckets(buckets) { let len = buckets.length; let newBuckets = new Array(len); diff --git a/lib/js/belt_internalSetBuckets.js b/lib/js/belt_internalSetBuckets.js index 8e2bf8ff4f..400900178c 100644 --- a/lib/js/belt_internalSetBuckets.js +++ b/lib/js/belt_internalSetBuckets.js @@ -3,6 +3,18 @@ let Curry = require("./curry.js"); let Belt_Array = require("./belt_Array.js"); +function copyBucket(c) { + if (c === undefined) { + return c; + } + let head = { + key: c.key, + next: undefined + }; + copyAuxCont(c.next, head); + return head; +} + function copyAuxCont(_c, _prec) { while(true) { let prec = _prec; @@ -21,18 +33,6 @@ function copyAuxCont(_c, _prec) { }; } -function copyBucket(c) { - if (c === undefined) { - return c; - } - let head = { - key: c.key, - next: undefined - }; - copyAuxCont(c.next, head); - return head; -} - function copyBuckets(buckets) { let len = buckets.length; let newBuckets = new Array(len);