-
Notifications
You must be signed in to change notification settings - Fork 44
Consider known predicates in Booster's simplifier API #3953
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9afbc46
Add known predicates to simplifier API
geo2a 3170762
Actually use the patterns constraints
geo2a a2f86a9
Merge remote-tracking branch 'origin/master' into georgy/check-constr…
geo2a 1e56d5c
Add integration tests
geo2a 7e87f2c
Typos
geo2a 93658a8
Only run test-use-path-condition-in-equations with booster-dev
geo2a cfb80b5
Merge branch 'master' into georgy/check-constraint-with-known
rv-jenkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,7 @@ computeCeilRule :: | |
computeCeilRule mllvm def [email protected]{lhs, requires, rhs, attributes, computedAttributes} | ||
| null computedAttributes.notPreservesDefinednessReasons = pure Nothing | ||
| otherwise = do | ||
(res, _) <- runEquationT def mllvm Nothing mempty $ do | ||
(res, _) <- runEquationT def mllvm Nothing mempty mempty $ do | ||
lhsCeils <- Set.fromList <$> computeCeil lhs | ||
requiresCeils <- Set.fromList <$> concatMapM (computeCeil . coerce) (Set.toList requires) | ||
let subtractLHSAndRequiresCeils = (Set.\\ (lhsCeils `Set.union` requiresCeils)) . Set.fromList | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -353,7 +353,7 @@ applyRule pat@Pattern{ceilConditions} rule = | |||||
<+> (hsep . punctuate comma . map (pretty' @mods) $ knownTrue) | ||||||
|
||||||
unclearRequires <- | ||||||
catMaybes <$> mapM (checkConstraint id notAppliedIfBottom) toCheck | ||||||
catMaybes <$> mapM (checkConstraint id notAppliedIfBottom prior) toCheck | ||||||
|
||||||
-- check unclear requires-clauses in the context of known constraints (prior) | ||||||
mbSolver <- lift $ RewriteT $ (.smtSolver) <$> ask | ||||||
|
@@ -403,7 +403,7 @@ applyRule pat@Pattern{ceilConditions} rule = | |||||
Set.toList rule.ensures | ||||||
trivialIfBottom = RewriteRuleAppT $ pure Trivial | ||||||
newConstraints <- | ||||||
catMaybes <$> mapM (checkConstraint id trivialIfBottom) ruleEnsures | ||||||
catMaybes <$> mapM (checkConstraint id trivialIfBottom prior) ruleEnsures | ||||||
|
||||||
-- check all new constraints together with the known side constraints | ||||||
whenJust mbSolver $ \solver -> | ||||||
|
@@ -450,17 +450,17 @@ applyRule pat@Pattern{ceilConditions} rule = | |||||
checkConstraint :: | ||||||
(Predicate -> a) -> | ||||||
RewriteRuleAppT (RewriteT io) (Maybe a) -> | ||||||
Set.Set Predicate -> | ||||||
Predicate -> | ||||||
RewriteRuleAppT (RewriteT io) (Maybe a) | ||||||
checkConstraint onUnclear onBottom p = do | ||||||
checkConstraint onUnclear onBottom knownPredicates p = do | ||||||
RewriteConfig{definition, llvmApi, smtSolver} <- lift $ RewriteT ask | ||||||
oldCache <- lift . RewriteT . lift $ get | ||||||
(simplified, cache) <- | ||||||
withContext CtxConstraint $ | ||||||
simplifyConstraint definition llvmApi smtSolver oldCache p | ||||||
simplifyConstraint definition llvmApi smtSolver oldCache knownPredicates p | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned, one could just use
Suggested change
|
||||||
-- update cache | ||||||
lift . RewriteT . lift . modify $ const cache | ||||||
-- TODO should we keep the traces? Or only on success? | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚮 |
||||||
case simplified of | ||||||
Right (Predicate FalseBool) -> onBottom | ||||||
Right (Predicate TrueBool) -> pure Nothing | ||||||
|
54 changes: 54 additions & 0 deletions
54
booster/test/rpc-integration/resources/use-path-condition-in-equations.k
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module USE-PATH-CONDITION-IN-EQUATIONS | ||
imports INT | ||
imports BOOL | ||
|
||
syntax State ::= test1Init() | ||
| test1State1() | ||
| test1State2() | ||
|
||
| test2Init() | ||
| test2State1() | ||
| test2State2() | ||
|
||
syntax Int ::= test1F ( Int ) [function, total, no-evaluators] | ||
| test2F ( Int ) [function, total, no-evaluators] | ||
|
||
configuration <k> $PGM:State ~> .K </k> | ||
<int> 0:Int </int> | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Here the simplification's side condition is syntactically present // | ||
// in the path condition and is not checked. // | ||
// Result: Stuck at depth 2 in state test1State2() // | ||
// after applying rules test1-init,test1-1-2 // | ||
//////////////////////////////////////////////////////////////////////////////// | ||
rule [test1-init]: <k> test1Init() => test1State1() ... </k> | ||
<int> _ => ?X </int> | ||
ensures ?X ==Int 42 | ||
|
||
rule [test1-1-2]: <k> test1State1() => test1State2() ... </k> | ||
<int> X </int> | ||
requires test1F(X) >Int 0 | ||
|
||
rule [test1F-simplify]: test1F(X:Int) => X requires X ==Int 42 [simplification] | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
// Here the simplification's side condition is implied by the path condition, // | ||
// but we need an SMT solver to establish that. // | ||
// Result: Aborted at depth 1 due to indeterminate condition of rule test2-1-2 // | ||
//////////////////////////////////////////////////////////////////////////////// | ||
rule [test2-init]: <k> test2Init() => test2State1() ... </k> | ||
<int> _ => ?X </int> | ||
ensures ?X ==Int 42 | ||
|
||
rule [test2-1-2]: <k> test2State1() => test2State2() ... </k> | ||
<int> X </int> | ||
requires test2F(X) >Int 0 | ||
|
||
rule [test2F-simplify]: test2F(X:Int) => X requires X >Int 0 [simplification] | ||
|
||
// to produce input state: | ||
// krun --output kore --depth 1 -cPGM='test1Init()' | kore-parser test-kompiled/definition.kore --module TEST --pattern /dev/stdin --print-pattern-json > state-test1Init.json | ||
// then edit state-test1Init.json to substitute test1State1() for test1Init() | ||
|
||
endmodule |
4 changes: 4 additions & 0 deletions
4
booster/test/rpc-integration/resources/use-path-condition-in-equations.kompile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
echo "kompiling use-path-condition-in-equations.k" | ||
kompile --backend haskell use-path-condition-in-equations.k | ||
cp use-path-condition-in-equations-kompiled/definition.kore use-path-condition-in-equations.kore | ||
rm -r use-path-condition-in-equations-kompiled |
3 changes: 3 additions & 0 deletions
3
booster/test/rpc-integration/test-use-path-condition-in-equations/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Test the use of the known path condition when applying simplifications | ||
|
||
See `../resourses/use-path-condition-in-equations.k`. |
148 changes: 148 additions & 0 deletions
148
booster/test/rpc-integration/test-use-path-condition-in-equations/response-test1.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
{ | ||
"jsonrpc": "2.0", | ||
"id": 1, | ||
"result": { | ||
"reason": "stuck", | ||
"depth": 2, | ||
"state": { | ||
"term": { | ||
"format": "KORE", | ||
"version": 1, | ||
"term": { | ||
"tag": "App", | ||
"name": "Lbl'-LT-'generatedTop'-GT-'", | ||
"sorts": [], | ||
"args": [ | ||
{ | ||
"tag": "App", | ||
"name": "Lbl'-LT-'k'-GT-'", | ||
"sorts": [], | ||
"args": [ | ||
{ | ||
"tag": "App", | ||
"name": "kseq", | ||
"sorts": [], | ||
"args": [ | ||
{ | ||
"tag": "App", | ||
"name": "inj", | ||
"sorts": [ | ||
{ | ||
"tag": "SortApp", | ||
"name": "SortState", | ||
"args": [] | ||
}, | ||
{ | ||
"tag": "SortApp", | ||
"name": "SortKItem", | ||
"args": [] | ||
} | ||
], | ||
"args": [ | ||
{ | ||
"tag": "App", | ||
"name": "Lbltest1State2'LParRParUnds'USE-PATH-CONDITION-IN-EQUATIONS'Unds'State", | ||
"sorts": [], | ||
"args": [] | ||
} | ||
] | ||
}, | ||
{ | ||
"tag": "App", | ||
"name": "dotk", | ||
"sorts": [], | ||
"args": [] | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"tag": "App", | ||
"name": "Lbl'-LT-'int'-GT-'", | ||
"sorts": [], | ||
"args": [ | ||
{ | ||
"tag": "EVar", | ||
"name": "Var'Ques'X", | ||
"sort": { | ||
"tag": "SortApp", | ||
"name": "SortInt", | ||
"args": [] | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"tag": "App", | ||
"name": "Lbl'-LT-'generatedCounter'-GT-'", | ||
"sorts": [], | ||
"args": [ | ||
{ | ||
"tag": "DV", | ||
"sort": { | ||
"tag": "SortApp", | ||
"name": "SortInt", | ||
"args": [] | ||
}, | ||
"value": "0" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
"predicate": { | ||
"format": "KORE", | ||
"version": 1, | ||
"term": { | ||
"tag": "Equals", | ||
"argSort": { | ||
"tag": "SortApp", | ||
"name": "SortBool", | ||
"args": [] | ||
}, | ||
"sort": { | ||
"tag": "SortApp", | ||
"name": "SortGeneratedTopCell", | ||
"args": [] | ||
}, | ||
"first": { | ||
"tag": "DV", | ||
"sort": { | ||
"tag": "SortApp", | ||
"name": "SortBool", | ||
"args": [] | ||
}, | ||
"value": "true" | ||
}, | ||
"second": { | ||
"tag": "App", | ||
"name": "Lbl'UndsEqlsEqls'Int'Unds'", | ||
"sorts": [], | ||
"args": [ | ||
{ | ||
"tag": "EVar", | ||
"name": "Var'Ques'X", | ||
"sort": { | ||
"tag": "SortApp", | ||
"name": "SortInt", | ||
"args": [] | ||
} | ||
}, | ||
{ | ||
"tag": "DV", | ||
"sort": { | ||
"tag": "SortApp", | ||
"name": "SortInt", | ||
"args": [] | ||
}, | ||
"value": "42" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should still start empty and push the path condition as the first step.
The code here returns all stored
predicates
as constraints of the pattern (in line 424) which may or may not be correct depending on how the function was called. This is correct for the current use of the function but might not be correct in all future use cases.Alternatively, how about we inline all of
evaluatedPattern'
intoevaluatePattern
(so no mistakes are possible).