Skip to content

Commit b50a995

Browse files
remove Realized (#76)
* remove Realized * remove unnecessary stuff * fmt * migration notes * cabal fmt
1 parent 25bac1a commit b50a995

File tree

5 files changed

+28
-50
lines changed

5 files changed

+28
-50
lines changed

quickcheck-dynamic-iosim/quickcheck-dynamic-iosim.cabal

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ library
5656
hs-source-dirs: src
5757
exposed-modules: Test.QuickCheck.StateModel.IOSim
5858
build-depends:
59-
, base >=4.7 && <5
60-
, io-classes
59+
, base >=4.7 && <5
6160
, io-sim
6261
, QuickCheck
63-
, quickcheck-dynamic
64-
, stm

quickcheck-dynamic-iosim/src/Test/QuickCheck/StateModel/IOSim.hs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,12 @@
22

33
module Test.QuickCheck.StateModel.IOSim where
44

5-
import Control.Concurrent
6-
import Control.Concurrent.Class.MonadSTM.TMVar qualified as IOClass
7-
import Control.Concurrent.Class.MonadSTM.TVar qualified as IOClass
8-
import Control.Concurrent.STM
95
import Control.Exception (SomeException (..))
10-
import Control.Monad.Class.MonadFork qualified as IOClass
116
import Control.Monad.IOSim
127

138
import Test.QuickCheck
149
import Test.QuickCheck.Gen.Unsafe (Capture (Capture), capture)
1510
import Test.QuickCheck.Monadic
16-
import Test.QuickCheck.StateModel
17-
18-
type family RealizeIOSim s a where
19-
RealizeIOSim s ThreadId = IOClass.ThreadId (IOSim s)
20-
RealizeIOSim s (TVar a) = IOClass.TVar (IOSim s) a
21-
RealizeIOSim s (MVar a) = IOClass.TMVar (IOSim s) a
22-
RealizeIOSim s (f a b) = f (RealizeIOSim s a) (RealizeIOSim s b)
23-
RealizeIOSim s (f a) = f (RealizeIOSim s a)
24-
RealizeIOSim s a = a
25-
26-
type instance Realized (IOSim s) a = RealizeIOSim s a
2711

2812
runIOSimProperty :: Testable a => (forall s. PropertyM (IOSim s) a) -> Gen (SimTrace Property, Property)
2913
runIOSimProperty p = do

quickcheck-dynamic/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ changes.
99

1010
## UNRELEASED
1111

12+
* Breaking removed `Realized`
13+
- To migrate uses of `Realized` with `IOSim`, index the state type on the choice of `RunModel` monad
14+
and index the relevant types:
15+
```
16+
-- Turn:
17+
data ModelState = State { threadId :: Var ThreadId }
18+
-- Into:
19+
data ModelState m = State { threadId :: Var (ThreadId m) }
20+
```
21+
1222
## 3.4.1 - 2024-03-22
1323
1424
* [#70](https://github.com/input-output-hk/quickcheck-dynamic/pull/70) Expose `IsPerformResult` typeclass

quickcheck-dynamic/src/Test/QuickCheck/StateModel.hs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module Test.QuickCheck.StateModel (
2323
EnvEntry (..),
2424
pattern (:=?),
2525
Env,
26-
Realized,
2726
Generic,
2827
IsPerformResult,
2928
monitorPost,
@@ -41,12 +40,9 @@ module Test.QuickCheck.StateModel (
4140
) where
4241

4342
import Control.Monad
44-
import Control.Monad.Identity
4543
import Control.Monad.Reader
46-
import Control.Monad.State
4744
import Control.Monad.Writer (WriterT, runWriterT, tell)
4845
import Data.Data
49-
import Data.Kind
5046
import Data.List
5147
import Data.Monoid (Endo (..))
5248
import Data.Set qualified as Set
@@ -178,15 +174,6 @@ instance {-# OVERLAPPING #-} IsPerformResult Void a where
178174
instance {-# OVERLAPPABLE #-} (PerformResult e a ~ Either e a) => IsPerformResult e a where
179175
performResultToEither = id
180176

181-
-- TODO: maybe it makes sense to write
182-
-- out a long list of these instances
183-
type family Realized (m :: Type -> Type) a :: Type
184-
type instance Realized IO a = a
185-
type instance Realized (StateT s m) a = Realized m a
186-
type instance Realized (ReaderT r m) a = Realized m a
187-
type instance Realized (WriterT w m) a = Realized m a
188-
type instance Realized Identity a = a
189-
190177
newtype PostconditionM m a = PostconditionM {runPost :: WriterT (Endo Property, Endo Property) m a}
191178
deriving (Functor, Applicative, Monad)
192179

@@ -221,57 +208,57 @@ class (forall a. Show (Action state a), Monad m) => RunModel state m where
221208
--
222209
-- The `Lookup` parameter provides an /environment/ to lookup `Var
223210
-- a` instances from previous steps.
224-
perform :: Typeable a => state -> Action state a -> LookUp m -> m (PerformResult (Error state) (Realized m a))
211+
perform :: Typeable a => state -> Action state a -> LookUp -> m (PerformResult (Error state) a)
225212

226213
-- | Postcondition on the `a` value produced at some step.
227214
-- The result is `assert`ed and will make the property fail should it be `False`. This is useful
228215
-- to check the implementation produces expected values.
229-
postcondition :: (state, state) -> Action state a -> LookUp m -> Realized m a -> PostconditionM m Bool
216+
postcondition :: (state, state) -> Action state a -> LookUp -> a -> PostconditionM m Bool
230217
postcondition _ _ _ _ = pure True
231218

232219
-- | Postcondition on the result of running a _negative_ `Action`.
233220
-- The result is `assert`ed and will make the property fail should it be `False`. This is useful
234221
-- to check the implementation produces e.g. the expected errors or to check that the SUT hasn't
235222
-- been updated during the execution of the negative action.
236-
postconditionOnFailure :: (state, state) -> Action state a -> LookUp m -> Either (Error state) (Realized m a) -> PostconditionM m Bool
223+
postconditionOnFailure :: (state, state) -> Action state a -> LookUp -> Either (Error state) a -> PostconditionM m Bool
237224
postconditionOnFailure _ _ _ _ = pure True
238225

239226
-- | Allows the user to attach additional information to the `Property` at each step of the process.
240227
-- This function is given the full transition that's been executed, including the start and ending
241228
-- `state`, the `Action`, the current environment to `Lookup` and the value produced by `perform`
242229
-- while executing this step.
243-
monitoring :: (state, state) -> Action state a -> LookUp m -> Either (Error state) (Realized m a) -> Property -> Property
230+
monitoring :: (state, state) -> Action state a -> LookUp -> Either (Error state) a -> Property -> Property
244231
monitoring _ _ _ _ prop = prop
245232

246233
-- | Allows the user to attach additional information to the `Property` if a positive action fails.
247-
monitoringFailure :: state -> Action state a -> LookUp m -> Error state -> Property -> Property
234+
monitoringFailure :: state -> Action state a -> LookUp -> Error state -> Property -> Property
248235
monitoringFailure _ _ _ _ prop = prop
249236

250-
type LookUp m = forall a. Typeable a => Var a -> Realized m a
237+
type LookUp = forall a. Typeable a => Var a -> a
251238

252-
type Env m = [EnvEntry m]
239+
type Env = [EnvEntry]
253240

254-
data EnvEntry m where
255-
(:==) :: Typeable a => Var a -> Realized m a -> EnvEntry m
241+
data EnvEntry where
242+
(:==) :: Typeable a => Var a -> a -> EnvEntry
256243

257244
infix 5 :==
258245

259-
pattern (:=?) :: forall a m. Typeable a => Var a -> Realized m a -> EnvEntry m
246+
pattern (:=?) :: forall a. Typeable a => Var a -> a -> EnvEntry
260247
pattern v :=? val <- (viewAtType -> Just (v, val))
261248

262-
viewAtType :: forall a m. Typeable a => EnvEntry m -> Maybe (Var a, Realized m a)
249+
viewAtType :: forall a. Typeable a => EnvEntry -> Maybe (Var a, a)
263250
viewAtType ((v :: Var b) :== val)
264251
| Just Refl <- eqT @a @b = Just (v, val)
265252
| otherwise = Nothing
266253

267-
lookUpVarMaybe :: forall a m. Typeable a => Env m -> Var a -> Maybe (Realized m a)
254+
lookUpVarMaybe :: forall a. Typeable a => Env -> Var a -> Maybe a
268255
lookUpVarMaybe [] _ = Nothing
269256
lookUpVarMaybe (((v' :: Var b) :== a) : env) v =
270257
case eqT @a @b of
271258
Just Refl | v == v' -> Just a
272259
_ -> lookUpVarMaybe env v
273260

274-
lookUpVar :: Typeable a => Env m -> Var a -> Realized m a
261+
lookUpVar :: Typeable a => Env -> Var a -> a
275262
lookUpVar env v = case lookUpVarMaybe env v of
276263
Nothing -> error $ "Variable " ++ show v ++ " is not bound at type " ++ show (typeRep v) ++ "!"
277264
Just a -> a
@@ -505,7 +492,7 @@ runActions
505492
, forall a. IsPerformResult e a
506493
)
507494
=> Actions state
508-
-> PropertyM m (Annotated state, Env m)
495+
-> PropertyM m (Annotated state, Env)
509496
runActions (Actions_ rejected (Smart _ actions)) = do
510497
(finalState, env) <- runSteps initialAnnotatedState [] actions
511498
unless (null rejected) $
@@ -523,9 +510,9 @@ runSteps
523510
, forall a. IsPerformResult e a
524511
)
525512
=> Annotated state
526-
-> Env m
513+
-> Env
527514
-> [Step state]
528-
-> PropertyM m (Annotated state, Env m)
515+
-> PropertyM m (Annotated state, Env)
529516
runSteps s env [] = return (s, reverse env)
530517
runSteps s env ((v := act) : as) = do
531518
pre $ computePrecondition s act

quickcheck-dynamic/test/Spec/DynamicLogic/RegistryModel.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ instance RunModel RegState RegM where
145145
. tabulate "Registry size" [show $ Map.size (regs s')]
146146

147147
data ShowDict a where
148-
ShowDict :: Show (Realized RegM a) => ShowDict a
148+
ShowDict :: Show a => ShowDict a
149149

150150
showDictAction :: forall a. Action RegState a -> ShowDict a
151151
showDictAction Spawn{} = ShowDict

0 commit comments

Comments
 (0)