2 * Copyright (c) 2015, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE file in the "hack" directory of this source tree.
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,
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
30 val union_list
: env
-> Reason.t
-> locl ty list
-> env
* locl ty
31 (** Simplify unions in a type. *)
34 ?on_tyvar
:(env
-> Reason.t
-> Ident.t
-> 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