Skip to content

Commit

Permalink
[abstracts] remove some underlying type checks in unify_with_variance
Browse files Browse the repository at this point in the history
  • Loading branch information
vonagam committed Jul 17, 2020
1 parent 992026b commit aa90a10
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/core/tUnification.ml
Expand Up @@ -979,16 +979,15 @@ and unify_with_variance uctx f t1 t2 =
let t1 = follow t1 in
let t2 = follow t2 in
let unify_param t1 t2 = with_variance (get_nested_context uctx) f t1 t2 in
let get_after_abstract_context () = get_after_abstract_context uctx t1 t2 in
let rec get_underlying_type t = match follow t with
| TAbstract(a,tl) ->
let tl = List.map get_underlying_type tl in
let t = apply_params a.a_params tl a.a_this in
if Meta.has Meta.CoreType a.a_meta then t else get_underlying_type t
| t -> t
in
let compare_underlying equality_kind a b = type_eq {uctx with equality_kind = equality_kind} a b in
let unifies_abstract uctx t ab tl ats =
let uctx = get_after_abstract_context uctx t1 t2 in
List.exists (does_func_unify_arg (fun at ->
let at = apply_params ab.a_params tl at in
if ats == ab.a_to then
Expand All @@ -1006,16 +1005,11 @@ and unify_with_variance uctx f t1 t2 =
| TAbstract(a1,tl1),TAbstract(a2,tl2) when a1 == a2 ->
List.iter2 unify_param tl1 tl2
| TAbstract(a1,tl1),TAbstract(a2,tl2) ->
let uctx = get_after_abstract_context() in
compare_underlying EqStrict (get_underlying_type t1) (get_underlying_type t2);
if not (unifies_abstract uctx t2 a1 tl1 a1.a_to) && not (unifies_abstract uctx t1 a2 tl2 a2.a_from) then fail();
type_eq {uctx with equality_kind = EqStrict} (get_underlying_type t1) (get_underlying_type t2);
| TAbstract(a,tl),_ ->
let uctx = get_after_abstract_context() in
compare_underlying EqBothDynamic (get_underlying_type t1) t2;
if not (unifies_abstract uctx t2 a tl a.a_to) then fail();
if not (unifies_abstract uctx t2 a tl a.a_to) then fail()
| _,TAbstract(a,tl) ->
let uctx = get_after_abstract_context() in
compare_underlying EqBothDynamic t1 (get_underlying_type t2);
if not (unifies_abstract uctx t1 a tl a.a_from) then fail()
| TAnon(a1),TAnon(a2) ->
rec_stack_default unify_stack (t1,t2) (fast_eq_pair (t1,t2)) (fun() -> unify_anons uctx t1 t2 a1 a2) ()
Expand Down

0 comments on commit aa90a10

Please sign in to comment.