Out_typeFunctions 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).
val wrap_printing_env : error:bool -> Env.t -> (unit -> 'a) -> 'aCall 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
val ident_name :
Shape.Sig_component_kind.t option ->
Ident.t ->
Outcometree.out_nameval tree_of_path : ?disambiguation:bool -> Path.t -> Outcometree.out_identval namespaced_tree_of_path :
Shape.Sig_component_kind.t ->
Path.t ->
Outcometree.out_identval tree_of_type_path : Path.t -> Outcometree.out_identSpecialized functions for printing types with short-paths
val same_path : Types.type_expr -> Types.type_expr -> boolsame_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)val prepare_for_printing : Types.type_expr list -> unitprepare_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.
val add_type_to_preparation : Types.type_expr -> unitadd_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.
val tree_of_typexp : type_or_scheme -> Types.type_expr -> Outcometree.out_typetree_of_typexp generate the outcometree for a prepared type expression.
val prepared_type_scheme : Types.type_expr Format_doc.printerval prepared_type_expr : Types.type_expr Format_doc.printerThe 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.
val type_expr_with_reserved_names : Types.type_expr Format_doc.printertype_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 diffval prepare_expansion : Errortrace.expanded_type -> Errortrace.expanded_typeval pp_type_expansion : Outcometree.out_type diff Format_doc.printerval hide_variant_name : Types.type_expr -> Types.type_exprval prepare_type_constructor_arguments : Types.constructor_arguments -> unitLabel and constructors
val tree_of_constructor_arguments :
Types.constructor_arguments ->
Outcometree.out_type listval tree_of_label : Types.label_declaration -> Outcometree.out_labelval add_constructor_to_preparation : Types.constructor_declaration -> unitval prepared_constructor : Types.constructor_declaration Format_doc.printerval 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 add_extension_constructor_to_preparation :
Types.extension_constructor ->
unitval prepared_extension_constructor :
Ident.t ->
Types.extension_constructor Format_doc.printerval tree_of_type_declaration :
Ident.t ->
Types.type_declaration ->
Types.rec_status ->
Outcometree.out_sig_itemval add_type_declaration_to_preparation :
Ident.t ->
Types.type_declaration ->
unitval prepared_type_declaration :
Ident.t ->
Types.type_declaration 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 tree_of_modtype : Types.module_type -> Outcometree.out_module_typeval tree_of_signature : Types.signature -> Outcometree.out_sig_item listval tree_of_class_type :
type_or_scheme ->
Types.class_type ->
Outcometree.out_class_typeval prepare_class_type : Types.class_type -> unitval print_items :
(Env.t -> Types.signature_item -> 'a option) ->
Env.t ->
Types.signature_item list ->
(Outcometree.out_sig_item * 'a option) listToplevel printing
module Out_name : sig ... endPath name, which were mutable at some point
module Ident_names : sig ... endDisambiguation for identifiers, e.g. the two type constructors named t in the type of f in
module Ident_conflicts : sig ... endThe 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
module Variable_names : sig ... endNaming choice for type variable names ('a, 'b, ...), for instance the two classes of distinct type variables in
module Internal_names : sig ... endRegister internal typechecker names ($0,$a) appearing in the outcometree