-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathtypetexp.mli
194 lines (162 loc) · 7.97 KB
/
typetexp.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
(**************************************************************************)
(* *)
(* OCaml *)
(* *)
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 1996 Institut National de Recherche en Informatique et *)
(* en Automatique. *)
(* *)
(* All rights reserved. This file is distributed under the terms of *)
(* the GNU Lesser General Public License version 2.1, with the *)
(* special exception on linking described in the file LICENSE. *)
(* *)
(**************************************************************************)
(* Typechecking of type expressions for the core language *)
open Types
open Mode
type jkind_initialization_choice = Sort | Any
module TyVarEnv : sig
(* this is just the subset of [TyVarEnv] that is needed outside
of [Typetexp]. See the ml file for more. *)
val reset : unit -> unit
(** removes all type variables from scope *)
val with_local_scope : (unit -> 'a) -> 'a
(** Evaluate in a narrowed type-variable scope *)
type poly_univars
val make_poly_univars : string Location.loc list -> poly_univars
(** A variant of [make_poly_univars_jkinds] that gets variables
without jkind annotations *)
val make_poly_univars_jkinds :
context:(string -> Jkind.History.annotation_context_lr) ->
(string Location.loc * Parsetree.jkind_annotation option) list ->
poly_univars
(** remember that a list of strings connotes univars; this must
always be paired with a [check_poly_univars]. *)
val check_poly_univars :
Env.t -> Location.t -> poly_univars -> type_expr list
(** Verify that the given univars are universally quantified,
and return the list of variables. The type in which the
univars are used must be generalised *)
val instance_poly_univars :
Env.t -> Location.t -> poly_univars -> type_expr list
(** Same as [check_poly_univars], but instantiates the resulting
type scheme (i.e. variables become Tvar rather than Tunivar) *)
end
(* Forward declaration, to be filled in by Typemod.type_open *)
val type_open:
(?used_slot:bool ref -> Asttypes.override_flag -> Env.t -> Location.t ->
Longident.t Asttypes.loc -> Path.t * Env.t)
ref
val valid_tyvar_name : string -> bool
(** [transl_label lbl ty] produces a Typedtree argument label for an argument
with label [lbl] and type [ty].
Position arguments ([lbl:[%call_pos] -> ...]) are parsed as
{{!Parsetree.arg_label.Labelled}[Labelled l]}. This function converts them
to {{!Types.arg_label.Position}[Position l]} when the type is of the form
[[%call_pos]]. *)
val transl_label :
Parsetree.arg_label -> Parsetree.core_type option -> Types.arg_label
(** Produces a Typedtree argument label, as well as the pattern corresponding
to the argument. [transl_label lbl pat] is equal to:
- [Position l, P] when [lbl] is {{!Parsetree.arg_label.Labelled}[Labelled l]}
and [pat] represents [(P : [%call_pos])]
- [transl_label lbl None, pat] otherwise.
*)
val transl_label_from_pat :
Parsetree.arg_label -> Parsetree.pattern
-> Types.arg_label * Parsetree.pattern
(** Like [transl_label_from_pat], but with special handling for expressions
[(E : [%call_pos])] instead of for patterns.
*)
val transl_label_from_expr :
Parsetree.arg_label -> Parsetree.expression
-> Types.arg_label * Parsetree.expression
(* Note about [new_var_jkind]
This is exposed as an option because the same initialization doesn't work in all
typing contexts.
If it's always [Sort], then it becomes difficult to get a type variable with jkind
any in type annotations on expressions and patterns due to the lack of explicit
binding sites.
If it's always [Any], then we risk breaking backwards compatibility with examples
such as:
[external to_bytes : 'a -> extern_flags list -> bytes = "caml_output_value_to_bytes"]
The general rule for selecting between [Sort] and [Any] is to use [Sort] in places
that allows users to explictly binding type variables to certain jkinds and [Any]
otherwise.
There are some exceptions made around type manifests and type constraints to not
constrain the type parameters to representable jkinds unnecessarily while maintaining
the most amount of backwards compatibility. It is for this reason, the left hand side
of a constraint is typed using [Any] while the right hand side uses [Sort]. *)
val transl_simple_type:
Env.t -> new_var_jkind:jkind_initialization_choice
-> ?univars:TyVarEnv.poly_univars -> closed:bool -> Alloc.Const.t
-> Parsetree.core_type -> Typedtree.core_type
val transl_simple_type_univars:
Env.t -> Parsetree.core_type -> Typedtree.core_type
val transl_simple_type_delayed
: Env.t -> Alloc.Const.t
-> Parsetree.core_type
-> Typedtree.core_type * type_expr * (unit -> unit)
(* Translate a type using [Any] as the [jkind_initialization_choice],
but leave type variables unbound.
Returns the type, an instance of the corresponding type_expr, and a
function that binds the type variable. *)
val transl_type_scheme:
Env.t -> Parsetree.core_type -> Typedtree.core_type
val transl_type_param:
Env.t -> Path.t -> jkind_lr -> Parsetree.core_type -> Typedtree.core_type
(* the Path.t above is of the type/class whose param we are processing;
the level defaults to the current level. The jkind_lr is the jkind to
use if no annotation is provided. *)
val get_type_param_jkind: Path.t -> Parsetree.core_type -> jkind_lr
val get_type_param_name: Parsetree.core_type -> string option
exception Already_bound
type value_loc =
Tuple | Poly_variant | Object_field
type sort_loc =
Fun_arg | Fun_ret
type cannot_quantify_reason
type jkind_info
type error =
| Unbound_type_variable of string * string list
| No_type_wildcards
| Undefined_type_constructor of Path.t
| Type_arity_mismatch of Longident.t * int * int
| Bound_type_variable of string
| Recursive_type
| Type_mismatch of Errortrace.unification_error
| Alias_type_mismatch of Errortrace.unification_error
| Present_has_conjunction of string
| Present_has_no_type of string
| Constructor_mismatch of type_expr * type_expr
| Not_a_variant of type_expr
| Variant_tags of string * string
| Invalid_variable_name of string
| Cannot_quantify of string * cannot_quantify_reason
| Bad_univar_jkind of
{ name : string; jkind_info : jkind_info; inferred_jkind : jkind_lr }
| Multiple_constraints_on_type of Longident.t
| Method_mismatch of string * type_expr * type_expr
| Opened_object of Path.t option
| Not_an_object of type_expr
| Unsupported_extension : _ Language_extension.t -> error
| Polymorphic_optional_param
| Non_value of
{vloc : value_loc; typ : type_expr; err : Jkind.Violation.t}
| Non_sort of
{vloc : sort_loc; typ : type_expr; err : Jkind.Violation.t}
| Bad_jkind_annot of type_expr * Jkind.Violation.t
| Did_you_mean_unboxed of Longident.t
| Invalid_label_for_call_pos of Parsetree.arg_label
exception Error of Location.t * Env.t * error
val report_error: Env.t -> Format.formatter -> error -> unit
(* Support for first-class modules. *)
val transl_modtype_longident: (* from Typemod *)
(Location.t -> Env.t -> Longident.t -> Path.t) ref
val transl_modtype: (* from Typemod *)
(Env.t -> Parsetree.module_type -> Typedtree.module_type) ref
val check_package_with_type_constraints: (* from Typemod *)
(Location.t -> Env.t -> Types.module_type ->
(Longident.t Asttypes.loc * Typedtree.core_type) list ->
Types.module_type) ref