From 642d8021506b62195b8eb10093a795fa33084d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Facundo=20Dom=C3=ADnguez?= Date: Thu, 27 Apr 2023 18:00:19 -0300 Subject: [PATCH] Add specs for Language.R.GC --- inline-r/inline-r.cabal | 2 +- inline-r/src/Language/R/GC.hs | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/inline-r/inline-r.cabal b/inline-r/inline-r.cabal index a6830991..3c34174c 100644 --- a/inline-r/inline-r.cabal +++ b/inline-r/inline-r.cabal @@ -63,7 +63,7 @@ library -- H.Prelude.Interactive -- Language.R -- Language.R.Debug --- Language.R.GC + Language.R.GC Language.R.Globals -- Language.R.HExp -- Language.R.Instance diff --git a/inline-r/src/Language/R/GC.hs b/inline-r/src/Language/R/GC.hs index ddd54c79..3fd6d343 100644 --- a/inline-r/src/Language/R/GC.hs +++ b/inline-r/src/Language/R/GC.hs @@ -17,18 +17,25 @@ -- discipline, at a performance cost. In particular, collections of many small, -- short-lived objects are best managed using regions. +{-# LANGUAGE GADTs #-} +{-# OPTIONS_GHC -fplugin-opt=LiquidHaskell:--skip-module=False #-} module Language.R.GC ( automatic - , automaticSome ) where +import Foreign.C -- only needed to help name resolution in LH +import Control.Monad.Primitive -- only needed to help name resolution in LH import Control.Memory.Region import Control.Monad.R.Class import Control.Exception -import Foreign.R (SomeSEXP(..)) import qualified Foreign.R as R import System.Mem.Weak (addFinalizer) +-- Helps LH name resolution. Otherwise ~ isn't found. +_f :: a ~ b => a -> b -> CString -> m (PrimState m) +_f = undefined + +{-@ automatic :: MonadR m => a:SEXP s -> m (TSEXP G (typeOf a)) @-} -- | Declare memory management for this value to be automatic. That is, the -- memory associated with it may be freed as soon as the garbage collector -- notices that it is safe to do so. @@ -38,19 +45,10 @@ import System.Mem.Weak (addFinalizer) -- value can never be observed. Indeed, it is a mere "optimization" to -- deallocate the value sooner - it would still be semantically correct to never -- deallocate it at all. -automatic :: MonadR m => R.SEXP s a -> m (R.SEXP G a) +automatic :: MonadR m => R.SEXP s -> m (R.SEXP G) automatic s = io $ mask_ $ do R.preserveObject s' s' `addFinalizer` (R.releaseObject (R.unsafeRelease s')) return s' where s' = R.unsafeRelease s - --- | 'automatic' for 'SomeSEXP'. -automaticSome :: MonadR m => R.SomeSEXP s -> m (R.SomeSEXP G) -automaticSome (SomeSEXP s) = io $ mask_ $ do - R.preserveObject s' - s' `addFinalizer` (R.releaseObject s') - return $ SomeSEXP s' - where - s' = R.unsafeRelease s