summaryrefslogtreecommitdiff
path: root/compiler/prelude/PrelInfo.hs
diff options
context:
space:
mode:
authorRichard Eisenberg <eir@cis.upenn.edu>2015-12-11 18:19:53 -0500
committerRichard Eisenberg <eir@cis.upenn.edu>2015-12-11 18:23:12 -0500
commit6746549772c5cc0ac66c0fce562f297f4d4b80a2 (patch)
tree96869fcfb5757651462511d64d99a3712f09e7fb /compiler/prelude/PrelInfo.hs
parent6e56ac58a6905197412d58e32792a04a63b94d7e (diff)
downloadhaskell-6746549772c5cc0ac66c0fce562f297f4d4b80a2.tar.gz
Add kind equalities to GHC.
This implements the ideas originally put forward in "System FC with Explicit Kind Equality" (ICFP'13). There are several noteworthy changes with this patch: * We now have casts in types. These change the kind of a type. See new constructor `CastTy`. * All types and all constructors can be promoted. This includes GADT constructors. GADT pattern matches take place in type family equations. In Core, types can now be applied to coercions via the `CoercionTy` constructor. * Coercions can now be heterogeneous, relating types of different kinds. A coercion proving `t1 :: k1 ~ t2 :: k2` proves both that `t1` and `t2` are the same and also that `k1` and `k2` are the same. * The `Coercion` type has been significantly enhanced. The documentation in `docs/core-spec/core-spec.pdf` reflects the new reality. * The type of `*` is now `*`. No more `BOX`. * Users can write explicit kind variables in their code, anywhere they can write type variables. For backward compatibility, automatic inference of kind-variable binding is still permitted. * The new extension `TypeInType` turns on the new user-facing features. * Type families and synonyms are now promoted to kinds. This causes trouble with parsing `*`, leading to the somewhat awkward new `HsAppsTy` constructor for `HsType`. This is dispatched with in the renamer, where the kind `*` can be told apart from a type-level multiplication operator. Without `-XTypeInType` the old behavior persists. With `-XTypeInType`, you need to import `Data.Kind` to get `*`, also known as `Type`. * The kind-checking algorithms in TcHsType have been significantly rewritten to allow for enhanced kinds. * The new features are still quite experimental and may be in flux. * TODO: Several open tickets: #11195, #11196, #11197, #11198, #11203. * TODO: Update user manual. Tickets addressed: #9017, #9173, #7961, #10524, #8566, #11142. Updates Haddock submodule.
Diffstat (limited to 'compiler/prelude/PrelInfo.hs')
-rw-r--r--compiler/prelude/PrelInfo.hs72
1 files changed, 50 insertions, 22 deletions
diff --git a/compiler/prelude/PrelInfo.hs b/compiler/prelude/PrelInfo.hs
index 1a7e056ada..0651a2c299 100644
--- a/compiler/prelude/PrelInfo.hs
+++ b/compiler/prelude/PrelInfo.hs
@@ -34,14 +34,18 @@ import DataCon
import Id
import Name
import MkId
+import NameEnv
import TysPrim
import TysWiredIn
import HscTypes
+import UniqFM
import Class
import TyCon
import Util
+import Panic ( panic )
import {-# SOURCE #-} TcTypeNats ( typeNatTyCons )
+import Data.List ( intercalate )
import Data.Array
{-
@@ -77,7 +81,19 @@ knownKeyNames :: [Name]
-- you get a Name with the correct known key
-- (See Note [Known-key names] in PrelNames)
knownKeyNames
- = concat [ tycon_kk_names funTyCon
+ | debugIsOn
+ , not (isNullUFM badNamesEnv)
+ = panic ("badKnownKeyNames:\n" ++ badNamesStr)
+ -- NB: We can't use ppr here, because this is sometimes evaluated in a
+ -- context where there are no DynFlags available, leading to a cryptic
+ -- "<<details unavailable>>" error. (This seems to happen only in the
+ -- stage 2 compiler, for reasons I [Richard] have no clue of.)
+
+ | otherwise
+ = names
+ where
+ names =
+ concat [ tycon_kk_names funTyCon
, concatMap tycon_kk_names primTyCons
, concatMap tycon_kk_names wiredInTyCons
@@ -95,28 +111,40 @@ knownKeyNames
, map idName wiredInIds
, map (idName . primOpId) allThePrimOps
, basicKnownKeyNames ]
- where
+
-- "kk" short for "known-key"
- tycon_kk_names :: TyCon -> [Name]
- tycon_kk_names tc = tyConName tc : (rep_names tc ++ concatMap thing_kk_names (implicitTyConThings tc))
-
- datacon_kk_names dc
- | Promoted tc <- promoteDataCon_maybe dc = dataConName dc : rep_names tc
- | otherwise = [dataConName dc]
-
- thing_kk_names :: TyThing -> [Name]
- thing_kk_names (ATyCon tc) = tycon_kk_names tc
- thing_kk_names (AConLike (RealDataCon dc)) = datacon_kk_names dc
- thing_kk_names thing = [getName thing]
-
- -- The TyConRepName for a known-key TyCon has a known key,
- -- but isn't itself an implicit thing. Yurgh.
- -- NB: if any of the wired-in TyCons had record fields, the record
- -- field names would be in a similar situation. Ditto class ops.
- -- But it happens that there aren't any
- rep_names tc = case tyConRepName_maybe tc of
- Just n -> [n]
- Nothing -> []
+ tycon_kk_names :: TyCon -> [Name]
+ tycon_kk_names tc = tyConName tc : (rep_names tc ++ concatMap thing_kk_names (implicitTyConThings tc))
+
+ datacon_kk_names dc
+ = dataConName dc : rep_names (promoteDataCon dc)
+
+ thing_kk_names :: TyThing -> [Name]
+ thing_kk_names (ATyCon tc) = tycon_kk_names tc
+ thing_kk_names (AConLike (RealDataCon dc)) = datacon_kk_names dc
+ thing_kk_names thing = [getName thing]
+
+ -- The TyConRepName for a known-key TyCon has a known key,
+ -- but isn't itself an implicit thing. Yurgh.
+ -- NB: if any of the wired-in TyCons had record fields, the record
+ -- field names would be in a similar situation. Ditto class ops.
+ -- But it happens that there aren't any
+ rep_names tc = case tyConRepName_maybe tc of
+ Just n -> [n]
+ Nothing -> []
+
+ namesEnv = foldl (\m n -> extendNameEnv_Acc (:) singleton m n n)
+ emptyUFM names
+ badNamesEnv = filterNameEnv (\ns -> length ns > 1) namesEnv
+ badNamesPairs = nameEnvUniqueElts badNamesEnv
+ badNamesStrs = map pairToStr badNamesPairs
+ badNamesStr = unlines badNamesStrs
+
+ pairToStr (uniq, ns) = " " ++
+ show uniq ++
+ ": [" ++
+ intercalate ", " (map (occNameString . nameOccName) ns) ++
+ "]"
{-
We let a lot of "non-standard" values be visible, so that we can make