diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2012-06-13 17:21:09 +0100 |
---|---|---|
committer | Simon Peyton Jones <simonpj@microsoft.com> | 2012-06-13 17:21:09 +0100 |
commit | 5a8ac0f823c151c062a3f1903574030423bb255c (patch) | |
tree | 60c7bbe1091ddba9c404f8024928fcea83480523 /compiler/iface/BinIface.hs | |
parent | 03f78f0686f048e75d671f2797c8684b71655c49 (diff) | |
download | haskell-5a8ac0f823c151c062a3f1903574030423bb255c.tar.gz |
Simplify the implementation of Implicit Parameters
This patch re-implements implicit parameters via a class
with a functional dependency:
class IP (n::Symbol) a | n -> a where
ip :: a
This definition is in the library module GHC.IP. Notice
how it use a type-literal, so we can have constraints like
IP "x" Int
Now all the functional dependency machinery works right to make
implicit parameters behave as they should.
Much special-case processing for implicit parameters can be removed
entirely. One particularly nice thing is not having a dedicated
"original-name cache" for implicit parameters (the nsNames field of
NameCache). But many other cases disappear:
* BasicTypes.IPName
* IPTyCon constructor in Tycon.TyCon
* CIPCan constructor in TcRnTypes.Ct
* IPPred constructor in Types.PredTree
Implicit parameters remain special in a few ways:
* Special syntax. Eg the constraint (IP "x" Int) is parsed
and printed as (?x::Int). And we still have local bindings
for implicit parameters, and occurrences thereof.
* A implicit-parameter binding (let ?x = True in e) amounts
to a local instance declaration, which we have not had before.
It just generates an implication contraint (easy), but when
going under it we must purge any existing bindings for
?x in the inert set. See Note [Shadowing of Implicit Parameters]
in TcSimplify
* TcMType.sizePred classifies implicit parameter constraints as size-0,
as before the change
There are accompanying patches to libraries 'base' and 'haddock'
All the work was done by Iavor Diatchki
Diffstat (limited to 'compiler/iface/BinIface.hs')
-rw-r--r-- | compiler/iface/BinIface.hs | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/compiler/iface/BinIface.hs b/compiler/iface/BinIface.hs index 5d1c48f183..f03808fbd2 100644 --- a/compiler/iface/BinIface.hs +++ b/compiler/iface/BinIface.hs @@ -19,9 +19,8 @@ module BinIface ( #include "HsVersions.h" import TcRnMonad -import TyCon (TyCon, tyConName, tupleTyConSort, tupleTyConArity, isTupleTyCon, tyConIP_maybe) +import TyCon (TyCon, tyConName, tupleTyConSort, tupleTyConArity, isTupleTyCon) import DataCon (dataConName, dataConWorkId, dataConTyCon) -import IParam (ipFastString, ipTyConName) import PrelInfo (wiredInThings, basicKnownKeyNames) import Id (idName, isDataConWorkId_maybe) import TysWiredIn @@ -316,7 +315,7 @@ knownKeyNamesMap = listToUFM_Directly [(nameUnique n, n) | n <- knownKeyNames] -- See Note [Symbol table representation of names] putName :: BinDictionary -> BinSymbolTable -> BinHandle -> Name -> IO () -putName dict BinSymbolTable{ +putName _dict BinSymbolTable{ bin_symtab_map = symtab_map_ref, bin_symtab_next = symtab_next } bh name | name `elemUFM` knownKeyNamesMap @@ -327,10 +326,6 @@ putName dict BinSymbolTable{ = case wiredInNameTyThing_maybe name of Just (ATyCon tc) | isTupleTyCon tc -> putTupleName_ bh tc 0 - | Just ip <- tyConIP_maybe tc -> do - off <- allocateFastString dict (ipFastString ip) - -- MASSERT(off < 2^(30 :: Int)) - put_ bh (0xC0000000 .|. off) Just (ADataCon dc) | let tc = dataConTyCon dc, isTupleTyCon tc -> putTupleName_ bh tc 1 Just (AnId x) @@ -362,7 +357,7 @@ putTupleName_ bh tc thing_tag getSymtabName :: NameCacheUpdater -> Dictionary -> SymbolTable -> BinHandle -> IO Name -getSymtabName ncu dict symtab bh = do +getSymtabName _ncu _dict symtab bh = do i <- get bh case i .&. 0xC0000000 of 0x00000000 -> return $! symtab ! fromIntegral (i :: Word32) @@ -385,7 +380,6 @@ getSymtabName ncu dict symtab bh = do _ -> pprPanic "getSymtabName:unknown tuple sort" (ppr i) thing_tag = (i .&. 0x0CFFFFFF) `shiftR` 26 arity = fromIntegral (i .&. 0x03FFFFFF) - 0xC0000000 -> liftM ipTyConName $ updateNameCache ncu $ flip allocateIPName (dict ! fromIntegral (i .&. 0x3FFFFFFF)) _ -> pprPanic "getSymtabName:unknown name tag" (ppr i) data BinSymbolTable = BinSymbolTable { @@ -426,7 +420,6 @@ data BinDictionary = BinDictionary { -- All the binary instances -- BasicTypes -{-! for IPName derive: Binary !-} {-! for Fixity derive: Binary !-} {-! for FixityDirection derive: Binary !-} {-! for Boxity derive: Binary !-} @@ -825,11 +818,6 @@ instance Binary Fixity where ab <- get bh return (Fixity aa ab) -instance (Binary name) => Binary (IPName name) where - put_ bh (IPName aa) = put_ bh aa - get bh = do aa <- get bh - return (IPName aa) - ------------------------------------------------------------------------- -- Types from: Demand ------------------------------------------------------------------------- @@ -1057,8 +1045,7 @@ instance Binary IfaceCoCon where put_ bh IfaceTransCo = putByte bh 4 put_ bh IfaceInstCo = putByte bh 5 put_ bh (IfaceNthCo d) = do { putByte bh 6; put_ bh d } - put_ bh (IfaceIPCoAx ip) = do { putByte bh 7; put_ bh ip } - + get bh = do h <- getByte bh case h of @@ -1069,7 +1056,6 @@ instance Binary IfaceCoCon where 4 -> return IfaceTransCo 5 -> return IfaceInstCo 6 -> do { d <- get bh; return (IfaceNthCo d) } - 7 -> do { ip <- get bh; return (IfaceIPCoAx ip) } _ -> panic ("get IfaceCoCon " ++ show h) ------------------------------------------------------------------------- |