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