Skip to content

Commit

Permalink
Merge pull request #1014 from GaloisInc/issue985
Browse files Browse the repository at this point in the history
Make `goal_eval` preserve pi-bound variables in goals.
  • Loading branch information
brianhuffman authored Jan 22, 2021
2 parents f87988f + 0f045d2 commit 9083eec
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
25 changes: 25 additions & 0 deletions intTests/test_goal_eval/test.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This is a regression test for GaloisInc/saw-script#985.
// It uses `goal_eval` and then calls `goal_intro` to enforce
// that `goal_eval` has preserved the explicit quantifiers in
// the goal.

enable_experimental;

let prop = {{ \(xs:[4][8]) (ys:([8],[8])) -> sum xs == ys.0 * ys.1 }};

prove
do {
goal_intro "z";
assume_unsat;
}
prop;

prove
do {
goal_eval;
goal_intro "z";
assume_unsat;
}
prop;

print "Done";
1 change: 1 addition & 0 deletions intTests/test_goal_eval/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$SAW test.saw
14 changes: 12 additions & 2 deletions src/SAWScript/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -536,13 +536,23 @@ goal_eval unints =
withFirstGoal $ \goal ->
do sc <- getSharedContext
unintSet <- resolveNames unints
t0 <- liftIO $ propToPredicate sc (goalProp goal)
-- replace all pi-bound quantified variables with new free variables
let (args, body) = asPiList (unProp (goalProp goal))
body' <-
case asEqTrue body of
Just t -> pure t
Nothing -> fail "goal_eval: expected EqTrue"
ecs <- liftIO $ traverse (\(nm, ty) -> scFreshEC sc (Text.unpack nm) ty) args
vars <- liftIO $ traverse (scExtCns sc) ecs
t0 <- liftIO $ instantiateVarList sc 0 (reverse vars) body'
let gen = globalNonceGenerator
sym <- liftIO $ Crucible.newSAWCoreBackend FloatRealRepr sc gen
(_names, (_mlabels, p)) <- liftIO $ W4Sim.w4Eval sym sc Map.empty unintSet t0
t1 <- liftIO $ Crucible.toSC sym p
t2 <- liftIO $ scEqTrue sc t1
return ((), mempty, Just (goal { goalProp = Prop t2 }))
-- turn the free variables we generated back into pi-bound variables
t3 <- liftIO $ scGeneralizeExts sc ecs t2
return ((), mempty, Just (goal { goalProp = Prop t3 }))

beta_reduce_goal :: ProofScript ()
beta_reduce_goal =
Expand Down

0 comments on commit 9083eec

Please sign in to comment.