Module Ocaml_typing.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 Cannot_expand
exception Cannot_apply
exception Incompatible
val with_local_level : ?post:('a -> unit) -> (unit -> 'a) -> 'a
val with_local_level_if : bool -> (unit -> 'a) -> post:('a -> unit) -> 'a
val with_local_level_iter : (unit -> 'a * 'b list) -> post:('b -> unit) -> 'a
val with_local_level_iter_if : bool -> (unit -> 'a * 'b list) -> post:('b -> unit) -> 'a
val with_level : level:int -> (unit -> 'a) -> 'a
val with_level_if : bool -> level:int -> (unit -> 'a) -> 'a
val with_local_level_if_principal : (unit -> 'a) -> post:('a -> unit) -> 'a
val with_local_level_iter_if_principal : (unit -> 'a * 'b list) -> post:('b -> unit) -> 'a
val with_local_level_for_class : ?post:('a -> unit) -> (unit -> 'a) -> 'a
val with_raised_nongen_level : (unit -> 'a) -> 'a
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 -> Types.jkind_lr -> Types.type_expr
val new_rep_var : ?name:string -> why:Jkind.History.concrete_creation_reason -> unit -> Types.type_expr * Jkind.sort
val newvar2 : ?name:string -> int -> Types.jkind_lr -> Types.type_expr
val new_global_var : ?name:string -> Types.jkind_lr -> 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 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 enforce_current_level : Env.t -> 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:Ocaml_parsing.Location.t -> ?manifest_and_scope:(Types.type_expr * int) -> Types.type_origin -> (Mode.allowed * 'r) Types.jkind -> Types.type_declaration
module Pattern_env : sig ... end
type existential_treatment =
  1. | Keep_existentials_flexible
  2. | Make_existentials_abstract of Pattern_env.t
val instance_parameterized_type : ?keep_names:bool -> Types.type_expr list -> Types.type_expr -> 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 -> Types.type_expr list -> Types.type_expr -> Types.type_expr
val instance_poly_fixed : ?keep_names: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 instance_label : fixed:bool -> _ Types.gen_label_description -> Types.type_expr list * Types.type_expr * Types.type_expr

Given (a @ m1 -> b -> c) @ m0, where m0 and m1 are modes expressed by user-syntax, curry_mode m0 m1 gives the mode we implicitly interpret b->c to have.

val apply : ?use_current_level:bool -> Env.t -> Types.type_expr list -> Types.type_expr -> Types.type_expr list -> Types.type_expr
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_var : Env.t -> Types.type_expr -> Types.type_expr -> unit
val unify_delaying_jkind_checks : Env.t -> Types.type_expr -> Types.type_expr -> (Types.type_expr * Types.jkind_r) list
type filtered_arrow = {
  1. ty_arg : Types.type_expr;
  2. arg_mode : Mode.Alloc.lr;
  3. ty_ret : Types.type_expr;
  4. ret_mode : Mode.Alloc.lr;
}
val filter_arrow : Env.t -> Types.type_expr -> Types.arg_label -> force_tpoly:bool -> filtered_arrow
val filter_mono : Types.type_expr -> Types.type_expr
val filter_arrow_mono : Env.t -> Types.type_expr -> Types.arg_label -> filtered_arrow
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_list : Types.type_expr -> Types.type_expr list -> 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 all_distinct_vars : Env.t -> Types.type_expr list -> bool
type matches_result =
  1. | Unification_failure of Errortrace.unification_error
  2. | Jkind_mismatch of {
    1. original_jkind : Types.jkind_lr;
    2. inferred_jkind : Types.jkind_lr;
    3. ty : Types.type_expr;
    }
  3. | All_good
val matches : expand_error_trace:bool -> Env.t -> Types.type_expr -> Types.type_expr -> matches_result
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 : Types.arg_label;
    2. expected : Types.arg_label;
    3. expected_type : Types.type_expr;
    }
  3. | Not_a_function
  4. | Jkind_error of Types.type_expr * Jkind.Violation.t
exception Filter_arrow_failed of filter_arrow_failure
exception Filter_mono_failed
exception Filter_arrow_mono_failed
type filter_method_failure =
  1. | Unification_error of Errortrace.unification_error
  2. | Not_a_method
  3. | Not_an_object of Types.type_expr
  4. | Not_a_value of Jkind.Violation.t
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 int * Env.t * Errortrace.equality_error
  4. | CM_Class_type_mismatch of Env.t * Types.class_type * Types.class_type
  5. | CM_Parameter_mismatch of int * 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 : ?do_jkind_check:bool -> 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 -> 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
module Rigidify : sig ... end
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 Ocaml_parsing.Asttypes.mutable_flag
  2. | Type_mismatch of Errortrace.unification_error
exception Add_instance_variable_failed of add_instance_variable_failure
type inherit_class_signature_failure =
  1. | Self_type_mismatch of Errortrace.unification_error
  2. | Method of Ocaml_parsing.Asttypes.label * add_method_failure
  3. | Instance_variable of Ocaml_parsing.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 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 remove_mode_and_jkind_variables : Types.type_expr -> unit
val nongen_vars_in_schema : Env.t -> Types.type_expr -> Btype.TypeSet.t option
val nongen_vars_in_class_declaration : Types.class_declaration -> Btype.TypeSet.t option
type variable_kind =
  1. | Row_variable
  2. | Type_variable
type closed_class_failure = {
  1. free_variable : Types.type_expr * variable_kind;
  2. meth : string;
  3. meth_ty : Types.type_expr;
}
val free_variables : ?env:Env.t -> Types.type_expr -> Types.type_expr list
val free_non_row_variables_of_list : Types.type_expr list -> Types.type_expr list
val free_variable_set_of_list : Env.t -> Types.type_expr list -> Btype.TypeSet.t
val exists_free_variable : (Types.type_expr -> Types.jkind_lr -> bool) -> Types.type_expr -> bool
val closed_type_expr : ?env:Env.t -> Types.type_expr -> bool
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 -> closed_class_failure 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 package_subtype : (Env.t -> Path.t -> (Ocaml_parsing.Longident.t * Types.type_expr) list -> Path.t -> (Ocaml_parsing.Longident.t * Types.type_expr) list -> bool) ref
val mcomp : Env.t -> Types.type_expr -> Types.type_expr -> unit
type unwrapped_type_expr = {
  1. ty : Types.type_expr;
  2. modality : Mode.Modality.Const.t;
}
val get_unboxed_type_representation : Env.t -> Types.type_expr -> (unwrapped_type_expr, unwrapped_type_expr) result
val get_unboxed_type_approximation : Env.t -> Types.type_expr -> unwrapped_type_expr
val contained_without_boxing : Env.t -> Types.type_expr -> Types.type_expr list
val estimate_type_jkind : Env.t -> Types.type_expr -> Types.jkind_l
val type_jkind : Env.t -> Types.type_expr -> Types.jkind_l
val type_jkind_purely : Env.t -> Types.type_expr -> Types.jkind_l
val type_jkind_purely_if_principal : Env.t -> Types.type_expr -> Types.jkind_l option
val mk_jkind_context : Env.t -> (Types.type_expr -> Types.jkind_l option) -> Jkind.jkind_context
val mk_jkind_context_check_principal : Env.t -> Jkind.jkind_context
val mk_jkind_context_always_principal : Env.t -> Jkind.jkind_context
val check_decl_jkind : Env.t -> Types.type_declaration -> Types.jkind_l -> (unit, Jkind.Violation.t) result
val constrain_decl_jkind : Env.t -> Types.type_declaration -> Types.jkind_l -> (unit, Jkind.Violation.t) result
val type_equal : Env.t -> Types.type_expr -> Types.type_expr -> bool
val check_type_jkind : Env.t -> Types.type_expr -> ('l * Mode.allowed) Types.jkind -> (unit, Jkind.Violation.t) result
val constrain_type_jkind : Env.t -> Types.type_expr -> ('l * Mode.allowed) Types.jkind -> (unit, Jkind.Violation.t) result
val check_type_externality : Env.t -> Types.type_expr -> Jkind_axis.Externality.t -> bool
val is_always_gc_ignorable : Env.t -> Types.type_expr -> bool
val check_type_nullability : Env.t -> Types.type_expr -> Jkind_axis.Nullability.t -> bool
val check_type_separability : Env.t -> Types.type_expr -> Jkind_axis.Separability.t -> bool
val check_and_update_generalized_ty_jkind : ?name:Ident.t -> loc:Ocaml_parsing.Location.t -> Env.t -> Types.type_expr -> unit
val is_principal : Types.type_expr -> bool
type global_state
val global_state : global_state
val print_global_state : Format.formatter -> global_state -> unit
val crossing_of_jkind : Env.t -> 'd Types.jkind -> Mode.Crossing.t

Get the crossing of a jkind

val crossing_of_ty : Env.t -> ?modalities:Mode.Modality.Const.t -> Types.type_expr -> Mode.Crossing.t

Get the crossing of a type wrapped in modalities. Non-principal types get trivial crossing.

val cross_right : Env.t -> ?modalities:Mode.Modality.Const.t -> Types.type_expr -> Mode.Value.r -> Mode.Value.r

Cross a right mode according to a type wrapped in modalities. Non-principal types don't cross.

val cross_left : Env.t -> ?modalities:Mode.Modality.Const.t -> Types.type_expr -> Mode.Value.l -> Mode.Value.l

Cross a left mode according to a type wrapped in modalities. Non-principal types don't cross.

val cross_right_alloc : Env.t -> ?modalities:Mode.Modality.Const.t -> Types.type_expr -> Mode.Alloc.r -> Mode.Alloc.r

Similar to cross_right but for Mode.Alloc

val cross_left_alloc : Env.t -> ?modalities:Mode.Modality.Const.t -> Types.type_expr -> Mode.Alloc.l -> Mode.Alloc.l

Similar to cross_left but for Mode.Alloc

val zap_modalities_to_floor_if_modes_enabled_at : Ocaml_parsing.Language_extension.maturity -> Mode.Modality.t -> Mode.Modality.Const.t

Zap a modality to floor if the modes extension is enabled at a level more immature than the given one. Zap to id otherwise.

val mode_crossing_structure_memaddr : Mode.Crossing.t

The mode crossing of the memory block of a structure.

val mode_crossing_functor : Mode.Crossing.t

The mode crossing of a functor.

val mode_crossing_module : Mode.Crossing.t

The mode crossing of any module.

Zap a modality to floor if maturity allows, zap to id otherwise.