Ocaml_typing.Out_typeSourceFunctions for representing type expressions and module types as outcometree (with as 'a aliases for cycles) and printing them. All functions below depends on global contexts that keep track of
Whenever possible, it is advised to use the simpler functions available in Printtyp which take care of setting up this naming context. The functions below are needed when one needs to share a common naming context (or part of it) between different calls to printing functions (or in order to implement Printtyp).
Call the function using the environment for type path shortening This affects all the printing and tree cration functions functions below Also, if ~error:true, then disable the loading of cmis
with_labels false disable labels in function types
Specialized functions for printing types with short-paths
same_path ty ty2 is true when there is an equation ty=ty2 in the short-path scope
Simple heuristic to rewrite Foo__bar.* as Foo.Bar.* when Foo.Bar is an alias for Foo__bar. This pattern is used by the stdlib.
Printing type expressions requires to translate the internal graph based representation into to an Outcometree closer to the source syntax. In order to do so, the printing is generally split in three phase:
tree_of_* functions)prepare_for_printing resets the global naming environment, a la reset_except_conflicts, and prepares the types for printing by reserving variable names and marking cycles. Any type variables that are shared between multiple types in the input list will be given the same name when printed with prepared_type_expr.
add_type_to_preparation ty extend a previous type expression preparation to the type expression ty
In Type_scheme mode, non-generic types variables are printed as weakly polymorphic type variables.
tree_of_typexp generate the outcometree for a prepared type expression.
The printers prepared_type_expr and prepared_type_scheme should only be used on prepared types. Types can be prepared by initially calling prepare_for_printing or adding them later to the preparation with add_type_to_preparation.
Calling this function on non-prepared types may cause a stack overflow (see #8860) due to cycles in the printed types.
See Printtyp.type_expr for a safer but less flexible printer.
type_expr_with_reserved_names can print "half-prepared" type expression. A "half-prepared" type expression should have had its names reserved (with Variable_names.reserve), but should not have had its cycles marked.
val trees_of_type_expansion :
type_or_scheme ->
Errortrace.expanded_type ->
Outcometree.out_type diffLabel and constructors
val tree_of_extension_constructor :
Ident.t ->
Types.extension_constructor ->
Types.ext_status ->
Outcometree.out_sig_itemval extension_constructor_args_and_ret_type_subtree :
Types.constructor_arguments ->
Types.type_expr option ->
Outcometree.out_type list * Outcometree.out_type optionval prepared_extension_constructor :
Ident.t ->
Types.extension_constructor Merlin_utils.Format_doc.printerval tree_of_type_declaration :
Ident.t ->
Types.type_declaration ->
Types.rec_status ->
Outcometree.out_sig_itemval prepared_type_declaration :
Ident.t ->
Types.type_declaration Merlin_utils.Format_doc.printerval tree_of_value_description :
Ident.t ->
Types.value_description ->
Outcometree.out_sig_itemval tree_of_modtype_declaration :
Ident.t ->
Types.modtype_declaration ->
Outcometree.out_sig_itemval tree_of_class_declaration :
Ident.t ->
Types.class_declaration ->
Types.rec_status ->
Outcometree.out_sig_itemval tree_of_cltype_declaration :
Ident.t ->
Types.class_type_declaration ->
Types.rec_status ->
Outcometree.out_sig_itemval tree_of_module :
Ident.t ->
?ellipsis:bool ->
Types.module_type ->
Types.rec_status ->
Outcometree.out_sig_itemval print_items :
(Env.t -> Types.signature_item -> 'a option) ->
Env.t ->
Types.signature_item list ->
(Outcometree.out_sig_item * 'a option) listToplevel printing
Disambiguation for identifiers, e.g. the two type constructors named t in the type of f in
The Ident_conflicts module keeps track of conflicts arising when attributing names to identifiers and provides functions that can print explanations for these conflict in error messages
Naming choice for type variable names ('a, 'b, ...), for instance the two classes of distinct type variables in
Register internal typechecker names ($0,$a) appearing in the outcometree
Reset all contexts
Reset all contexts except for conflicts