Add tyvars as newtype wrapper on idents
[hiphop-php.git] / hphp / hack / src / shape_analysis / shape_analysis_logic.ml
blob744f3b33adedec49f1a9aaa709dc12e19a186925
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 Shape_analysis_types
11 let result_id_counter = ref 0
13 let fresh_result_id () =
14 let result_id = !result_id_counter in
15 result_id_counter := result_id + 1;
16 ResultID.singleton result_id
18 let singleton result_id key ty = (result_id, ShapeKeyMap.singleton key ty)
20 let ( <> ) ~env (id1, sk1) (id2, sk2) =
21 let merge_shape_key_map _key ty_opt ty_opt' =
22 match (ty_opt, ty_opt') with
23 | (Some ty, Some ty') ->
24 let (_env, ty) = Typing_union.union env ty ty' in
25 Some ty
26 | (None, (Some _ as ty_opt))
27 | ((Some _ as ty_opt), None) ->
28 ty_opt
29 | (None, None) -> None
31 let result_id = ResultID.union id1 id2 in
32 let map = ShapeKeyMap.merge merge_shape_key_map sk1 sk2 in
33 (result_id, map)