Module Ocaml_typing.Env

type value_unbound_reason =
  1. | Val_unbound_instance_variable
  2. | Val_unbound_self
  3. | Val_unbound_ancestor
  4. | Val_unbound_ghost_recursive of Ocaml_parsing.Location.t
type module_unbound_reason =
  1. | Mod_unbound_illegal_recursion of {
    1. container : string option;
    2. unbound : string;
    }
type locks
type summary =
  1. | Env_empty
  2. | Env_value of summary * Ident.t * Types.value_description * Mode.Value.l
  3. | Env_type of summary * Ident.t * Types.type_declaration
  4. | Env_extension of summary * Ident.t * Types.extension_constructor
  5. | Env_module of summary * Ident.t * Types.module_presence * Types.module_declaration * Mode.Value.l * locks
  6. | Env_modtype of summary * Ident.t * Types.modtype_declaration
  7. | Env_class of summary * Ident.t * Types.class_declaration
  8. | Env_cltype of summary * Ident.t * Types.class_type_declaration
  9. | Env_open of summary * Path.t
    (*

    The string set argument of Env_open represents a list of module names to skip, i.e. that won't be imported in the toplevel namespace.

    *)
  10. | Env_functor_arg of summary * Ident.t
  11. | Env_constraints of summary * Types.type_declaration Path.Map.t
  12. | Env_copy_types of summary
  13. | Env_persistent of summary * Ident.t
  14. | Env_value_unbound of summary * string * value_unbound_reason
  15. | Env_module_unbound of summary * string * module_unbound_reason
type address = Persistent_env.address =
  1. | Aunit of Compilation_unit.t
  2. | Alocal of Ident.t
  3. | Adot of address * Jkind.Sort.t array * int
type t
type stage
val empty : t
val initial : t Lazy.t
val diff : t -> t -> Ident.t list
val same_type_declarations : t -> t -> bool
type type_descriptions = type_descr_kind
type iter_cont
val iter_types : (Path.t -> (Path.t * Types.type_declaration) -> unit) -> t -> iter_cont
val run_iter_cont : iter_cont list -> (Path.t * iter_cont) list
val same_types : t -> t -> bool
val used_persistent : unit -> Compilation_unit.Name.Set.t
val find_shadowed_types : Path.t -> t -> Path.t list
val without_cmis : ('a -> 'b) -> 'a -> 'b
val find_value_no_locks_exn : Ident.t -> t -> Subst.Lazy.value_description * Mode.Value.l

Find a value by an Ident.t. Raises if encounters any locks.

val find_value : Path.t -> t -> Subst.Lazy.value_description
val find_type : Path.t -> t -> Types.type_declaration
val find_type_descrs : Path.t -> t -> type_descriptions
val find_module_lazy : Path.t -> t -> Subst.Lazy.module_declaration
val find_module : Path.t -> t -> Types.module_declaration
val find_modtype_lazy : Path.t -> t -> Subst.Lazy.modtype_declaration
val find_modtype : Path.t -> t -> Types.modtype_declaration
val find_class : Path.t -> t -> Types.class_declaration
val find_cltype : Path.t -> t -> Types.class_type_declaration
val find_ident_constructor : Ident.t -> t -> Types.constructor_description
val find_ident_label : 'rcd Types.record_form -> Ident.t -> t -> 'rcd Types.gen_label_description
val find_type_expansion : Path.t -> t -> Types.type_expr list * Types.type_expr * int
val find_type_expansion_opt : Path.t -> t -> Types.type_expr list * Types.type_expr * int
val find_modtype_expansion : Path.t -> t -> Types.module_type
val find_modtype_expansion_lazy : Path.t -> t -> Subst.Lazy.module_type
val find_hash_type : Path.t -> t -> Types.type_declaration
val find_value_address : Path.t -> t -> address
val find_module_address : Path.t -> t -> address
val find_class_address : Path.t -> t -> address
val find_constructor_address : Path.t -> t -> address
val shape_of_path : namespace:Shape.Sig_component_kind.t -> t -> Path.t -> Shape.t
val shape_of_path_opt : namespace:Shape.Sig_component_kind.t -> t -> Path.t -> Shape.t option
val shape_for_constr : t -> Path.t -> args:Shape.t list -> Shape.t option
val add_functor_arg : Ident.t -> t -> t
val is_functor_arg : Path.t -> t -> bool
val normalize_module_path : Ocaml_parsing.Location.t option -> t -> Path.t -> Path.t
val normalize_type_path : Ocaml_parsing.Location.t option -> t -> Path.t -> Path.t
val normalize_value_path : Ocaml_parsing.Location.t option -> t -> Path.t -> Path.t
val normalize_modtype_path : t -> Path.t -> Path.t
val normalize_instance_names_in_module_path : Path.t -> Path.t
val reset_required_globals : unit -> unit
val get_required_globals : unit -> Compilation_unit.t list
val add_required_global : Path.t -> t -> unit
val reset_probes : unit -> unit
val add_probe : string -> unit
val has_probe : string -> bool
val has_local_constraints : t -> bool
val mark_value_used : Ocaml_typing.Types.Uid.t -> unit
val mark_module_used : Ocaml_typing.Types.Uid.t -> unit
val mark_type_used : Ocaml_typing.Types.Uid.t -> unit
val mark_value_mutated : Ocaml_typing.Types.Uid.t -> unit
type constructor_usage =
  1. | Positive
  2. | Pattern
  3. | Exported_private
  4. | Exported
val mark_constructor_used : constructor_usage -> Ocaml_typing.Types.Uid.t -> unit
val mark_extension_used : constructor_usage -> Ocaml_typing.Types.Uid.t -> unit
type label_usage =
  1. | Projection
  2. | Mutation
  3. | Construct
  4. | Exported_private
  5. | Exported
val mark_label_used : label_usage -> Ocaml_typing.Types.Uid.t -> unit
type unbound_value_hint =
  1. | No_hint
  2. | Missing_rec of Ocaml_parsing.Location.t
type mode_with_locks = Mode.Value.l * locks

Sometimes we get the locks for something, but either want to walk them later, or walk them for something else. The Longident.t and Location.t are only for error messages, and point to the variable for which we actually want to walk the locks.

val locks_empty : locks
val locks_is_empty : locks -> bool
val mode_unit : Mode.Value.lr
type structure_components_reason =
  1. | Project
  2. | Open
type no_open_quotations_context =
  1. | Object_qt
  2. | Struct_qt
  3. | Sig_qt
  4. | Open_qt
type lookup_error =
  1. | Unbound_value of Ocaml_parsing.Longident.t * unbound_value_hint
  2. | Unbound_type of Ocaml_parsing.Longident.t
  3. | Unbound_constructor of Ocaml_parsing.Longident.t
  4. | Unbound_label of Ocaml_parsing.Longident.t * Types.record_form_packed * label_usage
  5. | Unbound_module of Ocaml_parsing.Longident.t
  6. | Unbound_class of Ocaml_parsing.Longident.t
  7. | Unbound_modtype of Ocaml_parsing.Longident.t
  8. | Unbound_cltype of Ocaml_parsing.Longident.t
  9. | Unbound_settable_variable of string
  10. | Not_a_settable_variable of string
  11. | Masked_instance_variable of Ocaml_parsing.Longident.t
  12. | Masked_self_variable of Ocaml_parsing.Longident.t
  13. | Masked_ancestor_variable of Ocaml_parsing.Longident.t
  14. | Structure_used_as_functor of Ocaml_parsing.Longident.t
  15. | Abstract_used_as_functor of Ocaml_parsing.Longident.t * Path.t
  16. | Functor_used_as_structure of Ocaml_parsing.Longident.t * structure_components_reason
  17. | Abstract_used_as_structure of Ocaml_parsing.Longident.t * Path.t * structure_components_reason
  18. | Generative_used_as_applicative of Ocaml_parsing.Longident.t
  19. | Illegal_reference_to_recursive_module of {
    1. container : string option;
    2. unbound : string;
    }
  20. | Illegal_reference_to_recursive_class_type of {
    1. container : string option;
    2. unbound : string;
    3. unbound_class_type : Ocaml_parsing.Longident.t;
    4. container_class_type : string;
    }
  21. | Cannot_scrape_alias of Ocaml_parsing.Longident.t * Path.t
  22. | Local_value_used_in_exclave of Ocaml_typing.Mode.Hint.lock_item * Ocaml_parsing.Longident.t
  23. | Non_value_used_in_object of Ocaml_parsing.Longident.t * Types.type_expr * Jkind.Violation.t
  24. | No_unboxed_version of Ocaml_parsing.Longident.t * Types.type_declaration
  25. | Error_from_persistent_env of Persistent_env.error
  26. | Mutable_value_used_in_closure of Ocaml_typing.Mode.Hint.pinpoint
  27. | Incompatible_stage of Ocaml_parsing.Longident.t * Ocaml_parsing.Location.t * stage * Ocaml_parsing.Location.t * stage
  28. | No_constructor_in_stage of Ocaml_parsing.Longident.t * Ocaml_parsing.Location.t * int
val lookup_error : Ocaml_parsing.Location.t -> t -> lookup_error -> 'a

Takes the mode and the type of a value at definition site, walks through the list of locks and constrains the mode and the type. Return the access mode of the value allowed by the locks. ty is optional as the function works on modules and classes as well, for which ty should be None.

val lookup_module_path : ?use:bool -> loc:Ocaml_parsing.Location.t -> load:bool -> Ocaml_parsing.Longident.t -> t -> Path.t * mode_with_locks
val lookup_modtype_path : ?use:bool -> loc:Ocaml_parsing.Location.t -> Ocaml_parsing.Longident.t -> t -> Path.t
val lookup_module_instance_path : ?use:bool -> loc:Ocaml_parsing.Location.t -> load:bool -> Global_module.Name.t -> t -> Path.t * locks
val lookup_all_constructors : ?use:bool -> loc:Ocaml_parsing.Location.t -> constructor_usage -> Ocaml_parsing.Longident.t -> t -> (((Types.constructor_description * locks) * (unit -> unit)) list, Ocaml_parsing.Location.t * t * lookup_error) result
val lookup_all_constructors_from_type : ?use:bool -> loc:Ocaml_parsing.Location.t -> constructor_usage -> Path.t -> t -> ((Types.constructor_description * locks) * (unit -> unit)) list
val lookup_label : ?use:bool -> record_form:'rcd Types.record_form -> loc:Ocaml_parsing.Location.t -> label_usage -> Ocaml_parsing.Longident.t -> t -> 'rcd Types.gen_label_description
val lookup_all_labels : ?use:bool -> record_form:'rcd Types.record_form -> loc:Ocaml_parsing.Location.t -> label_usage -> Ocaml_parsing.Longident.t -> t -> (('rcd Types.gen_label_description * (unit -> unit)) list, Ocaml_parsing.Location.t * t * lookup_error) result
val lookup_all_labels_from_type : ?use:bool -> record_form:'rcd Types.record_form -> loc:Ocaml_parsing.Location.t -> label_usage -> Path.t -> t -> ('rcd Types.gen_label_description * (unit -> unit)) list
type settable_variable =
  1. | Instance_variable of Path.t * Ocaml_parsing.Asttypes.mutable_flag * string * Types.type_expr
  2. | Mutable_variable of Ident.t * Mode.Value.r * Types.type_expr * Jkind.Sort.t
val lookup_settable_variable : ?use:bool -> loc:Ocaml_parsing.Location.t -> string -> t -> settable_variable

For a mutable variable, use means mark as mutated. For an instance variable, it means mark as used.

val find_value_by_name_lazy : Ocaml_parsing.Longident.t -> t -> Path.t * Subst.Lazy.value_description
val find_module_by_name_lazy : Ocaml_parsing.Longident.t -> t -> Path.t * Subst.Lazy.module_declaration
val find_modtype_by_name_lazy : Ocaml_parsing.Longident.t -> t -> Path.t * Subst.Lazy.modtype_declaration
val find_constructor_by_name : Ocaml_parsing.Longident.t -> t -> Types.constructor_description
val find_label_by_name : 'rep Types.record_form -> Ocaml_parsing.Longident.t -> t -> 'rep Types.gen_label_description
val find_value_index : Ident.t -> t -> int option

The find_*_index functions computes a "namespaced" De Bruijn index of an identifier in a given environment. In other words, it returns how many times an identifier has been shadowed by a more recent identifiers with the same name in a given environment. Those functions return None when the identifier is not bound in the environment. This behavior is there to facilitate the detection of inconsistent printing environment, but should disappear in the long term.

val find_type_index : Ident.t -> t -> int option
val find_module_index : Ident.t -> t -> int option
val find_modtype_index : Ident.t -> t -> int option
val find_class_index : Ident.t -> t -> int option
val find_cltype_index : Ident.t -> t -> int option
val bound_value : string -> t -> bool
val bound_module : string -> t -> bool
val bound_type : string -> t -> bool
val bound_modtype : string -> t -> bool
val bound_class : string -> t -> bool
val bound_cltype : string -> t -> bool
val make_copy_of_types : t -> t -> t
val global_of_instance_compilation_unit : Compilation_unit.t -> Global_module.t
val add_value_lazy : ?check:(string -> Ocaml_utils.Warnings.t) -> mode:(Mode.allowed * 'r) Mode.Value.t -> Ident.t -> Subst.Lazy.value_description -> t -> t
val add_value : ?check:(string -> Ocaml_utils.Warnings.t) -> mode:(Mode.allowed * 'r) Mode.Value.t -> Ident.t -> Types.value_description -> t -> t
val add_type : check:bool -> ?shape:Shape.t -> Ident.t -> Types.type_declaration -> t -> t
val add_type_long_path : check:bool -> ?shape:Shape.t -> Ident.t -> Types.type_declaration -> t -> t
val add_extension : check:bool -> ?shape:Shape.t -> rebind:bool -> Ident.t -> Types.extension_constructor -> t -> t
val add_module : ?arg:bool -> ?shape:Shape.t -> Ident.t -> Types.module_presence -> Types.module_type -> ?mode:Mode.Value.l -> t -> t
val add_module_lazy : update_summary:bool -> Ident.t -> Types.module_presence -> Subst.Lazy.module_type -> ?mode:Mode.Value.l -> t -> t
val add_module_declaration : ?arg:bool -> ?shape:Shape.t -> check:bool -> Ident.t -> Types.module_presence -> Types.module_declaration -> ?mode:(Mode.allowed * 'r) Mode.Value.t -> ?locks:locks -> t -> t
val add_module_declaration_lazy : ?arg:bool -> update_summary:bool -> Ident.t -> Types.module_presence -> Subst.Lazy.module_declaration -> ?mode:(Mode.allowed * 'r) Mode.Value.t -> ?locks:locks -> t -> t
val add_modtype : Ident.t -> Types.modtype_declaration -> t -> t
val add_modtype_lazy : update_summary:bool -> Ident.t -> Subst.Lazy.modtype_declaration -> t -> t
val add_class : Ident.t -> Types.class_declaration -> t -> t
val add_cltype : Ident.t -> Types.class_type_declaration -> t -> t
val add_local_constraint : Path.t -> Types.type_declaration -> t -> t
val add_persistent_structure : Ident.t -> t -> t
val persistent_structures_of_dir : Ocaml_utils.Load_path.Dir.t -> Merlin_utils.Misc.String.Set.t
val persistent_structures_of_basenames : string list -> Merlin_utils.Misc.String.Set.t
val filter_non_loaded_persistent : (Ident.t -> bool) -> t -> t
val add_signature : Types.signature -> t -> t
val add_signature_lazy : Subst.Lazy.signature_item list -> t -> t
val open_signature_by_path : Path.t -> t -> t
val open_pers_signature : string -> t -> Path.t * mode_with_locks * t
val remove_last_open : Path.t -> t -> t option
val enter_value : ?check:(string -> Ocaml_utils.Warnings.t) -> mode:(Mode.allowed * 'r) Mode.Value.t -> string -> Types.value_description -> t -> Ident.t * t
val enter_type : scope:int -> string -> Types.type_declaration -> t -> Ident.t * t
val enter_extension : scope:int -> rebind:bool -> string -> Types.extension_constructor -> t -> Ident.t * t
val enter_module : scope:int -> ?arg:bool -> string -> Types.module_presence -> Types.module_type -> ?mode:(Mode.allowed * 'r) Mode.Value.t -> t -> Ident.t * t
val enter_module_declaration : scope:int -> ?arg:bool -> ?shape:Shape.t -> string -> Types.module_presence -> Types.module_declaration -> ?mode:(Mode.allowed * 'r) Mode.Value.t -> ?locks:locks -> t -> Ident.t * t
val enter_modtype : scope:int -> string -> Types.modtype_declaration -> t -> Ident.t * t
val enter_class : scope:int -> string -> Types.class_declaration -> t -> Ident.t * t
val enter_cltype : scope:int -> string -> Types.class_type_declaration -> t -> Ident.t * t
val enter_signature : ?mod_shape:Shape.t -> scope:int -> Types.signature -> ?mode:(Mode.allowed * 'r) Mode.Value.t -> t -> Types.signature * t
val enter_signature_and_shape : scope:int -> parent_shape:Shape.Map.t -> Shape.t -> Types.signature -> ?mode:(Mode.allowed * 'r) Mode.Value.t -> t -> Types.signature * Shape.Map.t * t
val enter_unbound_value : string -> value_unbound_reason -> t -> t
val enter_unbound_module : string -> module_unbound_reason -> t -> t
val add_const_closure_lock : ?ghost:bool -> Ocaml_typing.Mode.Hint.pinpoint -> Mode.Value.Comonadic.Const.t -> t -> t

A variant of add_closure_lock where the mode of the closure is a constant due to the nature of the pinpoint. As a result, the mode is not printed in error messages. ghost = true means the closure is not a value (such as a loop)

val add_region_lock : t -> t
val add_exclave_lock : t -> t
val add_unboxed_lock : t -> t
val enter_quotation : t -> t
val enter_splice : loc:Ocaml_parsing.Location.t -> t -> t
val check_no_open_quotations : Ocaml_parsing.Location.t -> t -> no_open_quotations_context -> unit
val stage : t -> stage
val reset_cache : preserve_persistent_env:bool -> unit
val reset_cache_toplevel : unit -> unit
val set_unit_name : Unit_info.t option -> unit
val get_unit_name : unit -> Unit_info.t option
val register_parameter : Global_module.Parameter_name.t -> unit
val crc_of_unit : Compilation_unit.Name.t -> Digest.t
val imports : unit -> Import_info.t list
val import_crcs : source:string -> Import_info.t array -> unit
val require_global_for_quote : Compilation_unit.Name.t -> unit
val quoted_globals : unit -> Compilation_unit.Name.t list
val runtime_parameter_bindings : unit -> (Global_module.t * Ident.t) list
val is_bound_to_runtime_parameter : Ident.t -> bool
val parameters : unit -> Global_module.Parameter_name.t list
val is_imported_opaque : Compilation_unit.Name.t -> bool
val register_import_as_opaque : Compilation_unit.Name.t -> unit
val is_parameter_unit : Global_module.Name.t -> bool
val implemented_parameter : Global_module.Name.t -> Global_module.Parameter_name.t option
val is_imported_parameter : Global_module.Name.t -> bool
val summary : t -> summary
val keep_only_summary : t -> t
val env_of_only_summary : (summary -> Subst.t -> t) -> t -> t
val update_short_paths : t -> t
val short_paths : t -> Short_paths.t
type error =
  1. | Missing_module of Ocaml_parsing.Location.t * Path.t * Path.t
  2. | Illegal_value_name of Ocaml_parsing.Location.t * string
  3. | Lookup_error of Ocaml_parsing.Location.t * t * lookup_error
  4. | Incomplete_instantiation of {
    1. unset_param : Global_module.Parameter_name.t;
    }
  5. | Toplevel_splice of Ocaml_parsing.Location.t
  6. | Unsupported_inside_quotation of Ocaml_parsing.Location.t * no_open_quotations_context
exception Error of error
val report_error : level:int -> Format.formatter -> error -> unit
val report_lookup_error : level:int -> Ocaml_parsing.Location.t -> t -> Format.formatter -> lookup_error -> unit
val in_signature : bool -> t -> t
val is_in_signature : t -> bool
val set_value_used_callback : Subst.Lazy.value_description -> (unit -> unit) -> unit
val set_value_mutated_callback : Subst.Lazy.value_description -> (unit -> unit) -> unit
val set_type_used_callback : Types.type_declaration -> ((unit -> unit) -> unit) -> unit
val check_functor_application : (errors:bool -> loc:Ocaml_parsing.Location.t -> lid_whole_app:Ocaml_parsing.Longident.t -> f0_path:Path.t -> args:(Path.t * Types.module_type) list -> arg_path:Path.t -> arg_mty:Types.module_type -> param_mty:Types.module_type -> t -> unit) ref
val check_well_formed_module : (t -> Ocaml_parsing.Location.t -> string -> Types.module_type -> unit) ref
val add_delayed_check_forward : ((unit -> unit) -> unit) ref
val same_constr : (t -> Types.type_expr -> Types.type_expr -> bool) ref
val constrain_type_jkind : (t -> Types.type_expr -> Types.jkind_r -> (unit, Jkind.Violation.t) result) ref
val print_longident : (Format.formatter -> Ocaml_parsing.Longident.t -> unit) ref
val print_path : (Format.formatter -> Path.t -> unit) ref
val print_type_expr : (Format.formatter -> Types.type_expr -> unit) ref
val shorten_module_path : (t -> Path.t -> Path.t) ref

Folds

Folding over all identifiers (for analysis purpose)

val fold_values : (string -> Path.t -> Subst.Lazy.value_description -> Mode.Value.l -> 'a -> 'a) -> Ocaml_parsing.Longident.t option -> t -> 'a -> 'a
val fold_types : (string -> Path.t -> Types.type_declaration -> 'a -> 'a) -> Ocaml_parsing.Longident.t option -> t -> 'a -> 'a
val fold_constructors : (Types.constructor_description -> 'a -> 'a) -> Ocaml_parsing.Longident.t option -> t -> 'a -> 'a
val fold_labels : 'rcd Types.record_form -> ('rcd Types.gen_label_description -> 'a -> 'a) -> Ocaml_parsing.Longident.t option -> t -> 'a -> 'a
val fold_modules : (string -> Path.t -> Subst.Lazy.module_declaration -> 'a -> 'a) -> Ocaml_parsing.Longident.t option -> t -> 'a -> 'a

Persistent structures are only traversed if they are already loaded.

val fold_modtypes : (string -> Path.t -> Subst.Lazy.modtype_declaration -> 'a -> 'a) -> Ocaml_parsing.Longident.t option -> t -> 'a -> 'a
val fold_classes : (string -> Path.t -> Types.class_declaration -> 'a -> 'a) -> Ocaml_parsing.Longident.t option -> t -> 'a -> 'a
val fold_cltypes : (string -> Path.t -> Types.class_type_declaration -> 'a -> 'a) -> Ocaml_parsing.Longident.t option -> t -> 'a -> 'a
val check_value_name : string -> Ocaml_parsing.Location.t -> unit

Utilities

val print_address : Format.formatter -> address -> unit
type address_head =
  1. | AHunit of Compilation_unit.t
  2. | AHlocal of Ident.t
val address_head : address -> address_head
val print_stage : Format.formatter -> stage -> unit
val unbound_class : Path.t

merlin: manage internal state

val check_state_consistency : unit -> bool
val with_cmis : (unit -> 'a) -> 'a
val add_merlin_extension_module : Ident.t -> Types.module_type -> t -> t
val cleanup_functor_caches : stamp:int -> unit
val cleanup_usage_tables : stamp:int -> unit
val msupport_raise_error : (?ignore_unify:bool -> exn -> unit) ref

This value should be filled in with Msupport.raise_error. Env cannot use this function directly because Msupport depends on Env

type 'acc fold_all_labels_f = {
  1. fold_all_labels_f : 'rcd. 'rcd Types.record_form -> 'rcd Types.gen_label_description -> 'acc -> 'acc;
}
val fold_all_labels : 'a fold_all_labels_f -> Ocaml_parsing.Longident.t option -> t -> 'a -> 'a
val print_with_quote_promote : Format.formatter -> (string * stage * stage) -> unit