Skip to content

Commit 1bbcad4

Browse files
committed
Remove a variety of panic cases in the saw-core simulator primitives.
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.
1 parent cb59fc6 commit 1bbcad4

File tree

8 files changed

+149
-111
lines changed

8 files changed

+149
-111
lines changed

saw-core-aig/src/Verifier/SAW/Simulator/BitBlast.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ pure3 f x y z = pure (f x y z)
170170
prims :: AIG.IsAIG l g => g s -> Prims.BasePrims (BitBlast (l s))
171171
prims be =
172172
Prims.BasePrims
173-
{ Prims.bpAsBool = AIG.asConstant be
173+
{ Prims.bpIsSymbolicEvaluator = True
174+
, Prims.bpAsBool = AIG.asConstant be
174175
-- Bitvectors
175176
, Prims.bpUnpack = pure1 vFromLV
176177
, Prims.bpPack = pure1 lvFromV

saw-core-sbv/src/Verifier/SAW/Simulator/SBV.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ pure3 f x y z = pure (f x y z)
105105
prims :: Prims.BasePrims SBV
106106
prims =
107107
Prims.BasePrims
108-
{ Prims.bpAsBool = svAsBool
108+
{ Prims.bpIsSymbolicEvaluator = True
109+
, Prims.bpAsBool = svAsBool
109110
, Prims.bpUnpack = svUnpack
110111
, Prims.bpPack = pure1 symFromBits
111112
, Prims.bpBvAt = pure2 svAt

saw-core-what4/src/Verifier/SAW/Simulator/What4.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ prims :: forall sym.
161161
Sym sym => sym -> Prims.BasePrims (What4 sym)
162162
prims sym =
163163
Prims.BasePrims
164-
{ Prims.bpAsBool = W.asConstantPred
164+
{ Prims.bpIsSymbolicEvaluator = True
165+
, Prims.bpAsBool = W.asConstantPred
165166
-- Bitvectors
166167
, Prims.bpUnpack = SW.bvUnpackBE sym
167168
, Prims.bpPack = SW.bvPackBE sym

saw-core/src/Verifier/SAW/Simulator.hs

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import Prelude hiding (mapM)
3535
import Control.Applicative ((<$>))
3636
#endif
3737
import Control.Monad (foldM, liftM)
38-
--import Control.Monad.IO.Class
38+
import Control.Monad.Trans.Except
3939
import Control.Monad.Trans.Maybe
4040
import Control.Monad.Fix (MonadFix(mfix))
4141
import Control.Monad.Identity (Identity)
@@ -624,6 +624,11 @@ evalPrim fallback pn = loop [] (primType pn)
624624
Just v -> loop ((ready x',t):env) tp' (f v)
625625
_ -> fallback msg ((ready x',t):env) tp'
626626

627+
loop env tp (Prims.PrimExcept m) =
628+
runExceptT m >>= \case
629+
Right v -> pure v
630+
Left msg -> fallback msg env tp
631+
627632
loop _env _tp (Prims.Prim m) = m
628633
loop _env _tp (Prims.PrimValue v) = pure v
629634

saw-core/src/Verifier/SAW/Simulator/Concrete.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ ite b x y = if b then x else y
132132
prims :: Prims.BasePrims Concrete
133133
prims =
134134
Prims.BasePrims
135-
{ Prims.bpAsBool = Just
135+
{ Prims.bpIsSymbolicEvaluator = False
136+
, Prims.bpAsBool = Just
136137
, Prims.bpUnpack = pure1 Prim.unpackBitVector
137138
, Prims.bpPack = pure1 Prim.packBitVector
138139
, Prims.bpBvAt = pure2 Prim.bvAt

0 commit comments

Comments
 (0)