Move MonadAtomicRef ST instance to Nix.Thunk
This commit is contained in:
parent
ae09c47b7d
commit
3b4af6f781
|
@ -26,6 +26,7 @@ import Control.Monad.Except
|
|||
import Control.Monad.Reader
|
||||
import Control.Monad.Ref
|
||||
import Control.Monad.State
|
||||
import Control.Monad.ST
|
||||
import Control.Monad.Writer
|
||||
import Data.GADT.Compare
|
||||
import Data.IORef
|
||||
|
@ -37,6 +38,19 @@ import Unsafe.Coerce
|
|||
|
||||
import Nix.Utils
|
||||
|
||||
-- Since there's no forking, it's automatically atomic.
|
||||
instance MonadAtomicRef (ST s) where
|
||||
atomicModifyRef r f = do
|
||||
v <- readRef r
|
||||
let (a, b) = f v
|
||||
writeRef r a
|
||||
return b
|
||||
atomicModifyRef' r f = do
|
||||
v <- readRef r
|
||||
let (a, b) = f v
|
||||
writeRef r $! a
|
||||
return b
|
||||
|
||||
data Deferred m v = Deferred (m v) | Computed v
|
||||
deriving (Functor, Foldable, Traversable)
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
{-# LANGUAGE TypeFamilies #-}
|
||||
{-# LANGUAGE TypeSynonymInstances #-}
|
||||
|
||||
{-# OPTIONS_GHC -Wno-name-shadowing -Wno-orphans #-}
|
||||
{-# OPTIONS_GHC -Wno-name-shadowing #-}
|
||||
|
||||
module Nix.Type.Infer (
|
||||
Constraint(..),
|
||||
|
@ -186,19 +186,6 @@ instance Monoid InferError where
|
|||
-- Inference
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
-- Since there's no forking, it's automatically atomic.
|
||||
instance MonadAtomicRef (ST s) where
|
||||
atomicModifyRef r f = do
|
||||
v <- readRef r
|
||||
let (a, b) = f v
|
||||
writeRef r a
|
||||
return b
|
||||
atomicModifyRef' r f = do
|
||||
v <- readRef r
|
||||
let (a, b) = f v
|
||||
writeRef r $! a
|
||||
return b
|
||||
|
||||
-- | Run the inference monad
|
||||
runInfer' ::
|
||||
( MonadFreshId Int m
|
||||
|
|
Loading…
Reference in a new issue