-
Notifications
You must be signed in to change notification settings - Fork 1
/
GhcShakeInstances.hs
148 lines (131 loc) · 4.11 KB
/
GhcShakeInstances.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StandaloneDeriving #-}
module GhcShakeInstances where
-- stuff in this module is slow to compile, so split it out
import GhcPlugins hiding (varName)
import Fingerprint
import Unique
import OccName
import DriverPhases
import GHC.Generics (Generic)
import Development.Shake.Classes
import Data.Binary (getWord8, putWord8)
-- A really useful typedef
type IsBoot = Bool
-- UnitId
instance Show UnitId where
show = unitIdString
instance Binary UnitId where
put = put . unitIdFS
get = fmap fsToUnitId get
instance NFData UnitId where
rnf s = s `seq` ()
instance Hashable UnitId where
hashWithSalt s a = getKey (getUnique a) + s
-- ModuleName
instance Show ModuleName where
show = moduleNameString
instance Binary ModuleName where
put = put . moduleNameFS
get = fmap mkModuleNameFS get
instance Hashable ModuleName where
hashWithSalt s a = getKey (getUnique a) + s
instance NFData ModuleName where
rnf s = s `seq` ()
-- Module
instance Show Module where
show m = show (moduleUnitId m) ++ ":"
++ show (moduleName m)
instance NFData Module where
rnf a = a `seq` ()
instance Binary Module where
put m = do
put (moduleUnitId m)
put (moduleName m)
get = do
uid <- get
mod_name <- get
return (mkModule uid mod_name)
instance Hashable Module where
hashWithSalt s a = getKey (getUnique a) + s
-- OccName
instance Show OccName where
show occ = occNameString occ ++ "{" ++ show (occNameSpace occ) ++ "}"
instance NFData OccName where
rnf a = a `seq` ()
instance Binary OccName where
put occ = do
putWord8 $ case occNameSpace occ of
n | n == tcName -> 0
| n == dataName -> 1
| n == tvName -> 2
| n == varName -> 3
| otherwise -> error "what is this! 2"
put (occNameFS occ)
get = do
tag <- getWord8
fs <- get
let ns = case tag of
0 -> tcName
1 -> dataName
2 -> tvName
3 -> varName
_ -> error "what is this! 3"
return (mkOccNameFS ns fs)
instance Hashable OccName where
hashWithSalt s a = getKey (getUnique a) + s
-- NameSpace
instance Show NameSpace where
show n | n == tcName = "tc"
| n == dataName = "d"
| n == tvName = "tv"
| n == varName = "v"
| otherwise = error "what is this!"
-- FastString
instance Binary FastString where
put = put . fastStringToByteString
get = fmap mkFastStringByteString get
instance NFData FastString where
rnf s = s `seq` ()
instance Hashable FastString where
hashWithSalt s fs = getKey (getUnique fs) + s
-- Fingerprint
instance Hashable Fingerprint where
hashWithSalt s (Fingerprint w1 w2) = hashWithSalt s (w1, w2)
-- HscSource
deriving instance Generic HscSource
deriving instance Typeable HscSource
instance NFData HscSource
instance Binary HscSource
instance Hashable HscSource
-- Phase
deriving instance Generic Phase
deriving instance Typeable Phase
instance NFData Phase
instance Binary Phase
instance Hashable Phase
-- | A 'RecompKey' is a key for a hash, for which recompilation can
-- be predicated on. Each hash represents some aspect of a module
-- which you could depend on.
data RecompKey
-- | The flags which were passed to compile a module.
= FlagHash Module
-- | The export list of a (boot) module
| ExportHash Module IsBoot
-- | The entire interface of the module
| ModuleHash Module -- external package deps CANNOT be on boot
-- | The declaration hash of a specific named entity
| DeclHash Module IsBoot OccName
deriving (Show, Typeable, Eq, Generic)
instance Hashable RecompKey
instance Binary RecompKey
instance NFData RecompKey
-- ModLocation
deriving instance Generic ModLocation
deriving instance Eq ModLocation
instance Hashable ModLocation
instance Binary ModLocation
instance NFData ModLocation