diff options
author | Richard Eisenberg <rae@cs.brynmawr.edu> | 2018-07-17 00:12:34 -0400 |
---|---|---|
committer | Richard Eisenberg <rae@cs.brynmawr.edu> | 2018-08-01 12:12:22 -0400 |
commit | f8618a9b15177ee8c84771b927cb3583c9cd8408 (patch) | |
tree | d8abc1b82308735a80721b900372a8eb3e5db56d /compiler/types/TyCon.hs | |
parent | 1df50a0f61f320428f2e6dd07b3c9ce49c4acd31 (diff) | |
download | haskell-f8618a9b15177ee8c84771b927cb3583c9cd8408.tar.gz |
Remove the type-checking knot.
Bug #15380 hangs because a knot-tied TyCon ended up in a kind.
Looking at the code in tcInferApps, I'm amazed this hasn't happened
before! I couldn't think of a good way to fix it (with dependent
types, we can't really keep types out of kinds, after all), so
I just went ahead and removed the knot.
This was remarkably easy to do. In tcTyVar, when we find a TcTyCon,
just use it. (Previously, we looked up the knot-tied TyCon and used
that.) Then, during the final zonk, replace TcTyCons with the real,
full-blooded TyCons in the global environment. It's all very easy.
The new bit is explained in the existing
Note [Type checking recursive type and class declarations]
in TcTyClsDecls.
Naturally, I removed various references to the knot and the
zonkTcTypeInKnot (and related) functions. Now, we can print types
during type checking with abandon!
NB: There is a teensy error message regression with this patch,
around the ordering of quantified type variables. This ordering
problem is fixed (I believe) with the patch for #14880. The ordering
affects only internal variables that cannot be instantiated with
any kind of visible type application.
There is also a teensy regression around the printing of types
in TH splices. I think this is really a TH bug and will file
separately.
Test case: dependent/should_fail/T15380
Diffstat (limited to 'compiler/types/TyCon.hs')
-rw-r--r-- | compiler/types/TyCon.hs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/compiler/types/TyCon.hs b/compiler/types/TyCon.hs index 7836a0258d..0a02adf0b6 100644 --- a/compiler/types/TyCon.hs +++ b/compiler/types/TyCon.hs @@ -10,7 +10,8 @@ The @TyCon@ datatype module TyCon( -- * Main TyCon data types - TyCon, AlgTyConRhs(..), visibleDataCons, + TyCon, + AlgTyConRhs(..), visibleDataCons, AlgTyConFlav(..), isNoParent, FamTyConFlav(..), Role(..), Injectivity(..), RuntimeRepInfo(..), TyConFlavour(..), @@ -812,7 +813,8 @@ data TyCon promDcRepInfo :: RuntimeRepInfo -- ^ See comments with 'RuntimeRepInfo' } - -- | These exist only during a recursive type/class type-checking knot. + -- | These exist only during type-checking. See Note [How TcTyCons work] + -- in TcTyClsDecls | TcTyCon { tyConUnique :: Unique, tyConName :: Name, @@ -1530,10 +1532,11 @@ mkSumTyCon name binders res_kind arity tyvars cons parent algTcParent = parent } --- | Makes a tycon suitable for use during type-checking. --- The only real need for this is for printing error messages during --- a recursive type/class type-checking knot. It has a kind because --- TcErrors sometimes calls typeKind. +-- | Makes a tycon suitable for use during type-checking. It stores +-- a variety of details about the definition of the TyCon, but no +-- right-hand side. It lives only during the type-checking of a +-- mutually-recursive group of tycons; it is then zonked to a proper +-- TyCon in zonkTcTyCon. -- See also Note [Kind checking recursive type and class declarations] -- in TcTyClsDecls. mkTcTyCon :: Name @@ -2383,7 +2386,11 @@ instance Uniquable TyCon where instance Outputable TyCon where -- At the moment a promoted TyCon has the same Name as its -- corresponding TyCon, so we add the quote to distinguish it here - ppr tc = pprPromotionQuote tc <> ppr (tyConName tc) + ppr tc = pprPromotionQuote tc <> ppr (tyConName tc) <> pp_tc + where + pp_tc = getPprStyle $ \sty -> if ((debugStyle sty || dumpStyle sty) && isTcTyCon tc) + then text "[tc]" + else empty -- | Paints a picture of what a 'TyCon' represents, in broad strokes. -- This is used towards more informative error messages. |