don't recreate global type var if it already exists
[hiphop-php.git] / hphp / hack / src / typing / typing_inference_env.mli
blobde1ceb4e9d90d2339b7d1c838402940eba79f891
1 (*
2 * Copyright (c) Facebook, Inc. and its affiliates.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the "hack" directory of this source tree.
7 *)
9 open Typing_defs
11 (** contains the inference env, containing all the information necessary to
12 perform type inference, including global type variables. *)
13 type t
15 (** contains only the information related to global type variables. This is returned
16 after typechecking individual functions and all the global inference environments
17 then get merged into a single one before being solved. *)
18 type t_global
20 type t_global_with_pos = Pos.t * t_global
22 module Log : sig
23 val inference_env_as_value : t -> Typing_log_value.value
25 val global_inference_env_as_value : t_global -> Typing_log_value.value
27 (** Convert a type variable from a global inference environment into json *)
28 val tyvar_to_json_g :
29 (locl_ty -> string) ->
30 (internal_type -> string) ->
31 t_global ->
32 Ident.t ->
33 Hh_json.json
34 end
36 val pp : Format.formatter -> t -> unit
38 val empty_inference_env : t
40 val fresh_type : ?variance:Ast_defs.variance -> t -> Pos.t -> t * locl_ty
42 (** Same as fresh_type but takes a specific reason as parameter. *)
43 val fresh_type_reason :
44 ?variance:Ast_defs.variance -> t -> Reason.t -> t * locl_ty
46 val fresh_invariant_type_var : t -> Pos.t -> t * locl_ty
48 val open_tyvars : t -> Pos.t -> t
50 val get_current_tyvars : t -> Ident.t list
52 val close_tyvars : t -> t
54 val tyvar_is_solved : t -> Ident.t -> bool
56 val tyvar_occurs_in_tyvar : t -> Ident.t -> in_:Ident.t -> bool
58 val get_tyvar_occurrences : t -> Ident.t -> ISet.t
60 val get_tyvars_in_tyvar : t -> Ident.t -> ISet.t
62 val contains_unsolved_tyvars : t -> Ident.t -> bool
64 val make_tyvar_no_more_occur_in_tyvar : t -> int -> no_more_in:int -> t
66 val bind : t -> ?tyvar_pos:Pos.t -> Ident.t -> locl_ty -> t
68 val add : t -> ?tyvar_pos:Pos.t -> Ident.t -> locl_ty -> t
70 val get_direct_binding : t -> Ident.t -> locl_ty option
72 val get_type : t -> Reason.t -> Ident.t -> t * locl_ty
74 val expand_var : t -> Reason.t -> Ident.t -> t * locl_ty
76 val expand_type : t -> locl_ty -> t * locl_ty
78 val expand_internal_type : t -> internal_type -> t * internal_type
80 val get_tyvar_pos : t -> Ident.t -> Pos.t
82 (* Get or add to bounds on type variables *)
83 val get_tyvar_lower_bounds : t -> Ident.t -> Internal_type_set.t
85 val get_tyvar_upper_bounds : t -> Ident.t -> Internal_type_set.t
87 val set_tyvar_lower_bounds : t -> Ident.t -> Internal_type_set.t -> t
89 val set_tyvar_upper_bounds : t -> Ident.t -> Internal_type_set.t -> t
91 (* Optionally supply intersection or union operations to simplify the bounds *)
92 val add_tyvar_upper_bound :
93 ?intersect:(internal_type -> internal_type list -> internal_type list) ->
94 t ->
95 Ident.t ->
96 internal_type ->
99 val add_tyvar_lower_bound :
100 ?union:(internal_type -> internal_type list -> internal_type list) ->
101 t ->
102 Ident.t ->
103 internal_type ->
106 val remove_tyvar_upper_bound : t -> Ident.t -> Ident.t -> t
108 val remove_tyvar_lower_bound : t -> Ident.t -> Ident.t -> t
110 val set_tyvar_appears_covariantly : t -> Ident.t -> t
112 val set_tyvar_appears_contravariantly : t -> Ident.t -> t
114 val set_tyvar_eager_solve_fail : t -> Ident.t -> t
116 val get_tyvar_appears_covariantly : t -> Ident.t -> bool
118 val get_tyvar_appears_contravariantly : t -> Ident.t -> bool
120 val get_tyvar_appears_invariantly : t -> Ident.t -> bool
122 val is_global_tyvar : t -> Ident.t -> bool
124 val new_global_tyvar : t -> Ident.t -> Typing_reason.t -> t * locl_ty
126 val wrap_ty_in_var : t -> Typing_reason.t -> locl_ty -> t * locl_ty
128 val get_tyvar_eager_solve_fail : t -> Ident.t -> bool
130 val get_tyvar_type_const :
131 t -> Ident.t -> Aast.sid -> (Aast.sid * locl_ty) option
133 val get_tyvar_pu_access :
134 t -> Ident.t -> Aast.sid -> (locl_ty * Aast.sid * locl_ty * Aast.sid) option
136 val set_tyvar_type_const : t -> Ident.t -> Aast.sid -> locl_ty -> t
138 val set_tyvar_pu_access :
139 t -> Ident.t -> locl_ty -> Aast.sid -> locl_ty -> Aast.sid -> t
141 val get_tyvar_type_consts : t -> Ident.t -> (Aast.sid * locl_ty) SMap.t
143 val add_subtype_prop : t -> Typing_logic.subtype_prop -> t
145 val get_current_pos_from_tyvar_stack : t -> Pos.t option
147 (** At the end of typechecking a function body, extract the remaining
148 inference env, which should only contain global type variables. *)
149 val extract_global_inference_env : t -> t * t_global
151 val get_vars : t -> Ident.t list
153 val get_vars_g : t_global -> Ident.t list
155 val copy_tyvar_from_genv_to_env :
156 Ident.t -> to_:t -> from:t_global -> t * Ident.t
158 module Size : sig
159 val ty_size : t -> locl_ty -> int
161 val inference_env_size : t -> int
164 (** Only merge the tvenv parts. Resolve conflicts stupidly by taking the first mapping of the two. *)
165 val simple_merge : t -> t -> t
167 (** Gets the part of the subtype proposition that should not be added to the
168 constraint graph (e.g. because it contains disjunctions). *)
169 val get_nongraph_subtype_prop : t -> Typing_logic.subtype_prop
171 val is_alias_for_another_var : t -> Ident.t -> bool
173 (** Remove variables containing no information. *)
174 val compress : t -> t
176 (** Remove variables containing no information. *)
177 val compress_g : t_global -> t_global
179 (** Split multiple global environments into (weakly) connected components. *)
180 val connected_components_g :
181 t_global_with_pos list -> t_global_with_pos list list