Commit 67465497 authored by eir@cis.upenn.edu's avatar eir@cis.upenn.edu

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.
parent 6e56ac58
[submodule "libraries/binary"]
path = libraries/binary
url = ../packages/binary.git
url = http://git.haskell.org/packages/binary.git
ignore = untracked
[submodule "libraries/bytestring"]
path = libraries/bytestring
url = ../packages/bytestring.git
url = http://git.haskell.org/packages/bytestring.git
ignore = untracked
[submodule "libraries/Cabal"]
path = libraries/Cabal
url = ../packages/Cabal.git
url = http://git.haskell.org/packages/Cabal.git
ignore = untracked
[submodule "libraries/containers"]
path = libraries/containers
url = ../packages/containers.git
url = http://git.haskell.org/packages/containers.git
ignore = untracked
[submodule "libraries/haskeline"]
path = libraries/haskeline
url = ../packages/haskeline.git
url = http://git.haskell.org/packages/haskeline.git
ignore = untracked
[submodule "libraries/pretty"]
path = libraries/pretty
url = ../packages/pretty.git
url = http://git.haskell.org/packages/pretty.git
ignore = untracked
[submodule "libraries/terminfo"]
path = libraries/terminfo
url = ../packages/terminfo.git
url = http://git.haskell.org/packages/terminfo.git
ignore = untracked
[submodule "libraries/transformers"]
path = libraries/transformers
url = ../packages/transformers.git
url = http://git.haskell.org/packages/transformers.git
ignore = untracked
[submodule "libraries/xhtml"]
path = libraries/xhtml
url = ../packages/xhtml.git
url = http://git.haskell.org/packages/xhtml.git
ignore = untracked
[submodule "libraries/Win32"]
path = libraries/Win32
url = ../packages/Win32.git
url = http://git.haskell.org/packages/Win32.git
ignore = untracked
[submodule "libraries/primitive"]
path = libraries/primitive
url = ../packages/primitive.git
url = http://git.haskell.org/packages/primitive.git
ignore = untracked
[submodule "libraries/vector"]
path = libraries/vector
url = ../packages/vector.git
url = http://git.haskell.org/packages/vector.git
ignore = untracked
[submodule "libraries/time"]
path = libraries/time
url = ../packages/time.git
url = http://git.haskell.org/packages/time.git
ignore = untracked
[submodule "libraries/random"]
path = libraries/random
url = ../packages/random.git
url = http://git.haskell.org/packages/random.git
ignore = untracked
[submodule "libraries/array"]
path = libraries/array
url = ../packages/array.git
url = http://git.haskell.org/packages/array.git
ignore = none
[submodule "libraries/deepseq"]
path = libraries/deepseq
url = ../packages/deepseq.git
url = http://git.haskell.org/packages/deepseq.git
ignore = none
[submodule "libraries/directory"]
path = libraries/directory
url = ../packages/directory.git
url = http://git.haskell.org/packages/directory.git
ignore = none
[submodule "libraries/filepath"]
path = libraries/filepath
url = ../packages/filepath.git
url = http://git.haskell.org/packages/filepath.git
ignore = none
[submodule "libraries/hoopl"]
path = libraries/hoopl
url = ../packages/hoopl.git
url = http://git.haskell.org/packages/hoopl.git
ignore = none
[submodule "libraries/hpc"]
path = libraries/hpc
url = ../packages/hpc.git
url = http://git.haskell.org/packages/hpc.git
ignore = none
[submodule "libraries/process"]
path = libraries/process
url = ../packages/process.git
url = http://git.haskell.org/packages/process.git
ignore = none
[submodule "libraries/unix"]
path = libraries/unix
url = ../packages/unix.git
url = http://git.haskell.org/packages/unix.git
ignore = none
[submodule "libraries/parallel"]
path = libraries/parallel
url = ../packages/parallel.git
url = http://git.haskell.org/packages/parallel.git
ignore = none
[submodule "libraries/stm"]
path = libraries/stm
url = ../packages/stm.git
url = http://git.haskell.org/packages/stm.git
ignore = none
[submodule "libraries/dph"]
path = libraries/dph
url = ../packages/dph.git
url = http://git.haskell.org/packages/dph.git
ignore = none
[submodule "utils/haddock"]
path = utils/haddock
url = ../haddock.git
url = http://git.haskell.org/haddock.git
ignore = none
branch = ghc-head
[submodule "nofib"]
path = nofib
url = ../nofib.git
url = http://git.haskell.org/nofib.git
ignore = none
[submodule "utils/hsc2hs"]
path = utils/hsc2hs
url = ../hsc2hs.git
url = http://git.haskell.org/hsc2hs.git
ignore = none
[submodule "libffi-tarballs"]
path = libffi-tarballs
url = ../libffi-tarballs.git
url = http://git.haskell.org/libffi-tarballs.git
ignore = none
[submodule ".arc-linters/arcanist-external-json-linter"]
path = .arc-linters/arcanist-external-json-linter
......
The Glasgow Haskell Compiler
============================
Dependent Types Branch of GHC
=============================
[![Build Status](https://api.travis-ci.org/ghc/ghc.svg?branch=master)](http://travis-ci.org/ghc/ghc)
This is a fork of GHC, with work toward supporting dependent types.
Anyone is welcome to download and play with this implementation,
and I am happy to receive feedback and issue reports on GitHub.
This is the source tree for [GHC][1], a compiler and interactive
environment for the Haskell functional programming language.
There are two options of using this branch: manual, and Nix-based.
For more information, visit [GHC's web site][1].
Manual
------
This code should build, but I have tested it only on `DEBUG` settings;
I recommend using build style `devel2` in `build.mk`.
Here is a minimal script you can follow to build this at home;
see the [GHC Building Guide] [3] for more info.
~~~
git clone https://github.com/goldfirere/ghc.git
cd ghc
git checkout nokinds
git remote set-url origin git://git.haskell.org/ghc.git # so submodules work
git submodule update --init
cd mk
cp build.mk.sample build.mk
## edit build.mk to uncomment the line to choose the `devel2` configuration
cd ..
perl boot
./configure
make
~~~
Check out the `testsuite/tests/dependent/should_compile` directory for
a few sample programs that should compile on this fork of GHC.
For more information about GHC, visit [GHC's web site][1].
Information for developers of GHC can be found on the [GHC Trac][2].
Nix-based
---------
Thanks to @deepfire, this branch is available in Nixpkgs, which means that with
some effort it can be fairly automatically employed to build any package from
Hackage. This way, though, requires that one installs the Nix package manager in
parallel with the system package manager -- and this option is currently
unavailable on Windows.
Here are the instructions:
1. To install the Nix package manager, taking over /nix for package storage:
curl https://nixos.org/nix/install | sh
2. Make Nix use the `master` repository of Nixpkgs package definitions:
Getting the Source
==================
git clone https://github.com/NixOS/nixpkgs.git
pushd ~/.nix-defexpr
rm -rf channels
ln -s ../nixpkgs
popd
echo 'export NIX_PATH=nixpkgs=/home/---<USERNAME>---/nixpkgs' >> ~/.bashrc
export NIX_PATH=nixpkgs=/home/---<USERNAME>---/nixpkgs
There are two ways to get a source tree:
3. [OPTIONAL] To enable prebuilt binaries from Peter Simons/NixOS Hydra servers:
1. *Download source tarballs*
sudo mkdir /etc/nix
echo 'binary-caches = http://hydra.nixos.org/ http://hydra.cryp.to/' | sudo dd of=/etc/nix/nix.conf
Download the GHC source distribution:
# If you don't do that, everything will still work, just it'll have
# to build everything from source.
ghc-<version>-src.tar.bz2
4. Enter a shell with `ghc-nokinds` available:
which contains GHC itself and the "boot" libraries.
nix-shell -p haskell.compiler.ghcNokinds
2. *Check out the source code from git*
5. See it's indeed `nokinds`:
$ git clone --recursive git://git.haskell.org/ghc.git
wget https://raw.githubusercontent.com/goldfirere/ghc/nokinds/testsuite/tests/dependent/should_compile/KindEqualities2.hs
runhaskell KindEqualities2.hs
Note: cloning GHC from Github requires a special setup. See [Getting a GHC
repository from Github] [7].
To apply 'nokinds' to building packages from Hackage, the best option would be
to follow instructions from the "Nix loves Haskell" talk by Peter Simons:
**DO NOT submit pull request directly to the github repo.**
*See the GHC team's working conventions re [how to contribute a patch to GHC](http://ghc.haskell.org/trac/ghc/wiki/WorkingConventions/FixingBugs "ghc.haskell.org/trac/ghc/wiki/WorkingConventions/FixingBug").*
http://cryp.to/nixos-meetup-3-slides.pdf
..where the relevant compiler name would be "ghcNokinds".
Building & Installing
=====================
......
......@@ -413,6 +413,10 @@ isBoxed :: Boxity -> Bool
isBoxed Boxed = True
isBoxed Unboxed = False
instance Outputable Boxity where
ppr Boxed = text "Boxed"
ppr Unboxed = text "Unboxed"
{-
************************************************************************
* *
......
......@@ -32,7 +32,7 @@ import Unique
import Util
import Name
import BasicTypes
import TypeRep (Type, ThetaType)
import TyCoRep (Type, ThetaType)
import Var
import Type (mkTyConApp)
......@@ -169,7 +169,7 @@ conLikeResTy (PatSynCon ps) tys = patSynInstResTy ps tys
--
-- 7) The original result type
conLikeFullSig :: ConLike
-> ([TyVar], [TyVar], [(TyVar,Type)]
-> ([TyVar], [TyVar], [EqSpec]
, ThetaType, ThetaType, [Type], Type)
conLikeFullSig (RealDataCon con) =
let (univ_tvs, ex_tvs, eq_spec, theta, arg_tys, res_ty) = dataConFullSig con
......
This diff is collapsed.
......@@ -6,10 +6,13 @@ import FieldLabel ( FieldLabel )
import Unique ( Uniquable )
import Outputable ( Outputable, OutputableBndr )
import BasicTypes (Arity)
import {-# SOURCE #-} TypeRep (Type, ThetaType)
import {-# SOURCE #-} TyCoRep (Type, ThetaType)
data DataCon
data DataConRep
data EqSpec
eqSpecTyVar :: EqSpec -> TyVar
dataConName :: DataCon -> Name
dataConTyCon :: DataCon -> TyCon
dataConExTyVars :: DataCon -> [TyVar]
......@@ -18,7 +21,7 @@ dataConFieldLabels :: DataCon -> [FieldLabel]
dataConInstOrigArgTys :: DataCon -> [Type] -> [Type]
dataConStupidTheta :: DataCon -> ThetaType
dataConFullSig :: DataCon
-> ([TyVar], [TyVar], [(TyVar,Type)], ThetaType, [Type], Type)
-> ([TyVar], [TyVar], [EqSpec], ThetaType, [Type], Type)
instance Eq DataCon
instance Ord DataCon
......
......@@ -17,7 +17,7 @@
--
-- * 'Name.Name': see "Name#name_types"
--
-- * 'Id.Id' represents names that not only have a 'Name.Name' but also a 'TypeRep.Type' and some additional
-- * 'Id.Id' represents names that not only have a 'Name.Name' but also a 'TyCoRep.Type' and some additional
-- details (a 'IdInfo.IdInfo' and one of 'Var.LocalIdDetails' or 'IdInfo.GlobalIdDetails') that
-- are added, modified and inspected by various compiler passes. These 'Var.Var' names may either
-- be global or local, see "Var#globalvslocal"
......@@ -30,11 +30,14 @@ module Id (
-- ** Simple construction
mkGlobalId, mkVanillaGlobal, mkVanillaGlobalWithInfo,
mkLocalId, mkLocalIdWithInfo, mkExportedLocalId,
mkSysLocal, mkSysLocalM, mkUserLocal, mkUserLocalM,
mkDerivedLocalM,
mkLocalId, mkLocalCoVar, mkLocalIdOrCoVar,
mkLocalIdOrCoVarWithInfo,
mkLocalIdWithInfo, mkExportedLocalId,
mkSysLocal, mkSysLocalM, mkSysLocalOrCoVar, mkSysLocalOrCoVarM,
mkUserLocal, mkUserLocalCoVar, mkUserLocalOrCoVar,
mkDerivedLocalCoVarM,
mkTemplateLocals, mkTemplateLocalsNum, mkTemplateLocal,
mkWorkerId, mkWiredInIdName,
mkWorkerId,
-- ** Taking an Id apart
idName, idType, idUnique, idInfo, idDetails, idRepArity,
......@@ -111,7 +114,7 @@ import IdInfo
import BasicTypes
-- Imported and re-exported
import Var( Id, DictId,
import Var( Id, CoVar, DictId,
idInfo, idDetails, globaliseId, varType,
isId, isLocalId, isGlobalId, isExportedId )
import qualified Var
......@@ -191,7 +194,7 @@ localiseId id
| ASSERT( isId id ) isLocalId id && isInternalName name
= id
| otherwise
= mkLocalIdWithInfo (localiseName name) (idType id) (idInfo id)
= Var.mkLocalVar (idDetails id) (localiseName name) (idType id) (idInfo id)
where
name = idName id
......@@ -249,7 +252,31 @@ mkVanillaGlobalWithInfo = mkGlobalId VanillaId
mkLocalId :: Name -> Type -> Id
mkLocalId name ty = mkLocalIdWithInfo name ty
(vanillaIdInfo `setOneShotInfo` typeOneShot ty)
-- It's tempting to ASSERT( not (isCoercionType ty) ), but don't. Sometimes,
-- the type is a panic. (Search invented_id)
-- | Make a local CoVar
mkLocalCoVar :: Name -> Type -> CoVar
mkLocalCoVar name ty
= ASSERT( isCoercionType ty )
Var.mkLocalVar CoVarId name ty (vanillaIdInfo `setOneShotInfo` typeOneShot ty)
-- | Like 'mkLocalId', but checks the type to see if it should make a covar
mkLocalIdOrCoVar :: Name -> Type -> Id
mkLocalIdOrCoVar name ty
| isCoercionType ty = mkLocalCoVar name ty
| otherwise = mkLocalId name ty
-- | Make a local id, with the IdDetails set to CoVarId if the type indicates
-- so.
mkLocalIdOrCoVarWithInfo :: Name -> Type -> IdInfo -> Id
mkLocalIdOrCoVarWithInfo name ty info
= Var.mkLocalVar details name ty info
where
details | isCoercionType ty = CoVarId
| otherwise = VanillaId
-- proper ids only; no covars!
mkLocalIdWithInfo :: Name -> Type -> IdInfo -> Id
mkLocalIdWithInfo name ty info = Var.mkLocalVar VanillaId name ty info
-- Note [Free type variables]
......@@ -265,26 +292,45 @@ mkExportedLocalId details name ty = Var.mkExportedLocalVar details name ty vanil
-- | Create a system local 'Id'. These are local 'Id's (see "Var#globalvslocal")
-- that are created by the compiler out of thin air
mkSysLocal :: FastString -> Unique -> Type -> Id
mkSysLocal fs uniq ty = mkLocalId (mkSystemVarName uniq fs) ty
mkSysLocal fs uniq ty = ASSERT( not (isCoercionType ty) )
mkLocalId (mkSystemVarName uniq fs) ty
-- | Like 'mkSysLocal', but checks to see if we have a covar type
mkSysLocalOrCoVar :: FastString -> Unique -> Type -> Id
mkSysLocalOrCoVar fs uniq ty
| isCoercionType ty = mkLocalCoVar name ty
| otherwise = mkLocalId name ty
where
name = mkSystemVarName uniq fs
mkSysLocalM :: MonadUnique m => FastString -> Type -> m Id
mkSysLocalM fs ty = getUniqueM >>= (\uniq -> return (mkSysLocal fs uniq ty))
mkSysLocalOrCoVarM :: MonadUnique m => FastString -> Type -> m Id
mkSysLocalOrCoVarM fs ty
= getUniqueM >>= (\uniq -> return (mkSysLocalOrCoVar fs uniq ty))
-- | Create a user local 'Id'. These are local 'Id's (see "Var#globalvslocal") with a name and location that the user might recognize
mkUserLocal :: OccName -> Unique -> Type -> SrcSpan -> Id
mkUserLocal occ uniq ty loc = mkLocalId (mkInternalName uniq occ loc) ty
mkUserLocalM :: MonadUnique m => OccName -> Type -> SrcSpan -> m Id
mkUserLocalM occ ty loc = getUniqueM >>= (\uniq -> return (mkUserLocal occ uniq ty loc))
mkDerivedLocalM :: MonadUnique m => (OccName -> OccName) -> Id -> Type -> m Id
mkDerivedLocalM deriv_name id ty
= getUniqueM >>= (\uniq -> return (mkLocalId (mkDerivedInternalName deriv_name uniq (getName id)) ty))
mkWiredInIdName :: Module -> FastString -> Unique -> Id -> Name
mkWiredInIdName mod fs uniq id
= mkWiredInName mod (mkOccNameFS varName fs) uniq (AnId id) UserSyntax
mkUserLocal occ uniq ty loc = ASSERT( not (isCoercionType ty) )
mkLocalId (mkInternalName uniq occ loc) ty
-- | Like 'mkUserLocal' for covars
mkUserLocalCoVar :: OccName -> Unique -> Type -> SrcSpan -> Id
mkUserLocalCoVar occ uniq ty loc
= mkLocalCoVar (mkInternalName uniq occ loc) ty
-- | Like 'mkUserLocal', but checks if we have a coercion type
mkUserLocalOrCoVar :: OccName -> Unique -> Type -> SrcSpan -> Id
mkUserLocalOrCoVar occ uniq ty loc
= mkLocalIdOrCoVar (mkInternalName uniq occ loc) ty
mkDerivedLocalCoVarM :: MonadUnique m => (OccName -> OccName) -> Id -> Type -> m Id
mkDerivedLocalCoVarM deriv_name id ty
= ASSERT( isCoercionType ty )
do { uniq <- getUniqueM
; let name = mkDerivedInternalName deriv_name uniq (getName id)
; return (mkLocalCoVar name ty) }
{-
Make some local @Ids@ for a template @CoreExpr@. These have bogus
......@@ -295,11 +341,11 @@ instantiated before use.
-- | Workers get local names. "CoreTidy" will externalise these if necessary
mkWorkerId :: Unique -> Id -> Type -> Id
mkWorkerId uniq unwrkr ty
= mkLocalId (mkDerivedInternalName mkWorkerOcc uniq (getName unwrkr)) ty
= mkLocalIdOrCoVar (mkDerivedInternalName mkWorkerOcc uniq (getName unwrkr)) ty
-- | Create a /template local/: a family of system local 'Id's in bijection with @Int@s, typically used in unfoldings
mkTemplateLocal :: Int -> Type -> Id
mkTemplateLocal i ty = mkSysLocal (fsLit "tpl") (mkBuiltinUnique i) ty
mkTemplateLocal i ty = mkSysLocalOrCoVar (fsLit "tpl") (mkBuiltinUnique i) ty
-- | Create a template local for a series of types
mkTemplateLocals :: [Type] -> [Id]
......
......@@ -10,7 +10,7 @@ Haskell. [WDP 94/11])
module IdInfo (
-- * The IdDetails type
IdDetails(..), pprIdDetails, coVarDetails,
IdDetails(..), pprIdDetails, coVarDetails, isCoVarDetails,
RecSelParent(..),
-- * The IdInfo type
......@@ -135,20 +135,19 @@ data IdDetails
-- implemented with a newtype, so it might be bad