Module Typedtree
Abstract syntax tree after typing
By comparison with Parsetree:
- Every
Longindent.tis accompanied by a resolvedPath.t.
module Uid = Shape.Uidtype constant = | Const_int of int| Const_char of char| Const_untagged_char of char| Const_string of string * Location.t * string option| Const_float of string| Const_float32 of string| Const_unboxed_float of string| Const_unboxed_float32 of string| Const_int8 of int| Const_int16 of int| Const_int32 of int32| Const_int64 of int64| Const_nativeint of nativeint| Const_untagged_int of int| Const_untagged_int8 of int| Const_untagged_int16 of int| Const_unboxed_int32 of int32| Const_unboxed_int64 of int64| Const_unboxed_nativeint of nativeint
Extension points
type attribute = Parsetree.attributetype attributes = Typedtree.attribute listCore language
type _ pattern_category = | Value : Typedtree.value Typedtree.pattern_category| Computation : Typedtree.computation Typedtree.pattern_category
module Unique_barrier : sig ... endA unique barrier annotates field accesses (eg. Texp_field and patterns) with the uniqueness mode of the allocation that is projected out of. Projections out of unique allocations may not be pushed down in later stages of the compiler, because the unique allocation may be overwritten.
type unique_use = Mode.Uniqueness.r * Mode.Linearity.lThe uniqueness/linearity of a usage (such as Pexp_ident) inferred by the type checker. It is derived during type checking as follows: unique_use.uniqueness = expected_mode.uniqueness unique_use.linearity = actual_mode.linearity for example, let x = P in f x, (Pexp_ident x).unique_use will contain the expected uniqueness of f's parameter, and linearity of P. uniqueness_analysis.ml will _lexically_ infer the uniqueness/linearity of a usage and compare against unique_use. Following the example, if there are two f x, the uniqueness analysis will perform the following for unique_use of both Pexp_ident x: unique_use.uniqueness >= aliased unique_use.linearity <= many That is, the consumers of the values (that is f) must not require its parameter to be unique, and the value itself (that is P) must be many.
val print_unique_use : Stdlib.Format.formatter -> Typedtree.unique_use -> unittype alloc_mode = Mode.Alloc.rtype texp_field_boxing = | Boxing of Typedtree.alloc_mode * Typedtree.unique_use(*Projection requires boxing.
*)unique_usedescribes the usage of the unboxed field as argument to boxing.| Non_boxing of Typedtree.unique_use(*Projection does not require boxing.
*)unique_usedescribes the usage of the field as the result of direct projection.
val aliased_many_use : Typedtree.unique_usetype pattern = Typedtree.value Typedtree.general_patternand 'k general_pattern = 'k Typedtree.pattern_desc Typedtree.pattern_dataand 'a pattern_data = {pat_desc : 'a;pat_loc : Location.t;pat_extra : (Typedtree.pat_extra * Location.t * Typedtree.attributes) list;pat_type : Types.type_expr;pat_env : Env.t;pat_attributes : Typedtree.attributes;pat_unique_barrier : Typedtree.Unique_barrier.t;(*This tracks whether the scrutinee of the pattern is used uniquely within the body of the pattern match.
*)
}and pat_extra = | Tpat_constraint of Typedtree.core_type(*P : T
*)pat_desc = P ; pat_extra = (Tpat_constraint T, _, _) :: ...| Tpat_type of Path.t * Longident.t Asttypes.loc(*#tconst
pat_desc = disjunction ; pat_extra = (Tpat_type (P, "tconst"), _, _) :: ...where
*)disjunctionis aTpat_or _representing the branches oftconst.| Tpat_open of Path.t * Longident.t Asttypes.loc * Env.t| Tpat_unpack(*(module P)
*)pat_desc = Tpat_var "P" ; pat_extra = (Tpat_unpack, _, _) :: ...(module _)pat_desc = Tpat_any ; pat_extra = (Tpat_unpack, _, _) :: ...
and 'k pattern_desc = | Tpat_any : Typedtree.value Typedtree.pattern_desc(*_
*)| Tpat_var : Ident.t * string Asttypes.loc * Uid.t * Jkind_types.Sort.t * Mode.Value.l -> Typedtree.value Typedtree.pattern_desc(*x
*)| Tpat_alias : Typedtree.value Typedtree.general_pattern * Ident.t * string Asttypes.loc * Uid.t * Jkind_types.Sort.t * Mode.Value.l * Types.type_expr -> Typedtree.value Typedtree.pattern_desc(*P as a
*)| Tpat_constant : Typedtree.constant -> Typedtree.value Typedtree.pattern_desc(*1, 'a', "true", 1.0, 1l, 1L, 1n
*)| Tpat_tuple : (string option * Typedtree.value Typedtree.general_pattern) list -> Typedtree.value Typedtree.pattern_desc(*(P1, ..., Pn)
(None,P1); ...; (None,Pn)) (L1:P1, ... Ln:Pn)(Some L1,P1); ...; (Some Ln,Pn)) Any mix, e.g. (L1:P1, P2)(Some L1,P1); ...; (None,P2))Invariant: n >= 2
*)| Tpat_unboxed_tuple : (string option * Typedtree.value Typedtree.general_pattern * Jkind.sort) list -> Typedtree.value Typedtree.pattern_desc(*#(P1, ..., Pn)
(None,P1,s1); ...; (None,Pn,sn)) #(L1:P1, ... Ln:Pn)(Some L1,P1,s1); ...; (Some Ln,Pn,sn)) Any mix, e.g. #(L1:P1, P2)(Some L1,P1,s1); ...; (None,P2,s2))Invariant: n >= 2
*)| Tpat_construct : Longident.t Asttypes.loc * Types.constructor_description * Typedtree.value Typedtree.general_pattern list * ((Ident.t Asttypes.loc * Parsetree.jkind_annotation option) list * Typedtree.core_type) option -> Typedtree.value Typedtree.pattern_desc(*C (, None) C P (
*)P, None) C (P1, ..., Pn) (P1; ...; Pn, None) C (P : t) (P, Some (, t)) C (P1, ..., Pn : t) (P1; ...; Pn, Some (, t)) C (type a) (P : t) (P, Some (a, t)) C (type a) (P1, ..., Pn : t) (P1; ...; Pn, Some (a, None, t)) C (type (a : k)) (P1, ..., Pn : t) (P1; ...; Pn, Some (a, Some k, t))| Tpat_variant : Asttypes.label * Typedtree.value Typedtree.general_pattern option * Types.row_desc Stdlib.ref -> Typedtree.value Typedtree.pattern_desc| Tpat_record : (Longident.t Asttypes.loc * Types.label_description * Typedtree.value Typedtree.general_pattern) list * Asttypes.closed_flag -> Typedtree.value Typedtree.pattern_desc(*l1=P1; ...; ln=Pn(flag = Closed)l1=P1; ...; ln=Pn; _(flag = Open)Invariant: n > 0
*)| Tpat_record_unboxed_product : (Longident.t Asttypes.loc * Types.unboxed_label_description * Typedtree.value Typedtree.general_pattern) list * Asttypes.closed_flag -> Typedtree.value Typedtree.pattern_desc(*#
l1=P1; ...; ln=Pn(flag = Closed) #l1=P1; ...; ln=Pn; _(flag = Open)Invariant: n > 0
*)| Tpat_array : Types.mutability * Jkind.sort * Typedtree.value Typedtree.general_pattern list -> Typedtree.value Typedtree.pattern_desc(*
*)| P1; ...; Pn |(flag = Mutable): P1; ...; Pn :(flag = Immutable)| Tpat_lazy : Typedtree.value Typedtree.general_pattern -> Typedtree.value Typedtree.pattern_desc(*lazy P
*)| Tpat_value : Typedtree.tpat_value_argument -> Typedtree.computation Typedtree.pattern_desc(*P
Invariant: Tpat_value pattern should not carry pat_attributes or pat_extra metadata coming from user syntax, which must be on the inner pattern node -- to facilitate searching for a certain value pattern constructor with a specific attributed.
To enforce this restriction, we made the argument of the Tpat_value constructor a private synonym of
*)pattern, requiring you to use theas_computation_patternfunction below instead of using theTpat_valueconstructor directly.| Tpat_exception : Typedtree.value Typedtree.general_pattern -> Typedtree.computation Typedtree.pattern_desc(*exception P
*)| Tpat_or : 'k Typedtree.general_pattern * 'k Typedtree.general_pattern * Types.row_desc option -> 'k Typedtree.pattern_desc(*P1 | P2
*)row_desc=Some _when translatingPpat_type _,Noneotherwise.
and tpat_value_argument = private Typedtree.value Typedtree.general_patternand expression = {exp_desc : Typedtree.expression_desc;exp_loc : Location.t;exp_extra : (Typedtree.exp_extra * Location.t * Typedtree.attributes) list;exp_type : Types.type_expr;exp_env : Env.t;exp_attributes : Typedtree.attributes;
}and exp_extra = | Texp_constraint of Typedtree.core_type(*E : T
*)| Texp_coerce of Typedtree.core_type option * Typedtree.core_type(*E :> T
*)Texp_coerce (None, T)E : T0 :> TTexp_coerce (Some T0, T)| Texp_poly of Typedtree.core_type option(*Used for method bodies.
*)| Texp_newtype of Ident.t * string Asttypes.loc * Parsetree.jkind_annotation option * Uid.t(*fun (type t : immediate) ->
The
*)Ident.tandUid.tfields are unused by the compiler, but Merlin needs them. Merlin cannot be cleanly patched to include these fields because Merlin must be able to deserialize typedtrees produced by the compiler. Thus, we include them here, as the cost of tracking this additional information is minimal.| Texp_stack(*stack_ E
*)| Texp_mode of Mode.Alloc.Const.Option.t(*E : _ @@ M
*)
and arg_label = Types.arg_label = and expression_desc = | Texp_ident of Path.t * Longident.t Asttypes.loc * Types.value_description * Typedtree.ident_kind * Typedtree.unique_use(*x M.x
*)| Texp_constant of Typedtree.constant(*1, 'a', "true", 1.0, 1l, 1L, 1n
*)| Texp_let of Asttypes.rec_flag * Typedtree.value_binding list * Typedtree.expression(*let P1 = E1 and ... and Pn = EN in E (flag = Nonrecursive) let rec P1 = E1 and ... and Pn = EN in E (flag = Recursive)
*)| Texp_letmutable of Typedtree.value_binding * Typedtree.expression(*let mutable P = E in E'
*)| Texp_function of {params : Typedtree.function_param list;body : Typedtree.function_body;ret_mode : Mode.Alloc.l;ret_sort : Jkind.sort;alloc_mode : Typedtree.alloc_mode;zero_alloc : Zero_alloc.t;
}(*fun P0 P1 -> function p1 -> e1 | p2 -> e2 (body = Tfunction_cases _) fun P0 P1 -> E (body = Tfunction_body _) This construct has the same arity as the originating
*)Pexp_function. Arity determines when side-effects for effectful parameters are run (e.g. optional argument defaults, matching against lazy patterns). Parameters' effects are run left-to-right when an n-ary function is saturated with n arguments.| Texp_apply of Typedtree.expression * (Typedtree.arg_label * Typedtree.apply_arg) list * Typedtree.apply_position * Mode.Locality.l * Zero_alloc.assume option(*E0 ~l1:E1 ... ~ln:En
The expression can be Omitted if the expression is abstracted over this argument. It currently appears when a label is applied.
For example: let f x ~y = x + y in f ~y:3
The resulting typedtree for the application is: Texp_apply (Texp_ident "f/1037",
(Nolabel, Omitted _); (Labelled "y", Some (Texp_constant Const_int 3)))The
*)Zero_alloc.assume optionrecords the optional@zero_alloc assumeattribute that may appear on applications.| Texp_match of Typedtree.expression * Jkind.sort * Typedtree.computation Typedtree.case list * Typedtree.partial(*match E0 with | P1 -> E1 | P2 | exception P3 -> E2 | exception P4 -> E3
*)Texp_match (E0, sort_of_E0, [(P1, E1); (P2 | exception P3, E2); (exception P4, E3)], _)| Texp_try of Typedtree.expression * Typedtree.value Typedtree.case list(*try E with P1 -> E1 | ... | PN -> EN
*)| Texp_tuple of (string option * Typedtree.expression) list * Typedtree.alloc_mode(*Texp_tuple(el)represents(E1, ..., En)whenelis(None, E1);...;(None, En),(L1:E1, ..., Ln:En)whenelis(Some L1, E1);...;(Some Ln, En),- Any mix, e.g.
(L1: E1, E2)whenelis(Some L1, E1); (None, E2)
| Texp_unboxed_tuple of (string option * Typedtree.expression * Jkind.sort) list(*Texp_unboxed_tuple(el)represents#(E1, ..., En)whenelis(None, E1, s1);...;(None, En, sn),#(L1:E1, ..., Ln:En)whenelis(Some L1, E1, s1);...;(Some Ln, En, sn),- Any mix, e.g.
#(L1: E1, E2)whenelis(Some L1, E1, s1); (None, E2, s2)
| Texp_construct of Longident.t Asttypes.loc * Types.constructor_description * Typedtree.expression list * Typedtree.alloc_mode option(*C C E
EC (E1, ..., En)E1;...;En
*)alloc_modeis the allocation mode of the construct, orNoneif the constructor isCstr_unboxedorCstr_constant, in which case it does not need allocation.| Texp_variant of Asttypes.label * (Typedtree.expression * Typedtree.alloc_mode) option(*
*)alloc_modeis the allocation mode of the variant, orNoneif the variant has no argument, in which case it does not need allocation.| Texp_record of {fields : (Types.label_description * Typedtree.record_label_definition) array;representation : Types.record_representation;extended_expression : (Typedtree.expression * Jkind.sort * Typedtree.Unique_barrier.t) option;alloc_mode : Typedtree.alloc_mode option;
}(*l1=P1; ...; ln=Pn(extended_expression = None)E0 with l1=P1; ...; ln=Pn(extended_expression = Some E0)Invariant: n > 0
If the type is
*)l1: t1; l2: t2, the expressionE0 with t2=P2is represented as Texp_recordfields = [| l1, Kept t1; l2 Override P2 |]; representation; extended_expression = Some E0alloc_modeis the allocation mode of the record, orNoneif it isRecord_unboxed, in which case it does not need allocation.| Texp_record_unboxed_product of {fields : (Types.unboxed_label_description * Typedtree.record_label_definition) array;representation : Types.record_unboxed_product_representation;extended_expression : (Typedtree.expression * Jkind.sort) option;
}(*#
l1=P1; ...; ln=Pn(extended_expression = None) #E0 with l1=P1; ...; ln=Pn(extended_expression = Some E0)Invariant: n > 0
If the type is #
*)l1: t1; l2: t2, the expression #E0 with t2=P2is represented as Texp_record_unboxed_productfields = [| l1, Kept t1; l2 Override P2 |]; representation; extended_expression = Some E0| Texp_atomic_loc of Typedtree.expression * Jkind.sort * Longident.t Asttypes.loc * Types.label_description * Typedtree.alloc_mode| Texp_field of Typedtree.expression * Jkind.sort * Longident.t Asttypes.loc * Types.label_description * Typedtree.texp_field_boxing * Typedtree.Unique_barrier.t(*The sort is the sort of the whole record (which may be non-value if the record is @
@unboxed
).
texp_field_boxingprovides extra information depending on if the projection requires boxing.
| Texp_unboxed_field of Typedtree.expression * Jkind.sort * Longident.t Asttypes.loc * Types.unboxed_label_description * Typedtree.unique_use| Texp_setfield of Typedtree.expression * Mode.Locality.l * Longident.t Asttypes.loc * Types.label_description * Typedtree.expression(*
*)alloc_modetranslates to themodify_modeof the record| Texp_array of Types.mutability * Jkind.Sort.t * Typedtree.expression list * Typedtree.alloc_mode| Texp_idx of Typedtree.block_access * Typedtree.unboxed_access list| Texp_list_comprehension of Typedtree.comprehension| Texp_array_comprehension of Types.mutability * Jkind.sort * Typedtree.comprehension| Texp_ifthenelse of Typedtree.expression * Typedtree.expression * Typedtree.expression option| Texp_sequence of Typedtree.expression * Jkind.sort * Typedtree.expression| Texp_while of {wh_cond : Typedtree.expression;wh_body : Typedtree.expression;wh_body_sort : Jkind.sort;
}| Texp_for of {for_id : Ident.t;for_debug_uid : Shape.Uid.t;for_pat : Parsetree.pattern;for_from : Typedtree.expression;for_to : Typedtree.expression;for_dir : Asttypes.direction_flag;for_body : Typedtree.expression;for_body_sort : Jkind.sort;
}| Texp_send of Typedtree.expression * Typedtree.meth * Typedtree.apply_position| Texp_new of Path.t * Longident.t Asttypes.loc * Types.class_declaration * Typedtree.apply_position| Texp_instvar of Path.t * Path.t * string Asttypes.loc| Texp_mutvar of Ident.t Asttypes.loc| Texp_setinstvar of Path.t * Path.t * string Asttypes.loc * Typedtree.expression| Texp_setmutvar of Ident.t Asttypes.loc * Jkind.sort * Typedtree.expression| Texp_override of Path.t * (Ident.t * string Asttypes.loc * Typedtree.expression) list| Texp_letmodule of Ident.t option * string option Asttypes.loc * Types.module_presence * Typedtree.module_expr * Typedtree.expression| Texp_letexception of Typedtree.extension_constructor * Typedtree.expression| Texp_assert of Typedtree.expression * Location.t| Texp_lazy of Typedtree.expression| Texp_object of Typedtree.class_structure * string list| Texp_pack of Typedtree.module_expr| Texp_letop of {let_ : Typedtree.binding_op;ands : Typedtree.binding_op list;param : Ident.t;param_debug_uid : Shape.Uid.t;param_sort : Jkind.sort;body : Typedtree.value Typedtree.case;body_sort : Jkind.sort;partial : Typedtree.partial;
}| Texp_unreachable| Texp_extension_constructor of Longident.t Asttypes.loc * Path.t| Texp_open of Typedtree.open_declaration * Typedtree.expression(*let open
*)!M in e| Texp_probe of {name : string;handler : Typedtree.expression;enabled_at_init : bool;
}| Texp_probe_is_enabled of {}| Texp_exclave of Typedtree.expression| Texp_src_pos| Texp_overwrite of Typedtree.expression * Typedtree.expression(*overwrite_ exp with exp
*)| Texp_hole of Typedtree.unique_use(*_
*)| Texp_quotation of Typedtree.expression| Texp_antiquotation of Typedtree.expression| Texp_eval of Typedtree.core_type * Jkind.sort
Jkinds in the typed tree: Compilation of the typed tree to lambda sometimes requires jkind information. Our approach is to propagate jkind information inward during compilation. This requires us to annotate places in the typed tree where the jkind of a type of a subexpression is not determined by the jkind of the type of the expression containing it. For example, to the left of a semicolon, or in value_bindings.
CR layouts v1.5: Some of these were mainly needed for void (e.g., left of a semicolon). If we redo how void is compiled, perhaps we can drop those. On the other hand, there are some places we're not annotating now (e.g., function arguments) that will need annotations in the future because we'll allow other jkinds there. Just do a rationalization pass on this.
and function_param = {fp_arg_label : Typedtree.arg_label;fp_param : Ident.t;(*
*)fp_paramis the identifier that is to be used to name the parameter of the function.fp_param_debug_uid : Shape.Uid.t;fp_partial : Typedtree.partial;(*
*)fp_partial=Partialif the pattern match is partialTotalotherwise.fp_kind : Typedtree.function_param_kind;fp_sort : Jkind.sort;fp_mode : Mode.Alloc.l;fp_curry : Typedtree.function_curry;fp_newtypes : (Ident.t * string Asttypes.loc * Parsetree.jkind_annotation option * Uid.t) list;(*fp_newtypesare the new type declarations that come *after* that parameter. The newtypes that come before the first parameter are placed as exp_extras on the Texp_function node. This is just used inUntypeast.The
*)Ident.tandUid.tfields are unused by the compiler, but Merlin needs them. Merlin cannot be cleanly patched to include these fields because Merlin must be able to deserialize typedtrees produced by the compiler. Thus, we include them here, as the cost of tracking this additional information is minimal.fp_loc : Location.t;(*
*)fp_locis the location of the entire value parameter, not including thefp_newtypes.
}and function_param_kind = | Tparam_pat of Typedtree.pattern(*
*)Tparam_pat pis a non-optional argument with patternp.| Tparam_optional_default of Typedtree.pattern * Typedtree.expression * Jkind.sort(*
*)Tparam_optional_default (p, e, sort)is an optional argumentpwith default valuee, i.e.?x:(p = e). If the parameter is of typea option, the pattern and expression are of typea.sortis the sort ofe.
and function_body = | Tfunction_body of Typedtree.expression| Tfunction_cases of Typedtree.function_cases(*The function body binds a final argument in
*)Tfunction_cases, and this argument is pattern-matched against the cases.
and function_cases = {fc_cases : Typedtree.value Typedtree.case list;fc_env : Env.t;(*
*)fc_envcontains entries from all parameters except for the last one being matched by the cases.fc_arg_mode : Mode.Alloc.l;fc_arg_sort : Jkind.sort;fc_ret_type : Types.type_expr;fc_partial : Typedtree.partial;fc_param : Ident.t;fc_param_debug_uid : Shape.Uid.t;fc_loc : Location.t;fc_exp_extra : Typedtree.exp_extra option;fc_attributes : Typedtree.attributes;(*
*)fc_attributesis just used in untypeast.
}and block_access = | Baccess_field of Longident.t Asttypes.loc * Types.label_description| Baccess_array of {mut : Asttypes.mutable_flag;index_kind : Asttypes.index_kind;index : Typedtree.expression;base_ty : Types.type_expr;elt_ty : Types.type_expr;elt_sort : Jkind.Sort.t;
}| Baccess_block of Asttypes.mutable_flag * Typedtree.expression
and unboxed_access = | Uaccess_unboxed_field of Longident.t Asttypes.loc * Types.unboxed_label_description
and comprehension = {comp_body : Typedtree.expression;comp_clauses : Typedtree.comprehension_clause list;
}and comprehension_clause = | Texp_comp_for of Typedtree.comprehension_clause_binding list| Texp_comp_when of Typedtree.expression
and comprehension_clause_binding = {comp_cb_iterator : Typedtree.comprehension_iterator;comp_cb_attributes : Typedtree.attribute list;(*No built-in attributes are meaningful here; this would correspond to
*)[body for[@attr] x in xs], and there are no built-in attributes that would be efficacious there. (The only ones that might make sense would be inlining, but you can't do that with list/array items that are being iterated over.)
}We move the pattern into the comprehension_iterator, compared to the untyped syntax tree, so that range-based iterators can have just an identifier instead of a full pattern
and comprehension_iterator = | Texp_comp_range of {ident : Ident.t;ident_debug_uid : Shape.Uid.t;pattern : Parsetree.pattern;(*Redundant with
*)identstart : Typedtree.expression;stop : Typedtree.expression;direction : Asttypes.direction_flag;
}| Texp_comp_in of {pattern : Typedtree.pattern;sequence : Typedtree.expression;
}
and 'k case = {c_lhs : 'k Typedtree.general_pattern;c_guard : Typedtree.expression option;c_rhs : Typedtree.expression;
}and record_label_definition = | Kept of Types.type_expr * Types.mutability * Typedtree.unique_use| Overridden of Longident.t Asttypes.loc * Typedtree.expression
and binding_op = {bop_op_path : Path.t;bop_op_name : string Asttypes.loc;bop_op_val : Types.value_description;bop_op_type : Types.type_expr;bop_op_return_sort : Jkind.sort;bop_exp : Typedtree.expression;bop_exp_sort : Jkind.sort;bop_loc : Location.t;
}and omitted_parameter = {mode_closure : Mode.Alloc.r;mode_arg : Mode.Alloc.l;mode_ret : Mode.Alloc.l;sort_arg : Jkind.sort;sort_ret : Jkind.sort;
}and apply_arg =
(Typedtree.expression * Jkind.sort, Typedtree.omitted_parameter)
Typedtree.arg_or_omittedand class_expr = {cl_desc : Typedtree.class_expr_desc;cl_loc : Location.t;cl_type : Types.class_type;cl_env : Env.t;cl_attributes : Typedtree.attributes;
}and class_expr_desc = | Tcl_ident of Path.t * Longident.t Asttypes.loc * Typedtree.core_type list| Tcl_structure of Typedtree.class_structure| Tcl_fun of Typedtree.arg_label * Typedtree.pattern * (Ident.t * Typedtree.expression) list * Typedtree.class_expr * Typedtree.partial| Tcl_apply of Typedtree.class_expr * (Typedtree.arg_label * Typedtree.apply_arg) list| Tcl_let of Asttypes.rec_flag * Typedtree.value_binding list * (Ident.t * Typedtree.expression) list * Typedtree.class_expr| Tcl_constraint of Typedtree.class_expr * Typedtree.class_type option * string list * string list * Types.MethSet.t| Tcl_open of Typedtree.open_description * Typedtree.class_expr
and class_structure = {cstr_self : Typedtree.pattern;cstr_fields : Typedtree.class_field list;cstr_type : Types.class_signature;cstr_meths : Ident.t Types.Meths.t;
}and class_field = {cf_desc : Typedtree.class_field_desc;cf_loc : Location.t;cf_attributes : Typedtree.attributes;
}and class_field_kind = | Tcfk_virtual of Typedtree.core_type| Tcfk_concrete of Asttypes.override_flag * Typedtree.expression
and class_field_desc = | Tcf_inherit of Asttypes.override_flag * Typedtree.class_expr * string option * (string * Ident.t) list * (string * Ident.t) list| Tcf_val of string Asttypes.loc * Asttypes.mutable_flag * Ident.t * Typedtree.class_field_kind * bool| Tcf_method of string Asttypes.loc * Asttypes.private_flag * Typedtree.class_field_kind| Tcf_constraint of Typedtree.core_type * Typedtree.core_type| Tcf_initializer of Typedtree.expression| Tcf_attribute of Typedtree.attribute
and held_locks = Env.locks * Longident.t * Location.tand mode_with_locks = Mode.Value.l * Typedtree.held_locks optionand module_expr = {mod_desc : Typedtree.module_expr_desc;mod_loc : Location.t;mod_type : Types.module_type;mod_mode : Typedtree.mode_with_locks;(*The mode of the module. The second component is
*)Someifhold_locksis requested and the module is an identifier.mod_env : Env.t;mod_attributes : Typedtree.attributes;
}and module_type_constraint = | Tmodtype_implicit(*The module type constraint has been synthesized during typechecking.
*)| Tmodtype_explicit of Typedtree.module_type(*The module type was in the source file.
*)
Annotations for Tmod_constraint.
and functor_parameter = | Unit| Named of Ident.t option * string option Asttypes.loc * Typedtree.module_type
and module_expr_desc = | Tmod_ident of Path.t * Longident.t Asttypes.loc| Tmod_structure of Typedtree.structure| Tmod_functor of Typedtree.functor_parameter * Typedtree.module_expr| Tmod_apply of Typedtree.module_expr * Typedtree.module_expr * Typedtree.module_coercion| Tmod_apply_unit of Typedtree.module_expr| Tmod_constraint of Typedtree.module_expr * Types.module_type * Typedtree.module_type_constraint * Typedtree.module_coercion(*ME (constraint = Tmodtype_implicit) (ME : MT) (constraint = Tmodtype_explicit MT)
*)| Tmod_unpack of Typedtree.expression * Types.module_type
and structure = {str_items : Typedtree.structure_item list;str_type : Types.signature;str_final_env : Env.t;
}and structure_item = {str_desc : Typedtree.structure_item_desc;str_loc : Location.t;str_env : Env.t;
}and structure_item_desc = | Tstr_eval of Typedtree.expression * Jkind.sort * Typedtree.attributes| Tstr_value of Asttypes.rec_flag * Typedtree.value_binding list| Tstr_primitive of Typedtree.value_description| Tstr_type of Asttypes.rec_flag * Typedtree.type_declaration list| Tstr_typext of Typedtree.type_extension| Tstr_exception of Typedtree.type_exception| Tstr_module of Typedtree.module_binding| Tstr_recmodule of Typedtree.module_binding list| Tstr_modtype of Typedtree.module_type_declaration| Tstr_open of Typedtree.open_declaration| Tstr_class of (Typedtree.class_declaration * string list) list| Tstr_class_type of (Ident.t * string Asttypes.loc * Typedtree.class_type_declaration) list| Tstr_include of Typedtree.include_declaration| Tstr_attribute of Typedtree.attribute
and module_binding = {mb_id : Ident.t option;(*
*)Noneformodule _ = struct ... endmb_name : string option Asttypes.loc;mb_uid : Uid.t;mb_presence : Types.module_presence;mb_expr : Typedtree.module_expr;mb_attributes : Typedtree.attributes;mb_loc : Location.t;
}and value_binding = {vb_pat : Typedtree.pattern;vb_expr : Typedtree.expression;vb_rec_kind : Value_rec_types.recursive_binding_kind;vb_sort : Jkind.sort;vb_attributes : Typedtree.attributes;vb_loc : Location.t;
}and module_coercion = | Tcoerce_none| Tcoerce_structure of {input_repr : Types.module_representation;output_repr : Types.module_representation;pos_cc_list : (int * Typedtree.module_coercion) list;id_pos_list : (Ident.t * int * Typedtree.module_coercion) list;
}| Tcoerce_functor of Typedtree.module_coercion * Typedtree.module_coercion| Tcoerce_primitive of Typedtree.primitive_coercion(*External declaration coerced to a regular value.
module M : sig val ext : a -> b end = struct external ext : a -> b = "my_c_function" endOnly occurs inside a
*)Tcoerce_structurecoercion.| Tcoerce_alias of Env.t * Path.t * Typedtree.module_coercion(*Module alias coerced to a regular module.
module M : sig module Sub : T end = struct module Sub = Some_alias endOnly occurs inside a
*)Tcoerce_structurecoercion.
and module_type = {mty_desc : Typedtree.module_type_desc;mty_type : Types.module_type;mty_env : Env.t;mty_loc : Location.t;mty_attributes : Typedtree.attributes;
}and module_type_desc = | Tmty_ident of Path.t * Longident.t Asttypes.loc| Tmty_signature of Typedtree.signature| Tmty_functor of Typedtree.functor_parameter * Typedtree.module_type| Tmty_with of Typedtree.module_type * (Path.t * Longident.t Asttypes.loc * Typedtree.with_constraint) list| Tmty_typeof of Typedtree.module_expr| Tmty_alias of Path.t * Longident.t Asttypes.loc| Tmty_strengthen of Typedtree.module_type * Path.t * Longident.t Asttypes.loc
and primitive_coercion = {pc_desc : Primitive.description;pc_type : Types.type_expr;pc_poly_mode : Mode.Locality.l option;pc_poly_sort : Jkind.Sort.t option;pc_env : Env.t;pc_loc : Location.t;
}and signature = {sig_items : Typedtree.signature_item list;sig_modalities : Mode.Modality.Const.t;sig_type : Types.signature;sig_final_env : Env.t;sig_sloc : Location.t;
}and signature_item = {sig_desc : Typedtree.signature_item_desc;sig_env : Env.t;sig_loc : Location.t;
}and signature_item_desc = | Tsig_value of Typedtree.value_description| Tsig_type of Asttypes.rec_flag * Typedtree.type_declaration list| Tsig_typesubst of Typedtree.type_declaration list| Tsig_typext of Typedtree.type_extension| Tsig_exception of Typedtree.type_exception| Tsig_module of Typedtree.module_declaration| Tsig_modsubst of Typedtree.module_substitution| Tsig_recmodule of Typedtree.module_declaration list| Tsig_modtype of Typedtree.module_type_declaration| Tsig_modtypesubst of Typedtree.module_type_declaration| Tsig_open of Typedtree.open_description| Tsig_include of Typedtree.include_description * Mode.Modality.Const.t| Tsig_class of Typedtree.class_description list| Tsig_class_type of Typedtree.class_type_declaration list| Tsig_attribute of Typedtree.attribute
and module_declaration = {md_id : Ident.t option;md_name : string option Asttypes.loc;md_uid : Uid.t;md_presence : Types.module_presence;md_type : Typedtree.module_type;md_modalities : Mode.Modality.t;md_attributes : Typedtree.attributes;md_loc : Location.t;
}and module_substitution = {ms_id : Ident.t;ms_name : string Asttypes.loc;ms_uid : Uid.t;ms_manifest : Path.t;ms_txt : Longident.t Asttypes.loc;ms_attributes : Typedtree.attributes;ms_loc : Location.t;
}and module_type_declaration = {mtd_id : Ident.t;mtd_name : string Asttypes.loc;mtd_uid : Uid.t;mtd_type : Typedtree.module_type option;mtd_attributes : Typedtree.attributes;mtd_loc : Location.t;
}and 'a open_infos = {open_expr : 'a;open_bound_items : Types.signature;open_items_repr : Types.module_representation;open_override : Asttypes.override_flag;open_env : Env.t;open_loc : Location.t;open_attributes : Typedtree.attribute list;
}and open_description = (Path.t * Longident.t Asttypes.loc) Typedtree.open_infosand open_declaration = Typedtree.module_expr Typedtree.open_infosand include_kind = | Tincl_structure| Tincl_functor of {input_coercion : (Ident.t * Typedtree.module_coercion) list;input_repr : Types.module_representation;
}| Tincl_gen_functor of {input_coercion : (Ident.t * Typedtree.module_coercion) list;input_repr : Types.module_representation;
}
and 'a include_infos = {incl_mod : 'a;incl_type : Types.signature;incl_repr : Types.module_representation;incl_loc : Location.t;incl_kind : Typedtree.include_kind;incl_attributes : Typedtree.attribute list;
}and include_description = Typedtree.module_type Typedtree.include_infosand include_declaration = Typedtree.module_expr Typedtree.include_infosand with_constraint = | Twith_type of Typedtree.type_declaration| Twith_module of Path.t * Longident.t Asttypes.loc| Twith_modtype of Typedtree.module_type| Twith_typesubst of Typedtree.type_declaration| Twith_modsubst of Path.t * Longident.t Asttypes.loc| Twith_modtypesubst of Typedtree.module_type
and core_type = {mutable ctyp_desc : Typedtree.core_type_desc;(*mutable because of
*)Typeclass.declare_methodmutable ctyp_type : Types.type_expr;(*mutable because of
*)Typeclass.declare_methodctyp_env : Env.t;ctyp_loc : Location.t;ctyp_attributes : Typedtree.attributes;
}and core_type_desc = | Ttyp_var of string option * Parsetree.jkind_annotation option| Ttyp_arrow of Typedtree.arg_label * Typedtree.core_type * Typedtree.core_type| Ttyp_tuple of (string option * Typedtree.core_type) list| Ttyp_unboxed_tuple of (string option * Typedtree.core_type) list| Ttyp_constr of Path.t * Longident.t Asttypes.loc * Typedtree.core_type list| Ttyp_object of Typedtree.object_field list * Asttypes.closed_flag| Ttyp_class of Path.t * Longident.t Asttypes.loc * Typedtree.core_type list| Ttyp_alias of Typedtree.core_type * string Asttypes.loc option * Parsetree.jkind_annotation option| Ttyp_variant of Typedtree.row_field list * Asttypes.closed_flag * Asttypes.label list option| Ttyp_poly of (string * Parsetree.jkind_annotation option) list * Typedtree.core_type| Ttyp_package of Typedtree.package_type| Ttyp_open of Path.t * Longident.t Asttypes.loc * Typedtree.core_type| Ttyp_quote of Typedtree.core_type| Ttyp_splice of Typedtree.core_type| Ttyp_of_kind of Parsetree.jkind_annotation| Ttyp_call_pos(*
*)Ttyp_call_posrepresents the type of the value of a Position argument (lbl:[%call_pos] -> ...).
and package_type = {pack_path : Path.t;pack_fields : (Longident.t Asttypes.loc * Typedtree.core_type) list;pack_type : Types.module_type;pack_txt : Longident.t Asttypes.loc;
}and row_field = {rf_desc : Typedtree.row_field_desc;rf_loc : Location.t;rf_attributes : Typedtree.attributes;
}and row_field_desc = | Ttag of string Asttypes.loc * bool * Typedtree.core_type list| Tinherit of Typedtree.core_type
and object_field = {of_desc : Typedtree.object_field_desc;of_loc : Location.t;of_attributes : Typedtree.attributes;
}and object_field_desc = | OTtag of string Asttypes.loc * Typedtree.core_type| OTinherit of Typedtree.core_type
and value_description = {val_id : Ident.t;val_name : string Asttypes.loc;val_desc : Typedtree.core_type;val_val : Types.value_description;val_prim : string list;val_loc : Location.t;val_attributes : Typedtree.attributes;
}and type_declaration = {typ_id : Ident.t;typ_name : string Asttypes.loc;typ_params : (Typedtree.core_type * (Asttypes.variance * Asttypes.injectivity)) list;typ_type : Types.type_declaration;typ_cstrs : (Typedtree.core_type * Typedtree.core_type * Location.t) list;typ_kind : Typedtree.type_kind;typ_private : Asttypes.private_flag;typ_manifest : Typedtree.core_type option;typ_loc : Location.t;typ_attributes : Typedtree.attributes;typ_jkind_annotation : Parsetree.jkind_annotation option;
}and type_kind = | Ttype_abstract| Ttype_variant of Typedtree.constructor_declaration list| Ttype_record of Typedtree.label_declaration list| Ttype_record_unboxed_product of Typedtree.label_declaration list| Ttype_open
and label_declaration = {ld_id : Ident.t;ld_name : string Asttypes.loc;ld_uid : Uid.t;ld_mutable : Types.mutability;ld_modalities : Mode.Modality.Const.t;ld_type : Typedtree.core_type;ld_loc : Location.t;ld_attributes : Typedtree.attributes;
}and constructor_declaration = {cd_id : Ident.t;cd_name : string Asttypes.loc;cd_uid : Uid.t;cd_vars : (string * Parsetree.jkind_annotation option) list;cd_args : Typedtree.constructor_arguments;cd_res : Typedtree.core_type option;cd_loc : Location.t;cd_attributes : Typedtree.attributes;
}and constructor_argument = {ca_modalities : Mode.Modality.Const.t;ca_type : Typedtree.core_type;ca_loc : Location.t;
}and constructor_arguments = | Cstr_tuple of Typedtree.constructor_argument list| Cstr_record of Typedtree.label_declaration list
and type_extension = {tyext_path : Path.t;tyext_txt : Longident.t Asttypes.loc;tyext_params : (Typedtree.core_type * (Asttypes.variance * Asttypes.injectivity)) list;tyext_constructors : Typedtree.extension_constructor list;tyext_private : Asttypes.private_flag;tyext_loc : Location.t;tyext_attributes : Typedtree.attributes;
}and type_exception = {tyexn_constructor : Typedtree.extension_constructor;tyexn_loc : Location.t;tyexn_attributes : Typedtree.attribute list;
}and extension_constructor = {ext_id : Ident.t;ext_name : string Asttypes.loc;ext_type : Types.extension_constructor;ext_kind : Typedtree.extension_constructor_kind;ext_loc : Location.t;ext_attributes : Typedtree.attributes;
}and extension_constructor_kind = | Text_decl of (string * Parsetree.jkind_annotation option) list * Typedtree.constructor_arguments * Typedtree.core_type option| Text_rebind of Path.t * Longident.t Asttypes.loc
and class_type = {cltyp_desc : Typedtree.class_type_desc;cltyp_type : Types.class_type;cltyp_env : Env.t;cltyp_loc : Location.t;cltyp_attributes : Typedtree.attributes;
}and class_type_desc = | Tcty_constr of Path.t * Longident.t Asttypes.loc * Typedtree.core_type list| Tcty_signature of Typedtree.class_signature| Tcty_arrow of Typedtree.arg_label * Typedtree.core_type * Typedtree.class_type| Tcty_open of Typedtree.open_description * Typedtree.class_type
and class_signature = {csig_self : Typedtree.core_type;csig_fields : Typedtree.class_type_field list;csig_type : Types.class_signature;
}and class_type_field = {ctf_desc : Typedtree.class_type_field_desc;ctf_loc : Location.t;ctf_attributes : Typedtree.attributes;
}and class_type_field_desc = | Tctf_inherit of Typedtree.class_type| Tctf_val of string * Asttypes.mutable_flag * Asttypes.virtual_flag * Typedtree.core_type| Tctf_method of string * Asttypes.private_flag * Asttypes.virtual_flag * Typedtree.core_type| Tctf_constraint of Typedtree.core_type * Typedtree.core_type| Tctf_attribute of Typedtree.attribute
and class_declaration = Typedtree.class_expr Typedtree.class_infosand class_description = Typedtree.class_type Typedtree.class_infosand class_type_declaration = Typedtree.class_type Typedtree.class_infosand 'a class_infos = {ci_virt : Asttypes.virtual_flag;ci_params : (Typedtree.core_type * (Asttypes.variance * Asttypes.injectivity)) list;ci_id_name : string Asttypes.loc;ci_id_class : Ident.t;ci_id_class_type : Ident.t;ci_id_object : Ident.t;ci_expr : 'a;ci_decl : Types.class_declaration;ci_type_decl : Types.class_type_declaration;ci_loc : Location.t;ci_attributes : Typedtree.attributes;
}type argument_interface = {ai_signature : Types.signature;ai_coercion_from_primary : Typedtree.module_coercion;
}For a module M compiled with -as-argument-for P for some parameter module P, the signature of P along with the coercion from M's exported signature (the _primary interface_) to P's signature (the _argument interface_).
type implementation = {structure : Typedtree.structure;coercion : Typedtree.module_coercion;signature : Types.signature;argument_interface : Typedtree.argument_interface option;shape : Shape.t;
}A typechecked implementation including its module structure, its exported signature, and a coercion of the module against that signature.
If an .mli file is present, the signature will come from that file and be the exported signature of the module.
If there isn't one, the signature will be inferred from the module structure.
If the module is compiled with -as-argument-for and is thus typechecked against the .mli for a parameter in addition to its own .mli, it has an additional signature stored in argument_interface.
type item_declaration = | Value of Typedtree.value_description| Value_binding of Typedtree.value_binding| Type of Typedtree.type_declaration| Constructor of Typedtree.constructor_declaration| Extension_constructor of Typedtree.extension_constructor| Label of Typedtree.label_declaration| Module of Typedtree.module_declaration| Module_substitution of Typedtree.module_substitution| Module_binding of Typedtree.module_binding| Module_type of Typedtree.module_type_declaration| Class of Typedtree.class_declaration| Class_type of Typedtree.class_type_declaration(*
*)item_declarationgroups together items that correspond to the syntactic category of "declarations" which include types, values, modules, etc. declarations in signatures and their definitions in implementations.
val as_computation_pattern :
Typedtree.pattern ->
Typedtree.computation Typedtree.general_patternas_computation_pattern p is a computation pattern with description Tpat_value p, which enforces a correct placement of pat_attributes and pat_extra metadata (on the inner value pattern, rather than on the computation pattern).
val classify_pattern_desc :
'k Typedtree.pattern_desc ->
'k Typedtree.pattern_categoryval classify_pattern :
'k Typedtree.general_pattern ->
'k Typedtree.pattern_categoryval shallow_iter_pattern_desc :
Typedtree.pattern_action ->
'k Typedtree.pattern_desc ->
unittype pattern_transformation = {f : 'k. 'k Typedtree.general_pattern -> 'k Typedtree.general_pattern;
}val shallow_map_pattern_desc :
Typedtree.pattern_transformation ->
'k Typedtree.pattern_desc ->
'k Typedtree.pattern_descval iter_general_pattern :
Typedtree.pattern_action ->
'k Typedtree.general_pattern ->
unitval iter_pattern : (Typedtree.pattern -> unit) -> Typedtree.pattern -> unitval exists_general_pattern :
Typedtree.pattern_predicate ->
'k Typedtree.general_pattern ->
boolval exists_pattern : (Typedtree.pattern -> bool) -> Typedtree.pattern -> boolval let_bound_idents : Typedtree.value_binding list -> Ident.t listval let_bound_idents_with_sorts :
Typedtree.value_binding list ->
(Ident.t * Jkind.Sort.t) listval let_bound_idents_full :
Typedtree.value_binding list ->
(Ident.t * string Asttypes.loc * Types.type_expr * Jkind.Sort.t * Uid.t) listval let_bound_idents_with_modes_sorts_and_checks :
Typedtree.value_binding list ->
(Ident.t * (Location.t * Mode.Value.l * Jkind.sort) list * Zero_alloc.t) listval alpha_pat :
(Ident.t * Ident.t) list ->
'k Typedtree.general_pattern ->
'k Typedtree.general_patternAlpha conversion of patterns
val mknoloc : 'a -> 'a Asttypes.locval mkloc : 'a -> Location.t -> 'a Asttypes.locval pat_bound_idents : 'k Typedtree.general_pattern -> Ident.t listval pat_bound_idents_full :
'k Typedtree.general_pattern ->
(Ident.t
* string Asttypes.loc
* Types.type_expr
* Types.Uid.t
* Jkind.Sort.Const.t)
listval split_pattern :
Typedtree.computation Typedtree.general_pattern ->
Typedtree.pattern option * Typedtree.pattern optionSplits an or pattern into its value (left) and exception (right) parts.
val exp_is_nominal : Typedtree.expression -> boolWhether an expression looks nice as the subject of a sentence in a error message.
val function_arity :
Typedtree.function_param list ->
Typedtree.function_body ->
intCalculates the syntactic arity of a function based on its parameters and body.
val loc_of_decl :
uid:Shape.Uid.t ->
Typedtree.item_declaration ->
string Location.locGiven a declaration, return the location of the bound identifier
val min_mode_with_locks : Typedtree.mode_with_locksWhen type checking F(M).t, which does not involve modes, we say F(M) is of the strongest mode, to avoid modes in error messages.
val mode_without_locks_exn : Typedtree.mode_with_locks -> Mode.Value.lGet the mode, asserting no held locks.
val fold_antiquote_exp :
('a -> Typedtree.expression -> 'a) ->
'a ->
Typedtree.expression ->
'aFold over the antiquotations in an expression. This function defines the evaluation order of antiquotations.