17
17
-- discipline, at a performance cost. In particular, collections of many small,
18
18
-- short-lived objects are best managed using regions.
19
19
20
+ {-# LANGUAGE GADTs #-}
21
+ {-# OPTIONS_GHC -fplugin-opt=LiquidHaskell:--skip-module=False #-}
20
22
module Language.R.GC
21
23
( automatic
22
- , automaticSome
23
24
) where
24
25
26
+ import Foreign.C -- only needed to help name resolution in LH
27
+ import Control.Monad.Primitive -- only needed to help name resolution in LH
25
28
import Control.Memory.Region
26
29
import Control.Monad.R.Class
27
30
import Control.Exception
28
- import Foreign.R (SomeSEXP (.. ))
29
31
import qualified Foreign.R as R
30
32
import System.Mem.Weak (addFinalizer )
31
33
34
+ -- Helps LH name resolution. Otherwise ~ isn't found.
35
+ _f :: a ~ b => a -> b -> CString -> m (PrimState m )
36
+ _f = undefined
37
+
38
+ {-@ automatic :: MonadR m => a:SEXP s -> m (TSEXP G (typeOf a )) @-}
32
39
-- | Declare memory management for this value to be automatic. That is, the
33
40
-- memory associated with it may be freed as soon as the garbage collector
34
41
-- notices that it is safe to do so.
@@ -38,19 +45,10 @@ import System.Mem.Weak (addFinalizer)
38
45
-- value can never be observed. Indeed, it is a mere "optimization" to
39
46
-- deallocate the value sooner - it would still be semantically correct to never
40
47
-- deallocate it at all.
41
- automatic :: MonadR m => R. SEXP s a -> m (R. SEXP G a )
48
+ automatic :: MonadR m => R. SEXP s -> m (R. SEXP G )
42
49
automatic s = io $ mask_ $ do
43
50
R. preserveObject s'
44
51
s' `addFinalizer` (R. releaseObject (R. unsafeRelease s'))
45
52
return s'
46
53
where
47
54
s' = R. unsafeRelease s
48
-
49
- -- | 'automatic' for 'SomeSEXP'.
50
- automaticSome :: MonadR m => R. SomeSEXP s -> m (R. SomeSEXP G )
51
- automaticSome (SomeSEXP s) = io $ mask_ $ do
52
- R. preserveObject s'
53
- s' `addFinalizer` (R. releaseObject s')
54
- return $ SomeSEXP s'
55
- where
56
- s' = R. unsafeRelease s
0 commit comments