Module Ctype

exception Unify of Errortrace.unification_error
exception Equality of Errortrace.equality_error
exception Moregen of Errortrace.moregen_error
exception Subtype of Errortrace.Subtype.error
exception Tags of Asttypes.label * Asttypes.label
exception Cannot_expand
exception Cannot_apply
exception Matches_failure of Env.t * Errortrace.unification_error
exception Incompatible
val init_def : int -> unit
val begin_def : unit -> unit
val end_def : unit -> unit
val begin_class_def : unit -> unit
val raise_nongen_level : unit -> unit
val reset_global_level : unit -> unit
val increase_global_level : unit -> int
val restore_global_level : int -> unit
type levels = {
  1. current_level : int;
  2. nongen_level : int;
  3. global_level : int;
  4. saved_level : (int * int) list;
}
val save_levels : unit -> levels
val set_levels : levels -> unit
val create_scope : unit -> int
val new_scoped_ty : int -> Types.type_desc -> Types.type_expr
val newvar : ?name:string -> unit -> Types.type_expr
val newvar2 : ?name:string -> int -> Types.type_expr
val new_global_var : ?name:string -> unit -> Types.type_expr
val newconstr : Path.t -> Types.type_expr list -> Types.type_expr
val none : Types.type_expr
val object_fields : Types.type_expr -> Types.type_expr
val flatten_fields : Types.type_expr -> (string * Types.field_kind * Types.type_expr) list * Types.type_expr

Transform a field type into a list of pairs label-type. The fields are sorted.

Beware of the interaction with GADTs:

Due to the introduction of object indexes for GADTs, the row variable of an object may now be an expansible type abbreviation. A first consequence is that flatten_fields will not completely flatten the object, since the type abbreviation will not be expanded (flatten_fields does not receive the current environment). Another consequence is that various functions may be called with the expansion of this type abbreviation, which is a Tfield, e.g. during printing.

Concrete problems have been fixed, but new bugs may appear in the future. (Test cases were added to typing-gadts/test.ml)

val associate_fields : (string * Types.field_kind * Types.type_expr) list -> (string * Types.field_kind * Types.type_expr) list -> (string * Types.field_kind * Types.type_expr * Types.field_kind * Types.type_expr) list * (string * Types.field_kind * Types.type_expr) list * (string * Types.field_kind * Types.type_expr) list
val opened_object : Types.type_expr -> bool
val set_object_name : Ident.t -> Types.type_expr list -> Types.type_expr -> unit
val remove_object_name : Types.type_expr -> unit
val find_cltype_for_path : Env.t -> Path.t -> Types.type_declaration * Types.type_expr
val sort_row_fields : (Asttypes.label * Types.row_field) list -> (Asttypes.label * Types.row_field) list
val filter_row_fields : bool -> (Asttypes.label * Types.row_field) list -> (Asttypes.label * Types.row_field) list
val generalize : Types.type_expr -> unit
val lower_contravariant : Env.t -> Types.type_expr -> unit
val lower_variables_only : Env.t -> int -> Types.type_expr -> unit
val generalize_structure : Types.type_expr -> unit
val generalize_class_type : Types.class_type -> unit
val generalize_class_type_structure : Types.class_type -> unit
val generalize_class_signature_spine : Env.t -> Types.class_signature -> unit
val correct_levels : Types.type_expr -> Types.type_expr
val limited_generalize : Types.type_expr -> Types.type_expr -> unit
val limited_generalize_class_type : Types.type_expr -> Types.class_type -> unit
val fully_generic : Types.type_expr -> bool
val check_scope_escape : Env.t -> int -> Types.type_expr -> unit
val instance : ?partial:bool -> Types.type_expr -> Types.type_expr
val generic_instance : Types.type_expr -> Types.type_expr
val instance_list : Types.type_expr list -> Types.type_expr list
val new_local_type : ?loc:Location.t -> ?manifest_and_scope:(Types.type_expr * int) -> unit -> Types.type_declaration
val existential_name : Types.constructor_description -> Types.type_expr -> string
val instance_constructor : ?in_pattern:(Env.t ref * int) -> Types.constructor_description -> Types.type_expr list * Types.type_expr * Types.type_expr list
val instance_parameterized_type : ?keep_names:bool -> Types.type_expr list -> Types.type_expr -> Types.type_expr list * Types.type_expr
val instance_parameterized_type_2 : Types.type_expr list -> Types.type_expr list -> Types.type_expr -> Types.type_expr list * Types.type_expr list * Types.type_expr
val instance_declaration : Types.type_declaration -> Types.type_declaration
val generic_instance_declaration : Types.type_declaration -> Types.type_declaration
val instance_class : Types.type_expr list -> Types.class_type -> Types.type_expr list * Types.class_type
val instance_poly : ?keep_names:bool -> bool -> Types.type_expr list -> Types.type_expr -> Types.type_expr list * Types.type_expr
val polyfy : Env.t -> Types.type_expr -> Types.type_expr list -> Types.type_expr * bool
val try_expand_once_opt : Env.t -> Types.type_expr -> Types.type_expr
val try_expand_safe_opt : Env.t -> Types.type_expr -> Types.type_expr
val expand_head_once : Env.t -> Types.type_expr -> Types.type_expr
val expand_head : Env.t -> Types.type_expr -> Types.type_expr
val expand_head_opt : Env.t -> Types.type_expr -> Types.type_expr

The compiler's own version of expand_head necessary for type-based optimisations.

Expansion of types for error traces; lives here instead of in Errortrace because the expansion machinery lives here.

val expanded_diff : Env.t -> got:Types.type_expr -> expected:Types.type_expr -> (Errortrace.expanded_type, 'variant) Errortrace.elt

Create an Errortrace.Diff by expanding the two types

val unexpanded_diff : got:Types.type_expr -> expected:Types.type_expr -> (Errortrace.expanded_type, 'variant) Errortrace.elt

Create an Errortrace.Diff by *duplicating* the two types, so that each one's expansion is identical to itself. Despite the name, does create Errortrace.expanded_types.

val full_expand : may_forget_scope:bool -> Env.t -> Types.type_expr -> Types.type_expr
type typedecl_extraction_result =
  1. | Typedecl of Path.t * Path.t * Types.type_declaration
  2. | Has_no_typedecl
  3. | May_have_typedecl
val extract_concrete_typedecl : Env.t -> Types.type_expr -> typedecl_extraction_result
val unify : Env.t -> Types.type_expr -> Types.type_expr -> unit
val unify_gadt : equations_level:int -> allow_recursive:bool -> Env.t ref -> Types.type_expr -> Types.type_expr -> Btype.TypePairs.t
val unify_var : Env.t -> Types.type_expr -> Types.type_expr -> unit
val filter_method : Env.t -> string -> Types.type_expr -> Types.type_expr
val occur_in : Env.t -> Types.type_expr -> Types.type_expr -> bool
val deep_occur : Types.type_expr -> Types.type_expr -> bool
val moregeneral : Env.t -> bool -> Types.type_expr -> Types.type_expr -> unit
val is_moregeneral : Env.t -> bool -> Types.type_expr -> Types.type_expr -> bool
val rigidify : Types.type_expr -> Types.type_expr list
val all_distinct_vars : Env.t -> Types.type_expr list -> bool
val matches : expand_error_trace:bool -> Env.t -> Types.type_expr -> Types.type_expr -> unit
val does_match : Env.t -> Types.type_expr -> Types.type_expr -> bool
val reify_univars : Env.t -> Types.type_expr -> Types.type_expr
type filter_arrow_failure =
  1. | Unification_error of Errortrace.unification_error
  2. | Label_mismatch of {
    1. got : Asttypes.arg_label;
    2. expected : Asttypes.arg_label;
    3. expected_type : Types.type_expr;
    }
  3. | Not_a_function
exception Filter_arrow_failed of filter_arrow_failure
type filter_method_failure =
  1. | Unification_error of Errortrace.unification_error
  2. | Not_a_method
  3. | Not_an_object of Types.type_expr
exception Filter_method_failed of filter_method_failure
type class_match_failure =
  1. | CM_Virtual_class
  2. | CM_Parameter_arity_mismatch of int * int
  3. | CM_Type_parameter_mismatch of Env.t * Errortrace.equality_error
  4. | CM_Class_type_mismatch of Env.t * Types.class_type * Types.class_type
  5. | CM_Parameter_mismatch of Env.t * Errortrace.moregen_error
  6. | CM_Val_type_mismatch of string * Env.t * Errortrace.comparison_error
  7. | CM_Meth_type_mismatch of string * Env.t * Errortrace.comparison_error
  8. | CM_Non_mutable_value of string
  9. | CM_Non_concrete_value of string
  10. | CM_Missing_value of string
  11. | CM_Missing_method of string
  12. | CM_Hide_public of string
  13. | CM_Hide_virtual of string * string
  14. | CM_Public_method of string
  15. | CM_Private_method of string
  16. | CM_Virtual_method of string
val match_class_types : ?trace:bool -> Env.t -> Types.class_type -> Types.class_type -> class_match_failure list
val equal : Env.t -> bool -> Types.type_expr list -> Types.type_expr list -> unit
val is_equal : Env.t -> bool -> Types.type_expr list -> Types.type_expr list -> bool
val equal_private : Env.t -> Types.type_expr list -> Types.type_expr -> Types.type_expr list -> Types.type_expr -> unit
val match_class_declarations : Env.t -> Types.type_expr list -> Types.class_type -> Types.type_expr list -> Types.class_type -> class_match_failure list
val enlarge_type : Env.t -> Types.type_expr -> Types.type_expr * bool
val subtype : Env.t -> Types.type_expr -> Types.type_expr -> unit -> unit
val new_class_signature : unit -> Types.class_signature
val add_dummy_method : Env.t -> scope:int -> Types.class_signature -> unit
type add_method_failure =
  1. | Unexpected_method
  2. | Type_mismatch of Errortrace.unification_error
exception Add_method_failed of add_method_failure
type add_instance_variable_failure =
  1. | Mutability_mismatch of Asttypes.mutable_flag
  2. | Type_mismatch of Errortrace.unification_error
exception Add_instance_variable_failed of add_instance_variable_failure
val add_instance_variable : strict:bool -> Env.t -> Asttypes.label -> Asttypes.mutable_flag -> Asttypes.virtual_flag -> Types.type_expr -> Types.class_signature -> unit
type inherit_class_signature_failure =
  1. | Self_type_mismatch of Errortrace.unification_error
  2. | Method of Asttypes.label * add_method_failure
  3. | Instance_variable of Asttypes.label * add_instance_variable_failure
exception Inherit_class_signature_failed of inherit_class_signature_failure
val inherit_class_signature : strict:bool -> Env.t -> Types.class_signature -> Types.class_signature -> unit
val update_class_signature : Env.t -> Types.class_signature -> Asttypes.label list * Asttypes.label list
val hide_private_methods : Env.t -> Types.class_signature -> unit
val close_class_signature : Env.t -> Types.class_signature -> bool
exception Nondep_cannot_erase of Ident.t
val nondep_type : Env.t -> Ident.t list -> Types.type_expr -> Types.type_expr
val nondep_type_decl : Env.t -> Ident.t list -> bool -> Types.type_declaration -> Types.type_declaration
val nondep_extension_constructor : Env.t -> Ident.t list -> Types.extension_constructor -> Types.extension_constructor
val nondep_class_declaration : Env.t -> Ident.t list -> Types.class_declaration -> Types.class_declaration
val nondep_cltype_declaration : Env.t -> Ident.t list -> Types.class_type_declaration -> Types.class_type_declaration
val is_contractive : Env.t -> Path.t -> bool
val normalize_type : Types.type_expr -> unit
val nongen_schema : Env.t -> Types.type_expr -> bool
val nongen_class_declaration : Types.class_declaration -> bool
val free_variables : ?env:Env.t -> Types.type_expr -> Types.type_expr list
val closed_type_decl : Types.type_declaration -> Types.type_expr option
val closed_extension_constructor : Types.extension_constructor -> Types.type_expr option
val closed_class : Types.type_expr list -> Types.class_signature -> (Types.type_expr * bool * string * Types.type_expr) option
val arity : Types.type_expr -> int
val collapse_conj_params : Env.t -> Types.type_expr list -> unit
val get_current_level : unit -> int
val wrap_trace_gadt_instances : Env.t -> ('a -> 'b) -> 'a -> 'b
val reset_reified_var_counter : unit -> unit
val immediacy : Env.t -> Types.type_expr -> Type_immediacy.t
val package_subtype : (Env.t -> Path.t -> (Longident.t * Types.type_expr) list -> Path.t -> (Longident.t * Types.type_expr) list -> bool) ref
val mcomp : Env.t -> Types.type_expr -> Types.type_expr -> unit