Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the structure of the GenT monad, to better track explanations. #4838

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,12 @@ conformsToImpl = property @(ImpTestM era Property) . (`runContT` pure) $ do
let
simplifiedSpec = simplifySpec spec
generator = CV2.runGenT (CV2.genFromSpecT simplifiedSpec) Loose
shrinker (Result _ x) = pure <$> shrinkWithSpec simplifiedSpec x
shrinker (Result x) = pure <$> shrinkWithSpec simplifiedSpec x
shrinker _ = []
res :: GE a <- ContT $ \c ->
pure $ forAllShrinkBlind generator shrinker c
case res of
Result _ x -> pure x
Result x -> pure x
_ -> ContT . const . pure $ property Discard
env <- forAllSpec $ environmentSpec @fn @rule @era ctx
deepEval env "environment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import Cardano.Ledger.Plutus.CostModels (CostModels)
import Cardano.Ledger.Plutus.ExUnits
import Cardano.Ledger.Shelley.PParams (ProposedPPUpdates (..))
import Constrained hiding (Value)
import Constrained.Base (genListWithSize)
import Constrained.Univ ()
import Control.Monad.Identity (Identity (..))
import Control.Monad.Trans.Fail.String
Expand Down Expand Up @@ -95,6 +96,10 @@ instance BaseUniverse fn => Foldy fn Coin where
genList s s' = map fromSimpleRep <$> genList @fn @Word64 (toSimpleRepSpec s) (toSimpleRepSpec s')
theAddFn = addFn
theZero = Coin 0
genSizedList sz elemSpec foldSpec =
map fromSimpleRep
<$> genListWithSize @fn @Word64 sz (toSimpleRepSpec elemSpec) (toSimpleRepSpec foldSpec)
nonNeg = True

-- TODO: This is hack to get around the need for `Num` in `NumLike`. We should possibly split
-- this up so that `NumLike` has its own addition etc. instead?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ import Cardano.Ledger.UTxO
import Cardano.Ledger.Val (Val)
import Constrained hiding (Sized, Value)
import Constrained qualified as C
import Constrained.Base (Binder (..), HasGenHint (..), Pred (..), Term (..), explainSpecOpt)
import Constrained.Base (
Binder (..),
HasGenHint (..),
Pred (..),
Term (..),
explainSpecOpt,
genListWithSize,
)
import Constrained.Spec.Map
import Control.DeepSeq (NFData)
import Crypto.Hash (Blake2b_224)
Expand Down Expand Up @@ -250,6 +257,10 @@ instance IsConwayUniv fn => Foldy fn DeltaCoin where
genList s s' = map fromSimpleRep <$> genList @fn @Integer (toSimpleRepSpec s) (toSimpleRepSpec s')
theAddFn = addFn
theZero = DeltaCoin 0
genSizedList sz elemSpec foldSpec =
map fromSimpleRep
<$> genListWithSize @fn @Integer sz (toSimpleRepSpec elemSpec) (toSimpleRepSpec foldSpec)
nonNeg = False

deriving via Integer instance Num DeltaCoin

Expand Down
2 changes: 2 additions & 0 deletions libs/constrained-generators/constrained-generators.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ library
Constrained.Examples.Basic
Constrained.Examples.CheatSheet
Constrained.Examples.Either
Constrained.Examples.Fold
Constrained.Examples.List
Constrained.Examples.Map
Constrained.Examples.Set
Expand All @@ -41,6 +42,7 @@ library
Constrained.Spec.Map
Constrained.Spec.Pairs
Constrained.Spec.Tree
Constrained.SumList
Constrained.Syntax
Constrained.Univ

Expand Down
Loading
Loading