summaryrefslogtreecommitdiff
path: root/typing/types.ml
diff options
context:
space:
mode:
authorThomas Refis <thomas.refis@gmail.com>2021-02-25 16:17:53 +0100
committerLeo White <leo@lpw25.net>2021-07-14 13:40:29 +0100
commit845ac93066a179c2e7778d75f70b3cf2fa1f772f (patch)
tree7192c485ec4da3eef202028b529ca154e2a5eb1c /typing/types.ml
parent8f9b7667abe5c780545851c30108d6719fddcf30 (diff)
downloadocaml-845ac93066a179c2e7778d75f70b3cf2fa1f772f.tar.gz
Treat class_signature more like type_expr
Treat class_signature more like type_expr by making all its components mutable and using three unification-like operations for manipulating them: add_method, add_instance_variable and inherit_class_signature. These operations behave similarly to filter_self_method, which they replace. We move much of the logic for handling class_signature into Btype and Ctype and use it for the typing of class signatures and class structures. Instead of using method and variable tables with both identifiers and type components as accumulators during class structure typing, we use tables with just identifiers along with a single class_signature. This makes the logic clearer and makes it easier to share things with the typing of class signatures.
Diffstat (limited to 'typing/types.ml')
-rw-r--r--typing/types.ml28
1 files changed, 13 insertions, 15 deletions
diff --git a/typing/types.ml b/typing/types.ml
index 0499ba6152..94028683ab 100644
--- a/typing/types.ml
+++ b/typing/types.ml
@@ -138,6 +138,7 @@ end
module Meths = Misc.Stdlib.String.Map
module Vars = Meths
+
(* Value descriptions *)
type value_description =
@@ -153,17 +154,21 @@ and value_kind =
| Val_prim of Primitive.description (* Primitive *)
| Val_ivar of mutable_flag * string (* Instance variable (mutable ?) *)
| Val_self of
- self_var_kind *
- (Ident.t * mutable_flag * virtual_flag * type_expr) Vars.t *
- string
+ class_signature * self_meths * Ident.t Vars.t * string
(* Self *)
- | Val_anc of (Ident.t * type_expr) Meths.t * string
+ | Val_anc of class_signature * Ident.t Meths.t * string
(* Ancestor *)
-and self_var_kind =
- | Self_concrete of (Ident.t * private_flag * virtual_flag * type_expr) Meths.t
- | Self_virtual of
- (Ident.t * private_flag * virtual_flag * type_expr) Meths.t ref * type_expr
+and self_meths =
+ | Self_concrete of Ident.t Meths.t
+ | Self_virtual of Ident.t Meths.t ref
+
+and class_signature =
+ { csig_self: type_expr;
+ mutable csig_self_row: type_expr;
+ mutable csig_vars: (mutable_flag * virtual_flag * type_expr) Vars.t;
+ mutable csig_meths: (private_flag * virtual_flag * type_expr) Meths.t;
+ mutable csig_inher: (Path.t * type_expr list) list }
(* Variance *)
@@ -312,13 +317,6 @@ type class_type =
| Cty_signature of class_signature
| Cty_arrow of arg_label * type_expr * class_type
-and class_signature =
- { csig_self: type_expr;
- mutable csig_self_row: type_expr;
- csig_vars: (mutable_flag * virtual_flag * type_expr) Vars.t;
- mutable csig_meths: (private_flag * virtual_flag * type_expr) Meths.t;
- csig_inher: (Path.t * type_expr list) list }
-
type class_declaration =
{ cty_params: type_expr list;
mutable cty_type: class_type;