summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorRichard Eisenberg <rae@cs.brynmawr.edu>2018-07-05 14:21:43 -0400
committerRichard Eisenberg <rae@cs.brynmawr.edu>2018-07-10 19:07:23 -0400
commit042df603cbb5a77ec13ccfec2ce7bad2bb940aae (patch)
treedcd4c2290e9f24f9d378a42a1c6eb601de3d0afd /compiler
parent8ec2946048123f9278cf68eaf520104319a1f569 (diff)
downloadhaskell-042df603cbb5a77ec13ccfec2ce7bad2bb940aae.tar.gz
Unwrap casts before checking vars in eager unifier
Previously, checking whether (tv |> co) ~ (tv |> co) got deferred, because we looked for vars before stripping casts. (The left type would get stripped, and then tv ~ (tv |> co) would scare the occurs- checker.) This opportunity for improvement presented itself in other work. This is just an optimization. Some programs can now report more errors simultaneously.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/typecheck/TcUnify.hs19
1 files changed, 11 insertions, 8 deletions
diff --git a/compiler/typecheck/TcUnify.hs b/compiler/typecheck/TcUnify.hs
index 08a5c59879..410277ca4b 100644
--- a/compiler/typecheck/TcUnify.hs
+++ b/compiler/typecheck/TcUnify.hs
@@ -1304,6 +1304,17 @@ uType t_or_k origin orig_ty1 orig_ty2
-- The arguments to 'go' are always semantically identical
-- to orig_ty{1,2} except for looking through type synonyms
+ -- Unwrap casts before looking for variables. This way, we can easily
+ -- recognize (t |> co) ~ (t |> co), which is nice. Previously, we
+ -- didn't do it this way, and then the unification above was deferred.
+ go (CastTy t1 co1) t2
+ = do { co_tys <- uType t_or_k origin t1 t2
+ ; return (mkCoherenceLeftCo Nominal t1 co1 co_tys) }
+
+ go t1 (CastTy t2 co2)
+ = do { co_tys <- uType t_or_k origin t1 t2
+ ; return (mkCoherenceRightCo Nominal t2 co2 co_tys) }
+
-- Variables; go for uVar
-- Note that we pass in *original* (before synonym expansion),
-- so that type variables tend to get filled in with
@@ -1326,14 +1337,6 @@ uType t_or_k origin orig_ty1 orig_ty2
| tc1 == tc2
= return $ mkNomReflCo ty1
- go (CastTy t1 co1) t2
- = do { co_tys <- go t1 t2
- ; return (mkCoherenceLeftCo Nominal t1 co1 co_tys) }
-
- go t1 (CastTy t2 co2)
- = do { co_tys <- go t1 t2
- ; return ( mkCoherenceRightCo Nominal t2 co2 co_tys) }
-
-- See Note [Expanding synonyms during unification]
--
-- Also NB that we recurse to 'go' so that we don't push a