@@ -51,7 +51,6 @@ module Constrained.Generation (
5151 pattern SumSpec ,
5252) where
5353
54- -- import Debug.Trace
5554import Constrained.AbstractSyntax
5655import Constrained.Base
5756import Constrained.Conformance
@@ -98,40 +97,39 @@ import Prelude hiding (cycle, pred)
9897-- generators are not flexible enough.
9998genFromSpecT ::
10099 forall a m . (HasCallStack , HasSpec a , MonadGenError m ) => Specification a -> GenT m a
101- genFromSpecT (simplifySpec -> spec) =
102- case spec of
103- ExplainSpec [] s -> genFromSpecT s
104- ExplainSpec es s -> push es (genFromSpecT s)
105- MemberSpec as -> explain (" genFromSpecT on spec" ++ show spec) $ pureGen (elements (NE. toList as))
106- TrueSpec -> genFromSpecT (typeSpec $ emptySpec @ a )
107- SuspendedSpec x p
108- -- NOTE: If `x` isn't free in `p` we still have to try to generate things
109- -- from `p` to make sure `p` is sat and then we can throw it away. A better
110- -- approach would be to only do this in the case where we don't know if `p`
111- -- is sat. The proper way to implement such a sat check is to remove
112- -- sat-but-unnecessary variables in the optimiser.
113- | not $ Name x `appearsIn` p -> do
114- ! _ <- genFromPreds mempty p
115- genFromSpecT TrueSpec
116- | otherwise -> do
117- env <- genFromPreds mempty p
118- Env. find env x
119- TypeSpec s cant -> do
120- mode <- getMode
121- explainNE
122- ( NE. fromList
123- [ " genFromSpecT on (TypeSpec tspec cant) at type " ++ showType @ a
124- , " tspec = "
125- , show s
126- , " cant = " ++ show (short cant)
127- , " with mode " ++ show mode
128- ]
129- )
130- $
131- -- TODO: we could consider giving `cant` as an argument to `genFromTypeSpec` if this
132- -- starts giving us trouble.
133- genFromTypeSpec s `suchThatT` (`notElem` cant)
134- ErrorSpec e -> genErrorNE e
100+ genFromSpecT (simplifySpec -> spec) = case spec of
101+ ExplainSpec [] s -> genFromSpecT s
102+ ExplainSpec es s -> push es (genFromSpecT s)
103+ MemberSpec as -> explain (" genFromSpecT on spec" ++ show spec) $ pureGen (elements (NE. toList as))
104+ TrueSpec -> genFromSpecT (typeSpec $ emptySpec @ a )
105+ SuspendedSpec x p
106+ -- NOTE: If `x` isn't free in `p` we still have to try to generate things
107+ -- from `p` to make sure `p` is sat and then we can throw it away. A better
108+ -- approach would be to only do this in the case where we don't know if `p`
109+ -- is sat. The proper way to implement such a sat check is to remove
110+ -- sat-but-unnecessary variables in the optimiser.
111+ | not $ Name x `appearsIn` p -> do
112+ ! _ <- genFromPreds mempty p
113+ genFromSpecT TrueSpec
114+ | otherwise -> do
115+ env <- genFromPreds mempty p
116+ Env. find env x
117+ TypeSpec s cant -> do
118+ mode <- getMode
119+ explainNE
120+ ( NE. fromList
121+ [ " genFromSpecT on (TypeSpec tspec cant) at type " ++ showType @ a
122+ , " tspec = "
123+ , show s
124+ , " cant = " ++ show (short cant)
125+ , " with mode " ++ show mode
126+ ]
127+ )
128+ $
129+ -- TODO: we could consider giving `cant` as an argument to `genFromTypeSpec` if this
130+ -- starts giving us trouble.
131+ genFromTypeSpec s `suchThatT` (`notElem` cant)
132+ ErrorSpec e -> genErrorNE e
135133
136134-- | A version of `genFromSpecT` that simply errors if the generator fails
137135genFromSpec :: forall a . (HasCallStack , HasSpec a ) => Specification a -> Gen a
0 commit comments