Skip to content
Open
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
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved the partial evaluation for bit vectors. ([#176](https://github.com/lsrcz/grisette/pull/176))
- Added `symRotateNegated` and `symShiftNegated`. ([#181](https://github.com/lsrcz/grisette/pull/181))
- Added `mrg` and `sym` variants for all reasonable operations from
`Control.Monad`, `Control.Applicative`, `Data.Foldable`, `Data.List`, and `Data.Traversable`.
([#182](https://github.com/lsrcz/grisette/pull/182))
`Control.Monad`, `Control.Applicative`, `Data.Foldable`, `Data.List`, `Data.Traversable`,
and `Data.Function`.
([#182](https://github.com/lsrcz/grisette/pull/182),
[#186](https://github.com/lsrcz/grisette/pull/186))
- Added `mrgIfPropagatedStrategy`. ([#184](https://github.com/lsrcz/grisette/pull/184))
- Added instances for `Const`. ([#186](https://github.com/lsrcz/grisette/pull/186))
- Added support for [microlens](https://hackage.haskell.org/package/microlens). ([#186](https://github.com/lsrcz/grisette/pull/186))
- Added `freshString`. ([#188](https://github.com/lsrcz/grisette/pull/188))

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
let
pkgs = nixpkgs.legacyPackages.${system};

hPkgs = pkgs.haskell.packages."ghc982";
hPkgs = pkgs.haskell.packages."ghc964";

myDevTools = [
hPkgs.ghc # GHC compiler in the desired version (will be available on PATH)
# hPkgs.ghcid # Continuous terminal Haskell compile checker
# hPkgs.ormolu # Haskell formatter
# hPkgs.hlint # Haskell codestyle checker
# hPkgs.haskell-language-server # LSP server for editor
hPkgs.hlint # Haskell codestyle checker
hPkgs.haskell-language-server # LSP server for editor
hPkgs.cabal-install
stack-wrapped
# (pkgs.ihaskell.override {
Expand Down
11 changes: 11 additions & 0 deletions grisette.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,15 @@ library
Grisette.Lib.Data.Bool
Grisette.Lib.Data.Either
Grisette.Lib.Data.Foldable
Grisette.Lib.Data.Function
Grisette.Lib.Data.Functor
Grisette.Lib.Data.Functor.Const
Grisette.Lib.Data.Functor.Sum
Grisette.Lib.Data.List
Grisette.Lib.Data.Maybe
Grisette.Lib.Data.Traversable
Grisette.Lib.Data.Tuple
Grisette.Lib.Lens.Micro
Grisette.Qualified.ParallelUnionDo
Grisette.Utils
Grisette.Utils.Parameterized
Expand All @@ -161,6 +164,8 @@ library
, hashtables >=1.2.3.4 && <1.4
, intern >=0.9.2 && <0.10
, loch-th >=0.2.2 && <0.3
, microlens
, microlens-th
, mtl >=2.2.2 && <2.4
, parallel >=3.2.2.0 && <3.3
, prettyprinter >=1.5.0 && <1.8
Expand Down Expand Up @@ -200,6 +205,8 @@ test-suite doctest
, hashtables >=1.2.3.4 && <1.4
, intern >=0.9.2 && <0.10
, loch-th >=0.2.2 && <0.3
, microlens
, microlens-th
, mtl >=2.2.2 && <2.4
, parallel >=3.2.2.0 && <3.3
, prettyprinter >=1.5.0 && <1.8
Expand Down Expand Up @@ -269,9 +276,11 @@ test-suite spec
Grisette.Lib.Control.Monad.Trans.State.StrictTests
Grisette.Lib.Control.MonadTests
Grisette.Lib.Data.FoldableTests
Grisette.Lib.Data.FunctionTests
Grisette.Lib.Data.FunctorTests
Grisette.Lib.Data.ListTests
Grisette.Lib.Data.TraversableTests
Grisette.Lib.Lens.MicroTests
Grisette.TestUtil.NoMerge
Grisette.TestUtil.PrettyPrint
Grisette.TestUtil.SymbolicAssertion
Expand All @@ -293,6 +302,8 @@ test-suite spec
, hashtables >=1.2.3.4 && <1.4
, intern >=0.9.2 && <0.10
, loch-th >=0.2.2 && <0.3
, microlens
, microlens-th
, mtl >=2.2.2 && <2.4
, parallel >=3.2.2.0 && <3.3
, prettyprinter >=1.5.0 && <1.8
Expand Down
2 changes: 2 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ dependencies:
- prettyprinter >= 1.5.0 && < 1.8
- async >= 2.2.2 && < 2.3
- stm >= 2.5 && < 2.6
- microlens
- microlens-th

flags:
{
Expand Down
6 changes: 6 additions & 0 deletions src/Grisette/Core/Control/Monad/UnionM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,12 @@ instance (LogicalOp a, Mergeable a) => LogicalOp (UnionM a) where
symXor = unionMBinOp symXor
symImplies = unionMBinOp symImplies

instance (Monoid a, Mergeable a) => Monoid (UnionM a) where
mempty = mrgSingle mempty

instance (Monoid a, Mergeable a) => Semigroup (UnionM a) where
(<>) = unionMBinOp (<>)

instance (Solvable c t, Mergeable t) => Solvable c (UnionM t) where
con = mrgSingle . con
{-# INLINE con #-}
Expand Down
20 changes: 20 additions & 0 deletions src/Grisette/Core/Data/Class/BitVector.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Grisette.Core.Data.Class.BitVector
)
where

import Data.Functor.Const (Const (Const))
import Data.Proxy (Proxy (Proxy))
import GHC.TypeNats (KnownNat, type (+), type (-), type (<=))
import Grisette.Utils.Parameterized
Expand Down Expand Up @@ -129,6 +130,25 @@ class BV bv where
a ->
bv

instance (BV a) => BV (Const a b) where
bvConcat (Const a) (Const b) = Const (bvConcat a b)
{-# INLINE bvConcat #-}

bvZext n (Const a) = Const (bvZext n a)
{-# INLINE bvZext #-}

bvSext n (Const a) = Const (bvSext n a)
{-# INLINE bvSext #-}

bvExt n (Const a) = Const (bvExt n a)
{-# INLINE bvExt #-}

bvSelect i j (Const a) = Const (bvSelect i j a)
{-# INLINE bvSelect #-}

bv i w = Const (bv i w)
{-# INLINE bv #-}

-- | Slicing out a smaller bit vector from a larger one, extract a slice from
-- bit @i@ down to @j@.
--
Expand Down
6 changes: 6 additions & 0 deletions src/Grisette/Core/Data/Class/EvaluateSym.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import Control.Monad.Trans.Maybe (MaybeT (MaybeT))
import qualified Control.Monad.Writer.Lazy as WriterLazy
import qualified Control.Monad.Writer.Strict as WriterStrict
import qualified Data.ByteString as B
import Data.Functor.Const (Const (Const))
import Data.Functor.Sum (Sum)
import Data.Int (Int16, Int32, Int64, Int8)
import Data.Maybe (fromJust)
Expand Down Expand Up @@ -274,3 +275,8 @@ instance (EvaluateSym' a, EvaluateSym' b) => EvaluateSym' (a :+: b) where

instance (EvaluateSym' a, EvaluateSym' b) => EvaluateSym' (a :*: b) where
evaluateSym' fillDefault model (a :*: b) = evaluateSym' fillDefault model a :*: evaluateSym' fillDefault model b

-- Const
instance (EvaluateSym a) => EvaluateSym (Const a b) where
evaluateSym fillDefault model (Const a) =
Const $ evaluateSym fillDefault model a
5 changes: 5 additions & 0 deletions src/Grisette/Core/Data/Class/ExtractSymbolics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Control.Monad.Trans.Maybe (MaybeT (MaybeT))
import qualified Control.Monad.Writer.Lazy as WriterLazy
import qualified Control.Monad.Writer.Strict as WriterStrict
import qualified Data.ByteString as B
import Data.Functor.Const (Const (Const))
import Data.Functor.Sum (Sum)
import Data.Int (Int16, Int32, Int64, Int8)
import qualified Data.Text as T
Expand Down Expand Up @@ -311,3 +312,7 @@ instance
ExtractSymbolics' (a :*: b)
where
extractSymbolics' (l :*: r) = extractSymbolics' l <> extractSymbolics' r

-- Const
instance (ExtractSymbolics a) => ExtractSymbolics (Const a b) where
extractSymbolics (Const v) = extractSymbolics v
7 changes: 7 additions & 0 deletions src/Grisette/Core/Data/Class/GPretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import qualified Control.Monad.Writer.Lazy as WriterLazy
import qualified Control.Monad.Writer.Strict as WriterStrict
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as C
import Data.Functor.Const (Const)
import Data.Functor.Sum (Sum)
import Data.Int (Int16, Int32, Int64, Int8)
import Data.String (IsString (fromString))
Expand Down Expand Up @@ -322,6 +323,12 @@ instance (GPretty (m a)) => GPretty (IdentityT m a) where
gprettyPrec 11 a
]

-- Const
deriving via
(Default (Const a b))
instance
(GPretty a) => GPretty (Const a b)

-- Prettyprint
#define GPRETTY_SYM_SIMPLE(symtype) \
instance GPretty symtype where \
Expand Down
13 changes: 13 additions & 0 deletions src/Grisette/Core/Data/Class/GenSym.hs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import qualified Control.Monad.Writer.Lazy as WriterLazy
import qualified Control.Monad.Writer.Strict as WriterStrict
import Data.Bifunctor (Bifunctor (first))
import qualified Data.ByteString as B
import Data.Functor.Const (Const (Const))
import Data.Hashable (Hashable)
import Data.Int (Int16, Int32, Int64, Int8)
import Data.String (IsString (fromString))
Expand Down Expand Up @@ -1720,3 +1721,15 @@ instance
where
go (UnionSingle x) = fresh x
go (UnionIf _ _ _ t f) = mrgIf <$> simpleFresh () <*> go t <*> go f

instance (GenSym spec a) => GenSym spec (Const a b) where
fresh spec = do
u <- fresh spec
return $ do
a <- u
mrgSingle $ Const a
{-# INLINE fresh #-}

instance (GenSymSimple spec a) => GenSymSimple spec (Const a b) where
simpleFresh spec = Const <$> simpleFresh spec
{-# INLINE simpleFresh #-}
5 changes: 5 additions & 0 deletions src/Grisette/Core/Data/Class/ITEOp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Grisette.Core.Data.Class.ITEOp
)
where

import Data.Functor.Const (Const (Const))
import GHC.TypeNats (KnownNat, type (<=))
import Grisette.IR.SymPrim.Data.Prim.InternedTerm.Term
( LinkedRep,
Expand Down Expand Up @@ -75,3 +76,7 @@ ITEOP_BV(SymWordN)
ITEOP_FUN(=~>, SymTabularFun)
ITEOP_FUN(-~>, SymGeneralFun)
#endif

instance (ITEOp a) => ITEOp (Const a b) where
symIte c (Const t) (Const f) = Const $ symIte c t f
{-# INLINE symIte #-}
13 changes: 13 additions & 0 deletions src/Grisette/Core/Data/Class/LogicalOp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Grisette.Core.Data.Class.LogicalOp
)
where

import Data.Functor.Const (Const (Const))
import Grisette.IR.SymPrim.Data.Prim.PartialEval.Bool
( pevalAndTerm,
pevalImplyTerm,
Expand Down Expand Up @@ -104,3 +105,15 @@ instance LogicalOp SymBool where
symNot (SymBool v) = SymBool $ pevalNotTerm v
(SymBool l) `symXor` (SymBool r) = SymBool $ pevalXorTerm l r
(SymBool l) `symImplies` (SymBool r) = SymBool $ pevalImplyTerm l r

instance (LogicalOp a) => LogicalOp (Const a b) where
(.||) (Const a) (Const b) = Const $ a .|| b
{-# INLINE (.||) #-}
(.&&) (Const a) (Const b) = Const $ a .&& b
{-# INLINE (.&&) #-}
symNot (Const a) = Const $ symNot a
{-# INLINE symNot #-}
symXor (Const a) (Const b) = Const $ symXor a b
{-# INLINE symXor #-}
symImplies (Const a) (Const b) = Const $ symImplies a b
{-# INLINE symImplies #-}
12 changes: 12 additions & 0 deletions src/Grisette/Core/Data/Class/Mergeable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import Data.Functor.Classes
eq1,
showsPrec1,
)
import Data.Functor.Const (Const (Const, getConst))
import Data.Functor.Sum (Sum (InL, InR))
import Data.Int (Int16, Int32, Int64, Int8)
import Data.Kind (Type)
Expand Down Expand Up @@ -1038,3 +1039,14 @@ instance (Mergeable' a, Mergeable' b) => Mergeable' (a :+: b) where
else wrapStrategy rootStrategy' R1 (\case (R1 v) -> v; _ -> undefined)
)
{-# INLINE rootStrategy' #-}

deriving via
(Default (Const a b))
instance
(Mergeable a) => Mergeable (Const a b)

deriving via (Default1 (Const a)) instance (Mergeable a) => Mergeable1 (Const a)

instance Mergeable2 Const where
liftRootStrategy2 sa _ = wrapStrategy sa Const getConst
{-# INLINE liftRootStrategy2 #-}
6 changes: 6 additions & 0 deletions src/Grisette/Core/Data/Class/SEq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Control.Monad.Trans.Maybe (MaybeT (MaybeT))
import qualified Control.Monad.Writer.Lazy as WriterLazy
import qualified Control.Monad.Writer.Strict as WriterStrict
import qualified Data.ByteString as B
import Data.Functor.Const (Const)
import Data.Functor.Sum (Sum)
import Data.Int (Int16, Int32, Int64, Int8)
import qualified Data.Text as T
Expand Down Expand Up @@ -282,3 +283,8 @@ instance (SEq' a, SEq' b) => SEq' (a :*: b) where
instance (Generic a, SEq' (Rep a)) => SEq (Default a) where
Default l .== Default r = from l ..== from r
{-# INLINE (.==) #-}

deriving via
(Default (Const a b))
instance
(SEq a) => SEq (Const a b)
14 changes: 14 additions & 0 deletions src/Grisette/Core/Data/Class/SOrd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import Control.Monad.Trans.Maybe (MaybeT (MaybeT))
import qualified Control.Monad.Writer.Lazy as WriterLazy
import qualified Control.Monad.Writer.Strict as WriterStrict
import qualified Data.ByteString as B
import Data.Functor.Const (Const (Const))
import Data.Functor.Sum (Sum)
import Data.Int (Int16, Int32, Int64, Int8)
import qualified Data.Text as T
Expand Down Expand Up @@ -390,6 +391,19 @@ instance (SOrd a, Mergeable a) => SOrd (UnionM a) where
y1 <- tryMerge y
x1 `symCompare` y1

-- | Const
instance (SOrd a) => SOrd (Const a b) where
(Const l) .<= (Const r) = l .<= r
{-# INLINE (.<=) #-}
(Const l) .< (Const r) = l .< r
{-# INLINE (.<) #-}
(Const l) .>= (Const r) = l .>= r
{-# INLINE (.>=) #-}
(Const l) .> (Const r) = l .> r
{-# INLINE (.>) #-}
(Const l) `symCompare` (Const r) = l `symCompare` r
{-# INLINE symCompare #-}

-- | Auxiliary class for 'SOrd' instance derivation
class (SEq' f) => SOrd' f where
-- | Auxiliary function for '(..<) derivation
Expand Down
19 changes: 19 additions & 0 deletions src/Grisette/Core/Data/Class/SafeDivision.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ where

import Control.Exception (ArithException (DivideByZero, Overflow, Underflow))
import Control.Monad.Except (MonadError (throwError))
import Data.Functor.Const (Const (Const))
import Data.Int (Int16, Int32, Int64, Int8)
import Data.Word (Word16, Word32, Word64, Word8)
import GHC.TypeNats (KnownNat, type (<=))
Expand Down Expand Up @@ -290,3 +291,21 @@ instance
SAFE_DIVISION_SYMBOLIC_FUNC2(safeDivMod, SymWordN, pevalDivIntegralTerm, pevalModIntegralTerm)
SAFE_DIVISION_SYMBOLIC_FUNC2(safeQuotRem, SymWordN, pevalQuotIntegralTerm, pevalRemIntegralTerm)
#endif

instance (SafeDivision e a m) => SafeDivision e (Const a b) m where
safeDiv (Const c) (Const r) = mrgFmap Const $ safeDiv c r
{-# INLINE safeDiv #-}
safeMod (Const c) (Const r) = mrgFmap Const $ safeMod c r
{-# INLINE safeMod #-}
safeDivMod (Const c) (Const r) = do
(d, m) <- safeDivMod c r
mrgReturn (Const d, Const m)
{-# INLINE safeDivMod #-}
safeQuot (Const c) (Const r) = mrgFmap Const $ safeQuot c r
{-# INLINE safeQuot #-}
safeRem (Const c) (Const r) = mrgFmap Const $ safeRem c r
{-# INLINE safeRem #-}
safeQuotRem (Const c) (Const r) = do
(q, m) <- safeQuotRem c r
mrgReturn (Const q, Const m)
{-# INLINE safeQuotRem #-}
11 changes: 10 additions & 1 deletion src/Grisette/Core/Data/Class/SafeLinearArith.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ where

import Control.Exception (ArithException (DivideByZero, Overflow, Underflow))
import Control.Monad.Except (MonadError (throwError))
import Data.Functor.Const (Const (Const))
import Data.Int (Int16, Int32, Int64, Int8)
import Data.Word (Word16, Word32, Word64, Word8)
import GHC.TypeNats (KnownNat, type (<=))
Expand Down Expand Up @@ -53,7 +54,7 @@ import Grisette.IR.SymPrim.Data.SymPrim
SymInteger,
SymWordN,
)
import Grisette.Lib.Control.Monad (mrgReturn)
import Grisette.Lib.Control.Monad (mrgFmap, mrgReturn)
import Grisette.Lib.Control.Monad.Except (mrgThrowError)

-- $setup
Expand Down Expand Up @@ -224,3 +225,11 @@ instance
(mrgSingle res)
where
res = ls - rs

instance (SafeLinearArith e a m) => SafeLinearArith e (Const a b) m where
safeAdd (Const a) (Const b) = mrgFmap Const $ safeAdd a b
{-# INLINE safeAdd #-}
safeNeg (Const a) = mrgFmap Const $ safeNeg a
{-# INLINE safeNeg #-}
safeSub (Const a) (Const b) = mrgFmap Const $ safeSub a b
{-# INLINE safeSub #-}
Loading