solved some TODOs about Tgeneric type arguments (2)
[hiphop-php.git] / hphp / hack / src / typing / tast.ml
blob9041092733429632d3cfb654bc10ffb7631aabc8
1 (*
2 * Copyright (c) 2017, Facebook, Inc.
3 * All rights reserved.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
8 *)
10 include Aast_defs
12 [@@@warning "-33"]
14 open Hh_prelude
16 [@@@warning "+33"]
18 (* This is the current notion of type in the typed AST.
19 * In future we might want to reconsider this and define a new representation
20 * that omits type inference artefacts such as type variables and lambda
21 * identifiers.
23 type ty = Typing_defs.locl_ty
25 type possibly_enforced_ty = Typing_defs.locl_possibly_enforced_ty
27 type decl_ty = Typing_defs.decl_ty
29 type reactivity = Typing_defs.reactivity
31 type mutability_env = Typing_mutability_env.mutability_env
33 type type_param_mutability = Typing_defs.param_mutability
35 type val_kind = Typing_defs.val_kind
37 let pp_ty = Pp_type.pp_locl_ty
39 let show_ty = Pp_type.show_locl_ty
41 let pp_decl_ty = Pp_type.pp_decl_ty
43 let show_decl_ty = Pp_type.show_decl_ty
45 let pp_reactivity fmt r = Pp_type.pp_reactivity fmt r
47 let show_reactivity r = Pp_type.show_reactivity r
49 let show_mutability_env _ = "<mutability-env>"
51 let pp_mutability_env fmt _ = Format.fprintf fmt "<mutability-env>"
53 let show_param_mutability = Pp_type.show_param_mutability
55 let pp_type_param_mutability fmt v =
56 Format.fprintf fmt "%s" (show_param_mutability v)
58 type saved_env = {
59 tcopt: TypecheckerOptions.t; [@opaque]
60 inference_env: Typing_inference_env.t;
61 tpenv: Type_parameter_env.t;
62 reactivity: reactivity;
63 local_mutability: mutability_env;
64 fun_mutable: type_param_mutability option;
65 condition_types: decl_ty SMap.t;
66 pessimize: bool;
68 [@@deriving show]
70 type program = (Pos.t * ty, unit, saved_env, ty) Aast.program [@@deriving show]
72 type def = (Pos.t * ty, unit, saved_env, ty) Aast.def
74 type expr = (Pos.t * ty, unit, saved_env, ty) Aast.expr
76 type expr_ = (Pos.t * ty, unit, saved_env, ty) Aast.expr_
78 type stmt = (Pos.t * ty, unit, saved_env, ty) Aast.stmt
80 type block = (Pos.t * ty, unit, saved_env, ty) Aast.block
82 type class_ = (Pos.t * ty, unit, saved_env, ty) Aast.class_
84 type class_id = (Pos.t * ty, unit, saved_env, ty) Aast.class_id
86 type type_hint = ty Aast.type_hint
88 type targ = ty Aast.targ
90 type class_get_expr = (Pos.t * ty, unit, saved_env, ty) Aast.class_get_expr
92 type class_typeconst = (Pos.t * ty, unit, saved_env, ty) Aast.class_typeconst
94 type user_attribute = (Pos.t * ty, unit, saved_env, ty) Aast.user_attribute
96 type fun_ = (Pos.t * ty, unit, saved_env, ty) Aast.fun_
98 type file_attribute = (Pos.t * ty, unit, saved_env, ty) Aast.file_attribute
100 type fun_def = (Pos.t * ty, unit, saved_env, ty) Aast.fun_def
102 type fun_param = (Pos.t * ty, unit, saved_env, ty) Aast.fun_param
104 type func_body = (Pos.t * ty, unit, saved_env, ty) Aast.func_body
106 type method_ = (Pos.t * ty, unit, saved_env, ty) Aast.method_
108 type method_redeclaration =
109 (Pos.t * ty, unit, saved_env, ty) Aast.method_redeclaration
111 type class_var = (Pos.t * ty, unit, saved_env, ty) Aast.class_var
113 type class_tparams = (Pos.t * ty, unit, saved_env, ty) Aast.class_tparams
115 type class_const = (Pos.t * ty, unit, saved_env, ty) Aast.class_const
117 type tparam = (Pos.t * ty, unit, saved_env, ty) Aast.tparam
119 type typedef = (Pos.t * ty, unit, saved_env, ty) Aast.typedef
121 type record_def = (Pos.t * ty, unit, saved_env, ty) Aast.record_def
123 type gconst = (Pos.t * ty, unit, saved_env, ty) Aast.gconst
125 type pu_enum = (Pos.t * ty, unit, saved_env, ty) Aast.pu_enum
127 type pu_member = (Pos.t * ty, unit, saved_env, ty) Aast.pu_member
129 let empty_saved_env tcopt : saved_env =
131 tcopt;
132 inference_env = Typing_inference_env.empty_inference_env;
133 tpenv = Type_parameter_env.empty;
134 reactivity = Typing_defs.Nonreactive;
135 local_mutability = Local_id.Map.empty;
136 fun_mutable = None;
137 condition_types = SMap.empty;
138 pessimize = false;
141 (* Used when an env is needed in codegen.
142 * TODO: (arkumar,wilfred,thomasjiang) T42509373 Fix when when needed
144 let dummy_saved_env = empty_saved_env GlobalOptions.default
146 let dummy_type_hint (hint : hint option) : ty * hint option =
147 (Typing_defs.mk (Typing_reason.Rnone, Typing_defs.Tdynamic), hint)
149 (* Helper function to create an annotation for a typed and positioned expression.
150 * Do not construct this tuple directly - at some point we will build
151 * some abstraction in so that we can change the representation (e.g. put
152 * further annotations on the expression) as we see fit.
154 let make_expr_annotation p ty : Pos.t * ty = (p, ty)
156 (* Helper function to create a typed and positioned expression.
157 * Do not construct this triple directly - at some point we will build
158 * some abstraction in so that we can change the representation (e.g. put
159 * further annotations on the expression) as we see fit.
161 let make_typed_expr p ty te : expr = (make_expr_annotation p ty, te)
163 (* Get the position of an expression *)
164 let get_position (((p, _), _) : expr) = p
166 (* Get the type of an expression *)
167 let get_type (((_, ty), _) : expr) = ty
169 let nast_converter =
170 object
171 inherit [_] Aast.map
173 method on_'ex _ (p, _ex) = p
175 method on_'fb _ _fb = Nast.Named
177 method on_'en _ _ = ()
179 method on_'hi _ _ = ()
182 let to_nast p = nast_converter#on_program () p
184 let to_nast_expr (tast : expr) : Nast.expr = nast_converter#on_expr () tast
186 let to_nast_class_id_ cid = nast_converter#on_class_id_ () cid