Skip to content

Commit

Permalink
Apply simplification step before printing out final equivalence condi…
Browse files Browse the repository at this point in the history
…tions
  • Loading branch information
danmatichuk committed Feb 29, 2024
1 parent 2eca343 commit 97e0c2e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
12 changes: 12 additions & 0 deletions src/Pate/Verification/Simplify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Pate.Verification.Simplify (
, applySimplifier
, runSimplifier
, getSimplifier
, deepPredicateSimplifier
) where

import Control.Monad (foldM)
Expand Down Expand Up @@ -218,6 +219,17 @@ applySimplifier simplifier v = withSym $ \sym -> do
True -> withTracing @"debug_tree" "Simplifier" $ PEM.mapExpr sym (runSimplifier simplifier) v
False -> withNoTracing $ PEM.mapExpr sym (runSimplifier simplifier) v

deepPredicateSimplifier :: forall sym arch. EquivM sym arch (Simplifier sym arch)
deepPredicateSimplifier = withSym $ \sym -> do
Simplifier f <- getSimplifier
return $ Simplifier $ \e0 -> do
e1 <- liftIO $ WEH.stripAnnotations sym e0
e2 <- f e1
e4 <- case W4.exprType e0 of
W4.BaseBoolRepr -> simplifyPred_deep e2
_ -> return e2
applyCurrentAsms e4

getSimplifier :: forall sym arch. EquivM sym arch (Simplifier sym arch)
getSimplifier = withSym $ \sym -> do
heuristicTimeout <- CMR.asks (PC.cfgHeuristicTimeout . envConfig)
Expand Down
9 changes: 6 additions & 3 deletions src/Pate/Verification/StrongestPosts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -854,12 +854,15 @@ showFinalResult pg = withTracing @"final_result" () $ withSym $ \sym -> do
subTrace (GraphNode nd) $
emitTrace @"observable_result" (CE.ObservableCheckCounterexample report)
subTree @"node" "Assumed Equivalence Conditions" $ do
simplifier <- lift $ PSi.deepPredicateSimplifier
forM_ (getAllNodes pg) $ \nd -> do
case getCondition pg nd ConditionEquiv of
Just{} -> subTrace nd $ do
Just cond_spec -> subTrace nd $ do
_ <- withFreshScope (graphNodeBlocks nd) $ \scope -> do
-- 'withConditionsAssumed' emits the expected tracing info here
_ <- withGraphNode scope nd pg $ \_ _ -> return pg
(_,cond) <- IO.liftIO $ PS.bindSpec sym (PS.scopeVarsPair scope) cond_spec
cond_simplified <- PSi.applySimplifier simplifier cond
let pg' = setCondition nd ConditionEquiv PropagateNone (PS.mkSimSpec scope cond_simplified) pg
_ <- withGraphNode scope nd pg' $ \_ _ -> return pg
return $ (Const ())
return ()
Nothing -> return ()
Expand Down
12 changes: 4 additions & 8 deletions src/Pate/Verification/Widening.hs
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,12 @@ addRefinementChoice nd gr0 = withTracing @"message" "Modify Proof Node" $ do
emitTrace @"message" (conditionName condK ++ " Discharged")
return Nothing
False -> do
simplifier <- PSi.getSimplifier
simplifier <- PSi.deepPredicateSimplifier
curAsm <- currentAsm
emitTrace @"assumption" curAsm
eqCond_pred1 <- liftIO $ WEH.stripAnnotations sym eqCond_pred
eqCond_pred2 <- PSi.applySimplifier simplifier eqCond_pred1
eqCond_pred3 <- PSi.simplifyPred_deep eqCond_pred2
eqCond_pred4 <- applyCurrentAsms eqCond_pred3

emitTraceLabel @"expr" (ExprLabel $ "Simplified " ++ conditionName condK) (Some eqCond_pred4)
return $ Just eqCond_pred4
eqCond_pred_simp <- PSi.applySimplifier simplifier eqCond_pred
emitTraceLabel @"expr" (ExprLabel $ "Simplified " ++ conditionName condK) (Some eqCond_pred_simp)
return $ Just eqCond_pred_simp
case meqCond_pred' of
Nothing -> return $ dropCondition nd condK gr0_
Just eqCond_pred' -> do
Expand Down

0 comments on commit 97e0c2e

Please sign in to comment.