@@ -74,7 +74,7 @@ import GHC.Natural
7474import GHC.Real
7575import GHC.Stack
7676import GHC.TypeLits
77- import Prettyprinter
77+ import Prettyprinter hiding ( cat )
7878import System.Random
7979import System.Random.Stateful
8080import Test.QuickCheck hiding (Args , Fun , forAll )
@@ -532,7 +532,7 @@ monitorPred env = \case
532532 monitorPred (extendEnv x val env) p
533533 Exists k (x :-> p) -> do
534534 case k (errorGE . explain1 " monitorPred: Exists" . runTerm env) of
535- Result _ a -> monitorPred (extendEnv x a env) p
535+ Result a -> monitorPred (extendEnv x a env) p
536536 _ -> pure id
537537 Explain es p -> explain es $ monitorPred env p
538538
@@ -787,7 +787,7 @@ instance (HasSpec fn a, Arbitrary (TypeSpec fn a)) => Arbitrary (Specification f
787787 shrink (SuspendedSpec x p) =
788788 [TrueSpec , ErrorSpec (pure " From shrinking SuspendedSpec" )]
789789 ++ [ s
790- | Result _ s <- [computeSpec x p]
790+ | Result s <- [computeSpec x p]
791791 , not $ isSuspendedSpec s
792792 ]
793793 ++ [SuspendedSpec x p' | p' <- shrinkPred p]
@@ -1167,8 +1167,7 @@ genFromSpecT (simplifySpec -> spec) = case spec of
11671167 [ " genFromSpecT on (TypeSpec tspec cant) at type " ++ showType @ a
11681168 , " tspec = "
11691169 , show s
1170- , " cant = "
1171- , unlines (map (\ x -> " " ++ show x) cant)
1170+ , " cant = " ++ show (short cant)
11721171 , " with mode " ++ show mode
11731172 ]
11741173 )
@@ -1196,7 +1195,7 @@ shrinkWithSpec (simplifySpec -> spec) a = filter (`conformsToSpec` spec) $ case
11961195
11971196shrinkFromPreds :: HasSpec fn a => Pred fn -> Var a -> a -> [a ]
11981197shrinkFromPreds p
1199- | Result _ plan <- prepareLinearization p = \ x a -> listFromGE $ do
1198+ | Result plan <- prepareLinearization p = \ x a -> listFromGE $ do
12001199 -- NOTE: we do this to e.g. guard against bad construction functions in Exists
12011200 xaGood <- checkPred (singletonEnv x a) p
12021201 unless xaGood $
@@ -1292,7 +1291,7 @@ envFromPred env p = case p of
12921291genFromSpec :: forall fn a . (HasCallStack , HasSpec fn a ) => Specification fn a -> Gen a
12931292genFromSpec spec = do
12941293 res <- catchGen $ genFromSpecT @ fn @ a @ GE spec
1295- either (error . show . NE. toList ) pure res
1294+ either (error . show . catMessages ) pure res
12961295
12971296-- | A version of `genFromSpecT` that takes a seed and a size and gives you a result
12981297genFromSpecWithSeed ::
@@ -1309,9 +1308,9 @@ debugSpec spec = do
13091308 then putStrLn " True"
13101309 else putStrLn " False, perhaps there is an unsafeExists in the spec?"
13111310 case ans of
1312- FatalError xs x -> mapM f xs >> f x
1313- GenError xs x -> mapM f xs >> f x
1314- Result _ x -> print spec >> print x >> ok x
1311+ FatalError xs -> mapM_ f xs
1312+ GenError xs -> mapM_ f xs
1313+ Result x -> print spec >> print x >> ok x
13151314
13161315genInverse ::
13171316 ( MonadGenError m
@@ -1519,7 +1518,7 @@ backPropagation (SolverPlan plan graph) = SolverPlan (go [] (reverse plan)) grap
15191518 termVarEqCases spec x' t
15201519 | Just Refl <- eqVar x x'
15211520 , [Name y] <- Set. toList $ freeVarSet t
1522- , Result _ ctx <- toCtx y t =
1521+ , Result ctx <- toCtx y t =
15231522 [SolverStage y [] (propagateSpec spec ctx)]
15241523 termVarEqCases _ _ _ = []
15251524
@@ -1608,7 +1607,7 @@ short xs = "([" <+> viaShow (length xs) <+> "elements ...] @" <> prettyType @a <
16081607prettyPlan :: HasSpec fn a => Specification fn a -> Doc ann
16091608prettyPlan (simplifySpec -> spec)
16101609 | SuspendedSpec _ p <- spec
1611- , Result _ plan <- prepareLinearization p =
1610+ , Result plan <- prepareLinearization p =
16121611 vsep'
16131612 [ " Simplified spec:" /> pretty spec
16141613 , pretty plan
@@ -1761,9 +1760,9 @@ normalizeSolverStage (SolverStage x ps spec) = SolverStage x ps'' (spec <> spec'
17611760
17621761fromGESpec :: HasCallStack => GE (Specification fn a ) -> Specification fn a
17631762fromGESpec ge = case ge of
1764- Result [] s -> s
1765- Result es s -> addToErrorSpec ( foldr1 (<>) es) s
1766- _ -> fromGE ErrorSpec ge
1763+ Result s -> s
1764+ GenError xs -> ErrorSpec (catMessageList xs)
1765+ FatalError es -> error $ catMessages es
17671766
17681767-- | Add the explanations, if it's an ErrorSpec, else drop them
17691768addToErrorSpec :: NE. NonEmpty String -> Specification fn a -> Specification fn a
@@ -1886,8 +1885,10 @@ computeSpecSimplified x p = localGESpec $ case p of
18861885 [" The impossible happened in computeSpec: Reifies" , " " ++ show x, show $ indent 2 (pretty p)]
18871886 where
18881887 -- We want `genError` to turn into `ErrorSpec` and we want `FatalError` to turn into `FatalError`
1889- localGESpec ge@ FatalError {} = ge
1890- localGESpec ge = pure $ fromGESpec ge
1888+ localGESpec ge = case ge of
1889+ (GenError xs) -> Result $ ErrorSpec (catMessageList xs)
1890+ (FatalError es) -> FatalError es
1891+ (Result x) -> Result x
18911892
18921893-- | Precondition: the `Pred fn` defines the `Var a`.
18931894--
@@ -5636,7 +5637,7 @@ showType :: forall t. Typeable t => String
56365637showType = show (typeRep (Proxy @ t ))
56375638
56385639prettyType :: forall t x . Typeable t => Doc x
5639- prettyType = fromString $ showType @ t
5640+ prettyType = fromString $ show (typeRep ( Proxy @ t ))
56405641
56415642instance HasSpec fn a => Pretty (Term fn a ) where
56425643 pretty = prettyPrec 0
@@ -6236,11 +6237,13 @@ checkPredE env msgs = \case
62366237 Right v -> v
62376238 Left es -> error $ unlines $ NE. toList (msgs <> es)
62386239 in case k eval of
6239- Result _ a -> checkPredE (extendEnv x a env) msgs p
6240- FatalError ess es -> Just (msgs <> foldr1 (<>) ess <> es)
6241- GenError ess es -> Just (msgs <> foldr1 (<>) ess <> es)
6240+ Result a -> checkPredE (extendEnv x a env) msgs p
6241+ FatalError es -> Just (msgs <> catMessageList es)
6242+ GenError es -> Just (msgs <> catMessageList es)
62426243 Explain es p -> checkPredE env (msgs <> es) p
62436244
6245+ -- | conformsToSpec with explanation. Nothing if (conformsToSpec a spec),
6246+ -- but (Just explanations) if not(conformsToSpec a spec).
62446247conformsToSpecE ::
62456248 forall fn a .
62466249 HasSpec fn a =>
@@ -6249,7 +6252,7 @@ conformsToSpecE ::
62496252 NE. NonEmpty String ->
62506253 Maybe (NE. NonEmpty String )
62516254conformsToSpecE a (ExplainSpec [] s) msgs = conformsToSpecE a s msgs
6252- conformsToSpecE a (ExplainSpec (x : xs) s) msgs = conformsToSpecE a s (msgs <> (x NE. :| xs))
6255+ conformsToSpecE a (ExplainSpec (x : xs) s) msgs = conformsToSpecE a s ((x :| xs) <> msgs )
62536256conformsToSpecE _ TrueSpec _ = Nothing
62546257conformsToSpecE a (MemberSpec as) msgs =
62556258 if elem a as
0 commit comments