Skip to content

Commit 0ab52c3

Browse files
Remove some minor cruft
1 parent afb58d6 commit 0ab52c3

File tree

4 files changed

+37
-46
lines changed

4 files changed

+37
-46
lines changed

src/Constrained/Base.hs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ module Constrained.Base (
7272
-- * Building `Pred`, `Specification`, `Term` etc.
7373
bind,
7474
name,
75-
named,
7675

7776
-- * TODO: documentme
7877
propagateSpec,
@@ -772,12 +771,6 @@ name :: String -> Term a -> Term a
772771
name nh (V (Var i _)) = V (Var i nh)
773772
name _ _ = error "applying name to non-var thing! Shame on you!"
774773

775-
-- | Give a Term a nameHint, if its a Var, and doesn't already have one,
776-
-- otherwise return the Term unchanged.
777-
named :: String -> Term a -> Term a
778-
named nh t@(V (Var i x)) = if x /= "v" then t else V (Var i nh)
779-
named _ t = t
780-
781774
-- | Create a `Binder` with a fresh variable, used in e.g. `constrained`
782775
bind :: (HasSpec a, IsPred p) => (Term a -> p) -> Binder a
783776
bind bodyf = newv :-> bodyPred

src/Constrained/Generation.hs

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ module Constrained.Generation (
5151
pattern SumSpec,
5252
) where
5353

54-
-- import Debug.Trace
5554
import Constrained.AbstractSyntax
5655
import Constrained.Base
5756
import Constrained.Conformance
@@ -98,40 +97,39 @@ import Prelude hiding (cycle, pred)
9897
-- generators are not flexible enough.
9998
genFromSpecT ::
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
137135
genFromSpec :: forall a. (HasCallStack, HasSpec a) => Specification a -> Gen a

src/Constrained/Spec/Map.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ instance
186186
n <- genFromSpecT size'
187187
let go 0 _ m = pure m
188188
go n' kvs' m = do
189-
-- mkv <- tryGenT $ genFromSpecT kvs'
190189
mkv <- inspect $ genFromSpecT kvs'
191190
case mkv of
192191
Result (k, v) ->

src/Constrained/Syntax.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ reify t f body =
211211
, Explain (pure ("reify " ++ show t ++ " somef $")) $ toPred (body x)
212212
]
213213

214+
-- | Like `reify` but provide a @[`var`| ... |]@-style name explicitly
214215
reifyWithName ::
215216
( HasSpec a
216217
, HasSpec b
@@ -222,9 +223,9 @@ reifyWithName ::
222223
(Term b -> p) ->
223224
Pred
224225
reifyWithName nam t f body =
225-
exists (\eval -> pure $ f (eval t)) $ \x ->
226-
[ reifies (named nam x) t f
227-
, Explain (pure ("reify " ++ show t ++ " somef $")) $ toPred (body (named nam x))
226+
exists (\eval -> pure $ f (eval t)) $ \(name nam -> x) ->
227+
[ reifies x t f
228+
, Explain (pure ("reify " ++ show t ++ " somef $")) $ toPred (body x)
228229
]
229230

230231
-- | Like `suchThat` for constraints

0 commit comments

Comments
 (0)