diff options
author | Richard Eisenberg <eir@cis.upenn.edu> | 2015-12-11 18:19:53 -0500 |
---|---|---|
committer | Richard Eisenberg <eir@cis.upenn.edu> | 2015-12-11 18:23:12 -0500 |
commit | 6746549772c5cc0ac66c0fce562f297f4d4b80a2 (patch) | |
tree | 96869fcfb5757651462511d64d99a3712f09e7fb /compiler/typecheck/TcGenGenerics.hs | |
parent | 6e56ac58a6905197412d58e32792a04a63b94d7e (diff) | |
download | haskell-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/typecheck/TcGenGenerics.hs')
-rw-r--r-- | compiler/typecheck/TcGenGenerics.hs | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/compiler/typecheck/TcGenGenerics.hs b/compiler/typecheck/TcGenGenerics.hs index 2c5b80ef03..fb18517ad5 100644 --- a/compiler/typecheck/TcGenGenerics.hs +++ b/compiler/typecheck/TcGenGenerics.hs @@ -15,7 +15,6 @@ module TcGenGenerics (canDoGenerics, canDoGenerics1, import HsSyn import Type -import Kind ( isKind ) import TcType import TcGenDeriv import DataCon @@ -147,7 +146,7 @@ canDoGenerics tc tc_args -- -- Data family indices can be instantiated; the `tc_args` here are -- the representation tycon args - (if (all isTyVarTy (filterOut isKind tc_args)) + (if (all isTyVarTy (filterOutInvisibleTypes tc tc_args)) then IsValid else NotValid (tc_name <+> text "must not be instantiated;" <+> text "try deriving `" <> tc_name <+> tc_tys <> @@ -397,7 +396,7 @@ tc_mkRepFamInsts gk tycon mod = in newGlobalBinder mod (mkGen (nameOccName (tyConName tycon))) (nameSrcSpan (tyConName tycon)) - ; let axiom = mkSingleCoAxiom Nominal rep_name tyvars fam_tc appT repTy + ; let axiom = mkSingleCoAxiom Nominal rep_name tyvars [] fam_tc appT repTy ; newFamInst SynFamilyInst axiom } -------------------------------------------------------------------------------- @@ -460,7 +459,7 @@ argTyFold argVar (ArgTyAlg {ata_rec0 = mkRec0, isApp = do -- handles applications (phi, beta) <- tcSplitAppTy_maybe t - let interesting = argVar `elemVarSet` exactTyVarsOfType beta + let interesting = argVar `elemVarSet` exactTyCoVarsOfType beta -- Does it have no interesting structure to represent? if not interesting then Nothing @@ -602,12 +601,12 @@ mkBoxTy :: TyCon -- UAddr -> Type -> Type mkBoxTy uAddr uChar uDouble uFloat uInt uWord rec0 ty - | ty == addrPrimTy = mkTyConTy uAddr - | ty == charPrimTy = mkTyConTy uChar - | ty == doublePrimTy = mkTyConTy uDouble - | ty == floatPrimTy = mkTyConTy uFloat - | ty == intPrimTy = mkTyConTy uInt - | ty == wordPrimTy = mkTyConTy uWord + | ty `eqType` addrPrimTy = mkTyConTy uAddr + | ty `eqType` charPrimTy = mkTyConTy uChar + | ty `eqType` doublePrimTy = mkTyConTy uDouble + | ty `eqType` floatPrimTy = mkTyConTy uFloat + | ty `eqType` intPrimTy = mkTyConTy uInt + | ty `eqType` wordPrimTy = mkTyConTy uWord | otherwise = mkTyConApp rec0 [ty] -------------------------------------------------------------------------------- @@ -737,12 +736,12 @@ unboxRepRDR = maybe unK1_RDR snd . unboxedRepRDRs -- constructor. See Note [Generics and unlifted types] unboxedRepRDRs :: Type -> Maybe (RdrName, RdrName) unboxedRepRDRs ty - | ty == addrPrimTy = Just (uAddrDataCon_RDR, uAddrHash_RDR) - | ty == charPrimTy = Just (uCharDataCon_RDR, uCharHash_RDR) - | ty == doublePrimTy = Just (uDoubleDataCon_RDR, uDoubleHash_RDR) - | ty == floatPrimTy = Just (uFloatDataCon_RDR, uFloatHash_RDR) - | ty == intPrimTy = Just (uIntDataCon_RDR, uIntHash_RDR) - | ty == wordPrimTy = Just (uWordDataCon_RDR, uWordHash_RDR) + | ty `eqType` addrPrimTy = Just (uAddrDataCon_RDR, uAddrHash_RDR) + | ty `eqType` charPrimTy = Just (uCharDataCon_RDR, uCharHash_RDR) + | ty `eqType` doublePrimTy = Just (uDoubleDataCon_RDR, uDoubleHash_RDR) + | ty `eqType` floatPrimTy = Just (uFloatDataCon_RDR, uFloatHash_RDR) + | ty `eqType` intPrimTy = Just (uIntDataCon_RDR, uIntHash_RDR) + | ty `eqType` wordPrimTy = Just (uWordDataCon_RDR, uWordHash_RDR) | otherwise = Nothing -- Build a product pattern |