|
2 | 2 | {-# LANGUAGE DeriveAnyClass #-}
|
3 | 3 | {-# LANGUAGE DerivingStrategies #-}
|
4 | 4 | {-# LANGUAGE RecordWildCards #-}
|
| 5 | +{-# LANGUAGE TypeFamilies #-} |
5 | 6 |
|
6 | 7 | module Development.IDE.Graph.Internal.Types where
|
7 | 8 |
|
@@ -31,6 +32,9 @@ import UnliftIO (MonadUnliftIO)
|
31 | 32 | import Control.Applicative (liftA2)
|
32 | 33 | #endif
|
33 | 34 |
|
| 35 | +-- | The type mapping between the @key@ or a rule and the resulting @value@. |
| 36 | +type family RuleResult key -- = value |
| 37 | + |
34 | 38 | unwrapDynamic :: forall a . Typeable a => Dynamic -> a
|
35 | 39 | unwrapDynamic x = fromMaybe (error msg) $ fromDynamic x
|
36 | 40 | where msg = "unwrapDynamic failed: Expected " ++ show (typeRep (Proxy :: Proxy a)) ++
|
@@ -92,6 +96,11 @@ newtype Step = Step Int
|
92 | 96 |
|
93 | 97 | newtype Value = Value Dynamic
|
94 | 98 |
|
| 99 | +unwrapValue :: forall a . Typeable a => Value -> a |
| 100 | +unwrapValue (Value x) = fromMaybe (error msg) $ fromDynamic x |
| 101 | + where msg = "unwrapValue failed: Expected " ++ show (typeRep (Proxy :: Proxy a)) ++ |
| 102 | + ", but got " ++ show (dynTypeRep x) |
| 103 | + |
95 | 104 | data KeyDetails = KeyDetails {
|
96 | 105 | keyStatus :: !Status,
|
97 | 106 | keyReverseDeps :: !KeySet
|
@@ -144,25 +153,63 @@ data Result = Result {
|
144 | 153 | resultData :: !BS.ByteString
|
145 | 154 | }
|
146 | 155 |
|
147 |
| -data ResultDeps = UnknownDeps | AlwaysRerunDeps !KeySet | ResultDeps !KeySet |
148 |
| - deriving (Eq, Show) |
| 156 | +data ResultDeps = UnknownDeps | AlwaysRerunDeps !KeySet | ResultDeps !KeySet | ResultDepsTree !KeySet !DepsTree |
| 157 | +-- deriving (Eq, Show) |
| 158 | + |
| 159 | +data DepsTrees = DepsTrees { |
| 160 | + depsTrees :: [DepsTree] |
| 161 | + } |
| 162 | + |
| 163 | +instance Eq ResultDeps where |
| 164 | + UnknownDeps == UnknownDeps = True |
| 165 | + AlwaysRerunDeps ids == AlwaysRerunDeps ids' = ids == ids' |
| 166 | + ResultDeps ids == ResultDeps ids' = ids == ids' |
| 167 | + ResultDepsTree ids _ == ResultDeps ids' = ids == ids' |
| 168 | + ResultDeps ids == ResultDepsTree ids' _ = ids == ids' |
| 169 | + _ == _ = False |
| 170 | + |
| 171 | +instance Show ResultDeps where |
| 172 | + show (ResultDeps ids) = "ResultDeps " ++ show ids |
| 173 | + show (ResultDepsTree ids _) = "ResultDepsTree " ++ show ids ++ " " ++ "result" |
| 174 | + show (AlwaysRerunDeps ids) = "AlwaysRerunDeps " ++ show ids |
| 175 | + show UnknownDeps = "UnknownDeps" |
| 176 | + |
| 177 | + |
| 178 | +data DepsTree = forall key value .(RuleResult key ~ value, Typeable key, Hashable key, Show key, Typeable value) => DepsTree { |
| 179 | + depsTreeNodeDeps :: !KeySet, |
| 180 | + -- condition to continue the tree |
| 181 | + depsTreeNodeCond :: !key, |
| 182 | + -- the continuation of the tree |
| 183 | + depsTreeContinuation :: !(value -> DepsTree) |
| 184 | + } | DeptLeaf { depsTreeNodeDeps :: !KeySet} |
| 185 | + |
| 186 | + |
| 187 | +instance Semigroup DepsTrees where |
| 188 | + DepsTrees a <> DepsTrees b = DepsTrees $ a <> b |
149 | 189 |
|
150 | 190 | getResultDepsDefault :: KeySet -> ResultDeps -> KeySet
|
151 |
| -getResultDepsDefault _ (ResultDeps ids) = ids |
152 |
| -getResultDepsDefault _ (AlwaysRerunDeps ids) = ids |
153 |
| -getResultDepsDefault def UnknownDeps = def |
| 191 | +getResultDepsDefault _ (ResultDeps ids) = ids |
| 192 | +getResultDepsDefault _ (ResultDepsTree ids _)=ids |
| 193 | +getResultDepsDefault _ (AlwaysRerunDeps ids) = ids |
| 194 | +getResultDepsDefault def UnknownDeps = def |
154 | 195 |
|
155 | 196 | mapResultDeps :: (KeySet -> KeySet) -> ResultDeps -> ResultDeps
|
156 |
| -mapResultDeps f (ResultDeps ids) = ResultDeps $ f ids |
157 |
| -mapResultDeps f (AlwaysRerunDeps ids) = AlwaysRerunDeps $ f ids |
158 |
| -mapResultDeps _ UnknownDeps = UnknownDeps |
| 197 | +mapResultDeps f (ResultDeps ids) = ResultDeps $ f ids |
| 198 | +mapResultDeps f (ResultDepsTree ids _)=ResultDeps $ f ids |
| 199 | +mapResultDeps f (AlwaysRerunDeps ids) = AlwaysRerunDeps $ f ids |
| 200 | +mapResultDeps _ UnknownDeps = UnknownDeps |
| 201 | + |
159 | 202 |
|
160 | 203 | instance Semigroup ResultDeps where
|
161 | 204 | UnknownDeps <> x = x
|
162 | 205 | x <> UnknownDeps = x
|
163 | 206 | AlwaysRerunDeps ids <> x = AlwaysRerunDeps (ids <> getResultDepsDefault mempty x)
|
164 | 207 | x <> AlwaysRerunDeps ids = AlwaysRerunDeps (getResultDepsDefault mempty x <> ids)
|
165 | 208 | ResultDeps ids <> ResultDeps ids' = ResultDeps (ids <> ids')
|
| 209 | + ResultDeps ids <> ResultDepsTree ids' tree = ResultDepsTree (ids <> ids') tree |
| 210 | + ResultDepsTree ids tree <> ResultDeps ids' = ResultDepsTree (ids <> ids') tree |
| 211 | + ResultDepsTree ids tree <> ResultDepsTree ids' tree' = error "Semigroup ResultDepsTree: not implemented" |
| 212 | + |
166 | 213 |
|
167 | 214 | instance Monoid ResultDeps where
|
168 | 215 | mempty = UnknownDeps
|
|
0 commit comments