Skip to content

Commit

Permalink
Remove a variety of panic cases in the saw-core simulator primitives.
Browse files Browse the repository at this point in the history
Also, add a switch that controls if the evalutor will be have in
a "symbolic" way.

Adding a new `PrimExcept` constructor that allows primitives to
cause fallback behavior after examining all their arguments.
As with the existing `PrimFilterFun`, this causes term reconstruction
in the term model evaluator, and raises an error in the other evaluators.
We use this new type of primitive to remove cases that would otherwise
panic.

In addition, we add a flag to the `BasePrims` record that controls
if we do symbolic muxing for sequence operations and `ite`. For the
term model, we disable this behavior and fall back earlier on term
reconstruction. This avoids constructing large mux trees in some cases.
  • Loading branch information
robdockins committed Jul 2, 2021
1 parent cb59fc6 commit 1bbcad4
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 111 deletions.
3 changes: 2 additions & 1 deletion saw-core-aig/src/Verifier/SAW/Simulator/BitBlast.hs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ pure3 f x y z = pure (f x y z)
prims :: AIG.IsAIG l g => g s -> Prims.BasePrims (BitBlast (l s))
prims be =
Prims.BasePrims
{ Prims.bpAsBool = AIG.asConstant be
{ Prims.bpIsSymbolicEvaluator = True
, Prims.bpAsBool = AIG.asConstant be
-- Bitvectors
, Prims.bpUnpack = pure1 vFromLV
, Prims.bpPack = pure1 lvFromV
Expand Down
3 changes: 2 additions & 1 deletion saw-core-sbv/src/Verifier/SAW/Simulator/SBV.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ pure3 f x y z = pure (f x y z)
prims :: Prims.BasePrims SBV
prims =
Prims.BasePrims
{ Prims.bpAsBool = svAsBool
{ Prims.bpIsSymbolicEvaluator = True
, Prims.bpAsBool = svAsBool
, Prims.bpUnpack = svUnpack
, Prims.bpPack = pure1 symFromBits
, Prims.bpBvAt = pure2 svAt
Expand Down
3 changes: 2 additions & 1 deletion saw-core-what4/src/Verifier/SAW/Simulator/What4.hs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ prims :: forall sym.
Sym sym => sym -> Prims.BasePrims (What4 sym)
prims sym =
Prims.BasePrims
{ Prims.bpAsBool = W.asConstantPred
{ Prims.bpIsSymbolicEvaluator = True
, Prims.bpAsBool = W.asConstantPred
-- Bitvectors
, Prims.bpUnpack = SW.bvUnpackBE sym
, Prims.bpPack = SW.bvPackBE sym
Expand Down
7 changes: 6 additions & 1 deletion saw-core/src/Verifier/SAW/Simulator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import Prelude hiding (mapM)
import Control.Applicative ((<$>))
#endif
import Control.Monad (foldM, liftM)
--import Control.Monad.IO.Class
import Control.Monad.Trans.Except
import Control.Monad.Trans.Maybe
import Control.Monad.Fix (MonadFix(mfix))
import Control.Monad.Identity (Identity)
Expand Down Expand Up @@ -624,6 +624,11 @@ evalPrim fallback pn = loop [] (primType pn)
Just v -> loop ((ready x',t):env) tp' (f v)
_ -> fallback msg ((ready x',t):env) tp'

loop env tp (Prims.PrimExcept m) =
runExceptT m >>= \case
Right v -> pure v
Left msg -> fallback msg env tp

loop _env _tp (Prims.Prim m) = m
loop _env _tp (Prims.PrimValue v) = pure v

Expand Down
3 changes: 2 additions & 1 deletion saw-core/src/Verifier/SAW/Simulator/Concrete.hs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ ite b x y = if b then x else y
prims :: Prims.BasePrims Concrete
prims =
Prims.BasePrims
{ Prims.bpAsBool = Just
{ Prims.bpIsSymbolicEvaluator = False
, Prims.bpAsBool = Just
, Prims.bpUnpack = pure1 Prim.unpackBitVector
, Prims.bpPack = pure1 Prim.packBitVector
, Prims.bpBvAt = pure2 Prim.bvAt
Expand Down
Loading

0 comments on commit 1bbcad4

Please sign in to comment.