[commit: ghc] wip/ttypeable: Another recursive serialization case (e68d961)
git at git.haskell.org
git at git.haskell.org
Sun Jan 29 20:18:49 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/ttypeable
Link : http://ghc.haskell.org/trac/ghc/changeset/e68d96155dd7db6c0bed529522ac322dfc2103e5/ghc
>---------------------------------------------------------------
commit e68d96155dd7db6c0bed529522ac322dfc2103e5
Author: Ben Gamari <ben at smart-cactus.org>
Date: Wed Mar 16 14:05:43 2016 +0100
Another recursive serialization case
>---------------------------------------------------------------
e68d96155dd7db6c0bed529522ac322dfc2103e5
compiler/utils/Binary.hs | 14 +++++++++-----
libraries/ghci/GHCi/TH/Binary.hs | 14 +++++++++-----
2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/compiler/utils/Binary.hs b/compiler/utils/Binary.hs
index 9f3fb8d..431c55b 100644
--- a/compiler/utils/Binary.hs
+++ b/compiler/utils/Binary.hs
@@ -583,19 +583,22 @@ instance Binary TyCon where
#if MIN_VERSION_base(4,9,0)
putTypeRep :: BinHandle -> TypeRep a -> IO ()
--- Special handling for Type and RuntimeRep due to recursive kind relations.
+-- Special handling for Type, (->), and RuntimeRep due to recursive kind
+-- relations.
-- See Note [Mutually recursive representations of primitive types]
putTypeRep bh rep
| Just HRefl <- rep `eqTypeRep` (typeRep :: TypeRep Type)
= put_ bh (0 :: Word8)
| Just HRefl <- rep `eqTypeRep` (typeRep :: TypeRep RuntimeRep)
= put_ bh (1 :: Word8)
+ | Just HRefl <- rep `eqTypeRep` (typeRep :: TypeRep (->))
+ = put_ bh (2 :: Word8)
putTypeRep bh rep@(TRCon con) = do
- put_ bh (2 :: Word8)
+ put_ bh (3 :: Word8)
put_ bh con
putTypeRep bh (typeRepKind rep)
putTypeRep bh (TRApp f x) = do
- put_ bh (3 :: Word8)
+ put_ bh (4 :: Word8)
putTypeRep bh f
putTypeRep bh x
putTypeRep _ _ = fail "putTypeRep: Impossible"
@@ -606,13 +609,14 @@ getTypeRepX bh = do
case tag of
0 -> return $ TypeRepX (typeRep :: TypeRep Type)
1 -> return $ TypeRepX (typeRep :: TypeRep RuntimeRep)
- 2 -> do con <- get bh :: IO TyCon
+ 2 -> return $ TypeRepX (typeRep :: TypeRep (->))
+ 3 -> do con <- get bh :: IO TyCon
TypeRepX rep_k <- getTypeRepX bh
case rep_k `eqTypeRep` (typeRep :: TypeRep Type) of
Just HRefl -> pure $ TypeRepX $ mkTrCon con rep_k
Nothing -> fail "getTypeRepX: Kind mismatch"
- 3 -> do TypeRepX f <- getTypeRepX bh
+ 4 -> do TypeRepX f <- getTypeRepX bh
TypeRepX x <- getTypeRepX bh
case typeRepKind f of
TRFun arg _ ->
diff --git a/libraries/ghci/GHCi/TH/Binary.hs b/libraries/ghci/GHCi/TH/Binary.hs
index ea0809f..f617e2a 100644
--- a/libraries/ghci/GHCi/TH/Binary.hs
+++ b/libraries/ghci/GHCi/TH/Binary.hs
@@ -85,19 +85,22 @@ instance Binary TyCon where
get = mkTyCon <$> get <*> get <*> get
putTypeRep :: TypeRep a -> Put
--- Special handling for Type and RuntimeRep due to recursive kind relations.
+-- Special handling for Type, (->), and RuntimeRep due to recursive kind
+-- relations.
-- See Note [Mutually recursive representations of primitive types]
putTypeRep rep
| Just HRefl <- rep `eqTypeRep` (typeRep :: TypeRep Type)
= put (0 :: Word8)
| Just HRefl <- rep `eqTypeRep` (typeRep :: TypeRep RuntimeRep)
= put (1 :: Word8)
+ | Just HRefl <- rep `eqTypeRep` (typeRep :: TypeRep (->))
+ = put (2 :: Word8)
putTypeRep rep@(TRCon con) = do
- put (2 :: Word8)
+ put (3 :: Word8)
put con
putTypeRep (typeRepKind rep)
putTypeRep (TRApp f x) = do
- put (3 :: Word8)
+ put (4 :: Word8)
putTypeRep f
putTypeRep x
putTypeRep _ = fail "putTypeRep: Impossible"
@@ -108,13 +111,14 @@ getTypeRepX = do
case tag of
0 -> return $ TypeRepX (typeRep :: TypeRep Type)
1 -> return $ TypeRepX (typeRep :: TypeRep RuntimeRep)
- 2 -> do con <- get :: Get TyCon
+ 2 -> return $ TypeRepX (typeRep :: TypeRep (->))
+ 3 -> do con <- get :: Get TyCon
TypeRepX rep_k <- getTypeRepX
case rep_k `eqTypeRep` (typeRep :: TypeRep Type) of
Just HRefl -> pure $ TypeRepX $ mkTrCon con rep_k
Nothing -> fail "getTypeRepX: Kind mismatch"
- 3 -> do TypeRepX f <- getTypeRepX
+ 4 -> do TypeRepX f <- getTypeRepX
TypeRepX x <- getTypeRepX
case typeRepKind f of
TRFun arg _ ->
More information about the ghc-commits
mailing list