separate typing_env_types and typing_env
[hiphop-php.git] / hphp / hack / src / typing / typing_union.mli
blobad71bbecb608768e89585000474ec0be276189f2
1 (*
2 * Copyright (c) 2015, 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 open Typing_defs
11 open Typing_env_types
13 module Env = Typing_env
15 (** Performs the union of two types.
16 The union is the least upper bound of the subtyping relation.
18 There is however one approximation: if type A is covariant,
19 then
20 A<T1> | A<T2> = A<T1|T2>
22 This approximation is necessary to avoid type growing exponentially in size.
23 We have seen cases where it would otherwise generate unions involving all
24 the subsets of a set of types. *)
25 val union: env -> locl ty -> locl ty -> env * locl ty
26 (** Computes the union of a list of types by union types two by two.
27 This is quadratic, so if this requires more than 20 two by two unions,
28 fall back to simply flatten the unions, bubble up the option and remove
29 duplicates. *)
30 val union_list: env -> Reason.t -> locl ty list -> env * locl ty
31 (** Simplify unions in a type. *)
32 val simplify_unions:
33 env ->
34 ?on_tyvar:(env -> Reason.t -> Ident.t -> env * locl ty) ->
35 locl ty ->
36 env * locl ty
37 (** A cheap type difference. If ty1 is a union, remove ty2 from this union.
38 Assumes ty1 is a flattened union or an option of a flattened union,
39 and ty2 is a type variable *)
40 val diff: locl ty -> locl ty -> locl ty