Implement deriving strategies
[ghc.git] / libraries / ghci / GHCi / TH / Binary.hs
1 {-# OPTIONS_GHC -fno-warn-orphans #-}
2 -- This module is full of orphans, unfortunately
3 module GHCi.TH.Binary () where
4
5 import Data.Binary
6 import qualified Data.ByteString as B
7 import Data.Typeable
8 import GHC.Serialized
9 import qualified Language.Haskell.TH as TH
10 import qualified Language.Haskell.TH.Syntax as TH
11
12 -- Put these in a separate module because they take ages to compile
13
14 instance Binary TH.Loc
15 instance Binary TH.Name
16 instance Binary TH.ModName
17 instance Binary TH.NameFlavour
18 instance Binary TH.PkgName
19 instance Binary TH.NameSpace
20 instance Binary TH.Module
21 instance Binary TH.Info
22 instance Binary TH.Type
23 instance Binary TH.TyLit
24 instance Binary TH.TyVarBndr
25 instance Binary TH.Role
26 instance Binary TH.Lit
27 instance Binary TH.Range
28 instance Binary TH.Stmt
29 instance Binary TH.Pat
30 instance Binary TH.Exp
31 instance Binary TH.Dec
32 instance Binary TH.Overlap
33 instance Binary TH.DerivClause
34 instance Binary TH.DerivStrategy
35 instance Binary TH.Guard
36 instance Binary TH.Body
37 instance Binary TH.Match
38 instance Binary TH.Fixity
39 instance Binary TH.TySynEqn
40 instance Binary TH.FamFlavour
41 instance Binary TH.FunDep
42 instance Binary TH.AnnTarget
43 instance Binary TH.RuleBndr
44 instance Binary TH.Phases
45 instance Binary TH.RuleMatch
46 instance Binary TH.Inline
47 instance Binary TH.Pragma
48 instance Binary TH.Safety
49 instance Binary TH.Callconv
50 instance Binary TH.Foreign
51 instance Binary TH.Bang
52 instance Binary TH.SourceUnpackedness
53 instance Binary TH.SourceStrictness
54 instance Binary TH.DecidedStrictness
55 instance Binary TH.FixityDirection
56 instance Binary TH.OccName
57 instance Binary TH.Con
58 instance Binary TH.AnnLookup
59 instance Binary TH.ModuleInfo
60 instance Binary TH.Clause
61 instance Binary TH.InjectivityAnn
62 instance Binary TH.FamilyResultSig
63 instance Binary TH.TypeFamilyHead
64 instance Binary TH.PatSynDir
65 instance Binary TH.PatSynArgs
66
67 -- We need Binary TypeRep for serializing annotations
68
69 instance Binary TyCon where
70 put tc = put (tyConPackage tc) >> put (tyConModule tc) >> put (tyConName tc)
71 get = mkTyCon3 <$> get <*> get <*> get
72
73 instance Binary TypeRep where
74 put type_rep = put (splitTyConApp type_rep)
75 get = do
76 (ty_con, child_type_reps) <- get
77 return (mkTyConApp ty_con child_type_reps)
78
79 instance Binary Serialized where
80 put (Serialized tyrep wds) = put tyrep >> put (B.pack wds)
81 get = Serialized <$> get <*> (B.unpack <$> get)