summaryrefslogtreecommitdiff
path: root/compiler/coreSyn
diff options
context:
space:
mode:
authorsimonpj@microsoft.com <unknown>2007-12-21 09:04:06 +0000
committersimonpj@microsoft.com <unknown>2007-12-21 09:04:06 +0000
commit219f900f4e518e8158807cdda6fdec8331f701f0 (patch)
tree533aef92a761727ad13caba0a49bed6726491f0f /compiler/coreSyn
parentf645bca8386cd70021cdd467a423b49b7daa835b (diff)
downloadhaskell-219f900f4e518e8158807cdda6fdec8331f701f0.tar.gz
Improve handling of newtypes (fixes Trac 1495)
In a few places we want to "look through" newtypes to get to the representation type. But we need to be careful that we don't fall into an ininite loop with e.g. newtype T = MkT T The old mechansim for doing this was to have a field nt_rep, inside a newtype TyCon, that gave the "ultimate representation" of the type. But that failed for Trac 1495, which looked like this: newtype Fix a = Fix (a (Fix a)) data I a = I a Then, expanding the type (Fix I) went on for ever. The right thing to do seems to be to check for loops when epxanding the *type*, rather than in the *tycon*. This patch does that, - Removes nt_rep from TyCon - Make Type.repType check for loops See Note [Expanding newtypes] in Type.lhs. At the same time I also fixed a bug for Roman, where newtypes were not being expanded properly in FamInstEnv.topNormaliseType. This function and Type.repType share a common structure. Ian, see if this merges easily to the branch If not, I don't think it's essential to fix 6.8
Diffstat (limited to 'compiler/coreSyn')
-rw-r--r--compiler/coreSyn/MkExternalCore.lhs6
1 files changed, 2 insertions, 4 deletions
diff --git a/compiler/coreSyn/MkExternalCore.lhs b/compiler/coreSyn/MkExternalCore.lhs
index a0bccda29e..e5f81d0a54 100644
--- a/compiler/coreSyn/MkExternalCore.lhs
+++ b/compiler/coreSyn/MkExternalCore.lhs
@@ -69,13 +69,11 @@ collect_tdefs tcon tdefs
where
tdef | isNewTyCon tcon =
C.Newtype (make_con_qid (tyConName tcon)) (map make_tbind tyvars) repclause
--- 20060420 GHC handles empty data types just fine. ExtCore should too! jds
--- | null (tyConDataCons tcon) = error "MkExternalCore died: can't handle datatype declarations with no data constructors"
| otherwise =
C.Data (make_con_qid (tyConName tcon)) (map make_tbind tyvars) (map make_cdef (tyConDataCons tcon))
where repclause | isRecursiveTyCon tcon || isOpenTyCon tcon= Nothing
- | otherwise = Just (make_ty rep)
- where (_, rep) = newTyConRep tcon
+ | otherwise = Just (make_ty (repType rhs))
+ where (_, rhs) = newTyConRhs tcon
tyvars = tyConTyVars tcon
collect_tdefs _ tdefs = tdefs