Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3956 branching on complete conditions in Booster #4058

Merged
merged 51 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1004d23
Add integration tests from #3960
geo2a Sep 24, 2024
896d469
Make checkRequires return SMT-unknown conditions
geo2a Sep 25, 2024
d9ca0bd
Refactor state in RewriteT, add remainder predicates
geo2a Sep 25, 2024
73d743f
Attach rules to their application result outside applyRule
geo2a Oct 7, 2024
efba017
Remove outdated comment
geo2a Oct 7, 2024
94c3a73
Remove redundant argument of processGroups
geo2a Oct 7, 2024
9997ef9
Simplify RewriteRuleAppT monad transformer
geo2a Oct 7, 2024
8d07b37
Refactor applyRule in preparation for remainders
geo2a Oct 7, 2024
9cbd75d
Disable rule remainder-related integration tests
geo2a Oct 7, 2024
2eae60d
Further towards remainders
geo2a Oct 8, 2024
9d2f597
Account for incomplete rules
geo2a Oct 8, 2024
cda1ba0
Include rule predicate into branching response
geo2a Oct 9, 2024
282958e
Add logs of unsat remainders
geo2a Oct 9, 2024
24837f3
Clean-up
geo2a Oct 9, 2024
5255973
Do not abort on Branching by default
geo2a Oct 9, 2024
f1f93c6
Simplify rule predicates
geo2a Oct 10, 2024
6805ddf
Update remainders integration test for booster-dev
geo2a Oct 14, 2024
bfd9fe1
Add kore-rpc-booster results for test-remainder-predicates
geo2a Oct 14, 2024
384dfe5
Enable test-remainder-predicates
geo2a Oct 14, 2024
0e34472
Enable test-use-path-condition-in-equations
geo2a Oct 14, 2024
9107dc8
Adapt test-issue3764-vacuous-branch and test-3934-smt
geo2a Oct 14, 2024
86e5945
hlint and remove dead code
geo2a Oct 15, 2024
0376c8a
"Fix" unit tests by ignoring rule predicate and substitution
geo2a Oct 15, 2024
ecec60d
Remove spurious kore definition file
geo2a Oct 23, 2024
a110031
Update integration test outputs
geo2a Oct 23, 2024
3b572ee
Include "rule-substitution" field into the "branching" execute response
geo2a Oct 23, 2024
65f7e0b
update integration test outputs
geo2a Oct 23, 2024
1261b67
Demote Abort log to Warn
geo2a Oct 23, 2024
f063d83
Fix haddock
geo2a Oct 23, 2024
02ce999
Special-case one of the responses for booster-dev
geo2a Oct 24, 2024
b579e74
Introduce RewriteRuleAppliedData and RewriteGroupApplicationData
geo2a Oct 24, 2024
c52c5f5
Factor-out applyRuleGroup, add comments
geo2a Oct 24, 2024
7d7267e
Revert "Do not abort on Branching by default"
geo2a Oct 24, 2024
8b5991c
Refactor remainder check into a function
geo2a Oct 25, 2024
605ef06
Assert unsatisfiable remainder
geo2a Oct 25, 2024
8ce4dbd
Rename stuff, add more logging
geo2a Oct 25, 2024
d1b1f5e
Update integration tests
geo2a Oct 25, 2024
2d262cc
Introduce RewriteBranchNextState
geo2a Oct 25, 2024
36419fa
Tweak comments
geo2a Oct 25, 2024
c09ab2f
Return rulePredicate in the non-unclear case
geo2a Oct 25, 2024
773c953
Add remainder comment
geo2a Oct 25, 2024
8d2606e
Remove spurious pretty files
geo2a Oct 25, 2024
691f19c
Explicitly guard against non-empty remainder after applying zero rules
geo2a Oct 28, 2024
cb22130
Use the pattern sort for rule substitution
geo2a Oct 28, 2024
3baaa82
Allow setting feature server options in performance-tests-kontrol.sh
geo2a Oct 28, 2024
74f9e80
Introduce AppliedRuleMetadata
geo2a Oct 28, 2024
16efd5e
Update remainder-predicates.k
geo2a Oct 28, 2024
89e5f23
Change remainder trace message
geo2a Oct 29, 2024
5db7f3c
Eliminate redundant coerce calls
geo2a Oct 29, 2024
9b41239
Fix typos, add link
geo2a Oct 29, 2024
ff89457
Do not ignore rule substitution and predicate in unit tests
geo2a Oct 29, 2024
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
82 changes: 53 additions & 29 deletions booster/library/Booster/JsonRpc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import Control.Monad
import Control.Monad.IO.Class
import Control.Monad.Trans.Except (catchE, except, runExcept, runExceptT, throwE, withExceptT)
import Crypto.Hash (SHA256 (..), hashWith)
import Data.Bifunctor (second)
import Data.Bifunctor (first, second)
import Data.Foldable
import Data.List (singleton)
import Data.Map.Strict (Map)
Expand All @@ -38,7 +38,7 @@ import GHC.Records
import Numeric.Natural

import Booster.CLOptions (RewriteOptions (..))
import Booster.Definition.Attributes.Base (UniqueId, getUniqueId, uniqueId)
import Booster.Definition.Attributes.Base (getUniqueId, uniqueId)
import Booster.Definition.Base (KoreDefinition (..))
import Booster.Definition.Base qualified as Definition (RewriteRule (..))
import Booster.LLVM as LLVM (API)
Expand All @@ -49,6 +49,7 @@ import Booster.Pattern.Base qualified as Pattern
import Booster.Pattern.Implies (runImplies)
import Booster.Pattern.Pretty
import Booster.Pattern.Rewrite (
AppliedRuleMetadata (..),
RewriteConfig (..),
RewriteFailed (..),
RewriteResult (..),
Expand All @@ -57,7 +58,9 @@ import Booster.Pattern.Rewrite (
)
import Booster.Pattern.Substitution qualified as Substitution
import Booster.Pattern.Util (
externaliseRuleMarker,
freeVariables,
modifyVarName,
sortOfPattern,
sortOfTerm,
)
Expand Down Expand Up @@ -479,11 +482,13 @@ execResponse req (d, traces, rr) unsupported = case rr of
{ reason = RpcTypes.Branching
, depth
, logs
, state = toExecState p unsupported Nothing
, state = toExecState p Nothing unsupported
, nextStates =
Just $
map (\(_, muid, p') -> toExecState p' unsupported (Just muid)) $
toList nexts
Just
$ map
( \(rewritten, ruleMetadata) -> toExecState rewritten (Just ruleMetadata) unsupported
)
$ toList nexts
, rule = Nothing
, unknownPredicate = Nothing
}
Expand All @@ -494,7 +499,7 @@ execResponse req (d, traces, rr) unsupported = case rr of
{ reason = RpcTypes.Stuck
, depth
, logs
, state = toExecState p unsupported Nothing
, state = toExecState p Nothing unsupported
, nextStates = Nothing
, rule = Nothing
, unknownPredicate = Nothing
Expand All @@ -506,7 +511,7 @@ execResponse req (d, traces, rr) unsupported = case rr of
{ reason = RpcTypes.Vacuous
, depth
, logs
, state = toExecState p unsupported Nothing
, state = toExecState p Nothing unsupported
, nextStates = Nothing
, rule = Nothing
, unknownPredicate = Nothing
Expand All @@ -518,8 +523,8 @@ execResponse req (d, traces, rr) unsupported = case rr of
{ reason = RpcTypes.CutPointRule
, depth
, logs
, state = toExecState p unsupported Nothing
, nextStates = Just [toExecState next unsupported Nothing]
, state = toExecState p Nothing unsupported
, nextStates = Just [toExecState next Nothing unsupported]
, rule = Just lbl
, unknownPredicate = Nothing
}
Expand All @@ -530,7 +535,7 @@ execResponse req (d, traces, rr) unsupported = case rr of
{ reason = RpcTypes.TerminalRule
, depth
, logs
, state = toExecState p unsupported Nothing
, state = toExecState p Nothing unsupported
, nextStates = Nothing
, rule = Just lbl
, unknownPredicate = Nothing
Expand All @@ -542,7 +547,7 @@ execResponse req (d, traces, rr) unsupported = case rr of
{ reason = RpcTypes.DepthBound
, depth
, logs
, state = toExecState p unsupported Nothing
, state = toExecState p Nothing unsupported
, nextStates = Nothing
, rule = Nothing
, unknownPredicate = Nothing
Expand All @@ -559,7 +564,7 @@ execResponse req (d, traces, rr) unsupported = case rr of
(logSuccessfulRewrites, logFailedRewrites)
(RewriteStepFailed failure)
in logs <|> abortRewriteLog
, state = toExecState p unsupported Nothing
, state = toExecState p Nothing unsupported
, nextStates = Nothing
, rule = Nothing
, unknownPredicate = Nothing
Expand All @@ -582,23 +587,37 @@ execResponse req (d, traces, rr) unsupported = case rr of
xs@(_ : _) -> Just xs

toExecState ::
Pattern -> [Syntax.KorePattern] -> Maybe UniqueId -> RpcTypes.ExecuteState
toExecState pat unsupported muid =
Pattern ->
Maybe AppliedRuleMetadata ->
[Syntax.KorePattern] ->
RpcTypes.ExecuteState
{ term = addHeader t
, predicate = addHeader <$> addUnsupported p
, substitution = addHeader <$> s
, ruleSubstitution = Nothing
, rulePredicate = Nothing
, ruleId = getUniqueId <$> muid
}
where
(t, p, s) = externalisePattern pat
termSort = externaliseSort $ sortOfPattern pat
allUnsupported = Syntax.KJAnd termSort unsupported
addUnsupported
| null unsupported = id
| otherwise = maybe (Just allUnsupported) (Just . Syntax.KJAnd termSort . (: unsupported))
toExecState
pat
mRuleMetadata
unsupported =
RpcTypes.ExecuteState
{ term = addHeader t
, predicate = addHeader <$> addUnsupported p
, substitution = addHeader <$> s
, ruleSubstitution = addHeader <$> mruleSubstExt
, rulePredicate = addHeader <$> mrulePredExt
, ruleId = getUniqueId . ruleUniqueId <$> mRuleMetadata
}
where
mrulePredExt = externalisePredicate termSort . rulePredicate <$> mRuleMetadata
mruleSubstExt =
Syntax.KJAnd termSort
. map
(uncurry (externaliseSubstitution termSort) . first (modifyVarName externaliseRuleMarker))
. Map.toList
. ruleSubstitution
<$> mRuleMetadata
(t, p, s) = externalisePattern pat
termSort = externaliseSort $ sortOfPattern pat
allUnsupported = Syntax.KJAnd termSort unsupported
addUnsupported
| null unsupported = id
| otherwise = maybe (Just allUnsupported) (Just . Syntax.KJAnd termSort . (: unsupported))

mkLogRewriteTrace ::
(Bool, Bool) ->
Expand Down Expand Up @@ -639,6 +658,11 @@ mkLogRewriteTrace
{ reason = "Uncertain about a condition in rule"
, _ruleId = Just $ getUniqueId (uniqueId $ Definition.attributes r)
}
RewriteRemainderPredicate rs _ _ ->
Failure
{ reason = "Uncertain about a condition in rule"
geo2a marked this conversation as resolved.
Show resolved Hide resolved
, _ruleId = Just $ getUniqueId (uniqueId $ Definition.attributes (head rs))
}
DefinednessUnclear r _ undefReasons ->
Failure
{ reason = "Uncertain about definedness of rule because of: " <> pack (show undefReasons)
Expand Down
11 changes: 11 additions & 0 deletions booster/library/Booster/Pattern/Bool.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ License : BSD-3-Clause
module Booster.Pattern.Bool (
foldAndBool,
isBottom,
isFalse,
negateBool,
splitBoolPredicates,
splitAndBools,
collapseAndBools,
-- patterns
pattern TrueBool,
pattern FalseBool,
Expand Down Expand Up @@ -188,6 +190,11 @@ foldAndBool (x : xs) = AndBool x $ foldAndBool xs
isBottom :: Pattern -> Bool
isBottom = (Predicate FalseBool `elem`) . constraints

isFalse :: Predicate -> Bool
isFalse = \case
(Predicate FalseBool) -> True
_ -> False

{- | We want to break apart predicates of type `Y1 andBool ... Yn` apart, in case some of the `Y`s are abstract
which prevents the original expression from being fed to the LLVM simplifyBool function
-}
Expand All @@ -205,3 +212,7 @@ splitAndBools :: Predicate -> [Predicate]
splitAndBools p@(Predicate t)
| AndBool l r <- t = concatMap (splitAndBools . Predicate) [l, r]
| otherwise = [p]

-- | Inverse of splitAndBools
collapseAndBools :: [Predicate] -> Predicate
collapseAndBools = Predicate . foldAndBool . map (\(Predicate p) -> p)
Loading
Loading