167
167
-- > where
168
168
-- > sdictSendPort :: forall a. SerializableDict a -> SerializableDict (SendPort a)
169
169
-- > sdictSendPort SerializableDict = SerializableDict
170
- {-# LANGUAGE CPP #-}
171
- #if __GLASGOW_HASKELL__ >= 710
172
170
{-# LANGUAGE StaticPointers #-}
173
171
{-# LANGUAGE RoleAnnotations #-}
174
- #endif
175
172
module Control.Distributed.Static
176
173
( -- * Static values
177
174
Static
178
175
, staticLabel
179
176
, staticApply
180
- #if __GLASGOW_HASKELL__ >= 710
181
177
, staticPtr
182
178
, staticApplyPtr
183
- #endif
184
179
-- * Derived static combinators
185
180
, staticCompose
186
181
, staticSplit
@@ -213,9 +208,6 @@ import Data.Binary
213
208
, decode
214
209
)
215
210
import Data.ByteString.Lazy (ByteString , empty )
216
- #if ! MIN_VERSION_bytestring(0,10,0)
217
- import Data.ByteString.Lazy as BSL
218
- #endif
219
211
import Data.Map (Map )
220
212
import qualified Data.Map as Map (lookup , empty , insert )
221
213
import Control.Applicative ((<$>) , (<*>) )
@@ -228,27 +220,22 @@ import Data.Rank1Typeable
228
220
, ANY2
229
221
, ANY3
230
222
, ANY4
231
- #if __GLASGOW_HASKELL__ >= 710
232
223
, TypeRep
233
224
, typeOf
234
- #endif
235
225
)
236
226
237
227
-- Imports necessary to support StaticPtr
238
- #if __GLASGOW_HASKELL__ >= 710
239
228
import qualified GHC.Exts as GHC (Any )
240
229
import GHC.StaticPtr
241
230
import GHC.Fingerprint.Type (Fingerprint (.. ))
242
231
import System.IO.Unsafe (unsafePerformIO )
243
232
import Data.Rank1Dynamic (unsafeToDynamic )
244
233
import Unsafe.Coerce (unsafeCoerce )
245
- #endif
246
234
247
235
--------------------------------------------------------------------------------
248
236
-- Introducing static values --
249
237
--------------------------------------------------------------------------------
250
238
251
- #if __GLASGOW_HASKELL__ >= 710
252
239
-- | Static dynamic values
253
240
--
254
241
-- In the new proposal for static, the SPT contains these 'TypeRep's.
@@ -272,32 +259,25 @@ instance Eq SDynamic where
272
259
instance Ord SDynamic where
273
260
SDynamic _ ptr1 `compare` SDynamic _ ptr2 =
274
261
staticKey ptr1 `compare` staticKey ptr2
275
- #endif
276
262
277
263
data StaticLabel =
278
264
StaticLabel String
279
265
| StaticApply ! StaticLabel ! StaticLabel
280
- #if __GLASGOW_HASKELL__ >= 710
281
266
| StaticPtr SDynamic
282
- #endif
283
267
deriving (Eq , Ord , Typeable , Show )
284
268
285
269
instance NFData StaticLabel where
286
270
rnf (StaticLabel s) = rnf s
287
271
rnf (StaticApply a b) = rnf a `seq` rnf b
288
272
-- There are no NFData instances for TypeRep or for StaticPtr :/
289
- #if __GLASGOW_HASKELL__ >= 710
290
273
rnf (StaticPtr (SDynamic _a _b)) = ()
291
- #endif
292
274
293
275
-- | A static value. Static is opaque; see 'staticLabel' and 'staticApply'.
294
276
newtype Static a = Static StaticLabel
295
277
deriving (Eq , Ord , Typeable , Show )
296
278
297
279
-- Trying to 'coerce' static values will lead to unification errors
298
- #if __GLASGOW_HASKELL__ >= 710
299
280
type role Static nominal
300
- #endif
301
281
302
282
instance NFData (Static a ) where
303
283
rnf (Static s) = rnf s
@@ -312,35 +292,29 @@ putStaticLabel (StaticLabel string) =
312
292
putWord8 0 >> put string
313
293
putStaticLabel (StaticApply label1 label2) =
314
294
putWord8 1 >> putStaticLabel label1 >> putStaticLabel label2
315
- #if __GLASGOW_HASKELL__ >= 710
316
295
putStaticLabel (StaticPtr (SDynamic typ ptr)) =
317
296
let Fingerprint hi lo = staticKey ptr
318
297
in putWord8 2 >> put typ >> put hi >> put lo
319
- #endif
320
298
321
299
getStaticLabel :: Get StaticLabel
322
300
getStaticLabel = do
323
301
header <- getWord8
324
302
case header of
325
303
0 -> StaticLabel <$> get
326
304
1 -> StaticApply <$> getStaticLabel <*> getStaticLabel
327
- #if __GLASGOW_HASKELL__ >= 710
328
305
2 -> do typ <- get
329
306
hi <- get
330
307
lo <- get
331
308
let key = Fingerprint hi lo
332
309
case unsaferLookupStaticPtr key of
333
310
Nothing -> fail " StaticLabel.get: invalid pointer"
334
311
Just ptr -> return $ StaticPtr (SDynamic typ ptr)
335
- #endif
336
312
_ -> fail " StaticLabel.get: invalid"
337
313
338
- #if __GLASGOW_HASKELL__ >= 710
339
314
-- | We need to be able to lookup keys outside of the IO monad so that we
340
315
-- can provide a 'Get' instance.
341
316
unsaferLookupStaticPtr :: StaticKey -> Maybe (StaticPtr a )
342
317
unsaferLookupStaticPtr = unsafePerformIO . unsafeLookupStaticPtr
343
- #endif
344
318
345
319
-- | Create a primitive static value.
346
320
--
@@ -353,7 +327,6 @@ staticLabel = Static . StaticLabel . force
353
327
staticApply :: Static (a -> b ) -> Static a -> Static b
354
328
staticApply (Static f) (Static x) = Static (StaticApply f x)
355
329
356
- #if __GLASGOW_HASKELL__ >= 710
357
330
-- | Construct a static value from a static pointer
358
331
--
359
332
-- Since 0.3.4.0.
@@ -367,7 +340,6 @@ staticPtr x = Static . StaticPtr
367
340
staticApplyPtr :: (Typeable a , Typeable b )
368
341
=> StaticPtr (a -> b ) -> Static a -> Static b
369
342
staticApplyPtr = staticApply . staticPtr
370
- #endif
371
343
372
344
--------------------------------------------------------------------------------
373
345
-- Eliminating static values --
@@ -402,10 +374,8 @@ resolveStaticLabel rtable (StaticApply label1 label2) = do
402
374
f <- resolveStaticLabel rtable label1
403
375
x <- resolveStaticLabel rtable label2
404
376
f `dynApply` x
405
- #if __GLASGOW_HASKELL__ >= 710
406
377
resolveStaticLabel _ (StaticPtr (SDynamic typ ptr)) =
407
378
return $ unsafeToDynamic typ (deRefStaticPtr ptr)
408
- #endif
409
379
410
380
-- | Resolve a static value
411
381
unstatic :: Typeable a => RemoteTable -> Static a -> Either String a
@@ -425,11 +395,7 @@ instance Binary (Closure a) where
425
395
put (Closure st env) = put st >> put env
426
396
get = Closure <$> get <*> get
427
397
428
- #if MIN_VERSION_bytestring(0,10,0)
429
398
instance NFData (Closure a ) where rnf (Closure f b) = rnf f `seq` rnf b
430
- #else
431
- instance NFData (Closure a ) where rnf (Closure f b) = rnf f `seq` BSL. length b `seq` ()
432
- #endif
433
399
434
400
closure :: Static (ByteString -> a ) -- ^ Decoder
435
401
-> ByteString -- ^ Encoded closure environment
0 commit comments