-
Notifications
You must be signed in to change notification settings - Fork 45
4012 evaluate pattern pruning #4020
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
base: master
Are you sure you want to change the base?
Changes from all commits
a313ce8
0c0e203
5999a66
2f75bc2
0de9517
41e93b1
2359ddc
998eb07
598a00c
9c07a05
39e6abc
df4cfae
e155e58
586589f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,11 @@ respond stateVar request = | |
[ req.logSuccessfulRewrites | ||
, req.logFailedRewrites | ||
] | ||
checkConstraintsConsistent = | ||
case req.assumeDefined of | ||
Nothing -> ApplyEquations.CheckConstraintsConsistent | ||
Just False -> ApplyEquations.CheckConstraintsConsistent | ||
Just True -> ApplyEquations.NoCheckConstraintsConsistent | ||
-- apply the given substitution before doing anything else | ||
let substPat = | ||
Pattern | ||
|
@@ -147,26 +152,54 @@ respond stateVar request = | |
|
||
solver <- maybe (SMT.noSolver) (SMT.initSolver def) mSMTOptions | ||
|
||
logger <- getLogger | ||
prettyModifiers <- getPrettyModifiers | ||
let rewriteConfig = | ||
RewriteConfig | ||
{ definition = def | ||
, llvmApi = mLlvmLibrary | ||
, smtSolver = solver | ||
, varsToAvoid = substVars | ||
, doTracing | ||
, logger | ||
, prettyModifiers | ||
, mbMaxDepth = mbDepth | ||
, mbSimplify = rewriteOpts.interimSimplification | ||
, cutLabels = cutPoints | ||
, terminalLabels = terminals | ||
} | ||
result <- | ||
performRewrite rewriteConfig substPat | ||
SMT.finaliseSolver solver | ||
pure $ execResponse req result substitution unsupported | ||
-- check input pattern's consistency before starting rewriting | ||
evaluatedInitialPattern <- | ||
ApplyEquations.evaluatePattern | ||
def | ||
mLlvmLibrary | ||
solver | ||
mempty | ||
checkConstraintsConsistent | ||
substPat | ||
|
||
let trivialResponse = | ||
execResponse | ||
req | ||
(0, mempty, RewriteTrivial substPat) | ||
substitution | ||
unsupported | ||
|
||
case evaluatedInitialPattern of | ||
(Left ApplyEquations.SideConditionFalse{}, _) -> do | ||
-- input pattern's constraints are Bottom, return Vacuous | ||
pure trivialResponse | ||
(Left ApplyEquations.UndefinedTerm{}, _) -> do | ||
-- LLVM has stumbled upon an undefined term, the whole term is Bottom, return Vacuous | ||
pure trivialResponse | ||
(Left other, _) -> | ||
pure . Left . RpcError.backendError $ RpcError.Aborted (Text.pack . constructorName $ other) | ||
(Right newPattern, simplifierCache) -> do | ||
logger <- getLogger | ||
prettyModifiers <- getPrettyModifiers | ||
let rewriteConfig = | ||
RewriteConfig | ||
{ definition = def | ||
, llvmApi = mLlvmLibrary | ||
, smtSolver = solver | ||
, varsToAvoid = substVars | ||
, doTracing | ||
, logger | ||
, prettyModifiers | ||
, mbMaxDepth = mbDepth | ||
, mbSimplify = rewriteOpts.interimSimplification | ||
, cutLabels = cutPoints | ||
, terminalLabels = terminals | ||
} | ||
|
||
result <- | ||
performRewrite rewriteConfig simplifierCache newPattern | ||
SMT.finaliseSolver solver | ||
pure $ execResponse req result substitution unsupported | ||
RpcTypes.AddModule RpcTypes.AddModuleRequest{_module, nameAsId = nameAsId'} -> Booster.Log.withContext CtxAddModule $ runExceptT $ do | ||
-- block other request executions while modifying the server state | ||
state <- liftIO $ takeMVar stateVar | ||
|
@@ -255,21 +288,29 @@ respond stateVar request = | |
, constraints = Set.map (substituteInPredicate substitution) pat.constraints | ||
, ceilConditions = pat.ceilConditions | ||
} | ||
ApplyEquations.evaluatePattern def mLlvmLibrary solver mempty substPat >>= \case | ||
(Right newPattern, _) -> do | ||
let (term, mbPredicate, mbSubstitution) = externalisePattern newPattern substitution | ||
tSort = externaliseSort (sortOfPattern newPattern) | ||
result = case catMaybes (mbPredicate : mbSubstitution : map Just unsupported) of | ||
[] -> term | ||
ps -> KoreJson.KJAnd tSort $ term : ps | ||
pure $ Right (addHeader result) | ||
(Left ApplyEquations.SideConditionFalse{}, _) -> do | ||
let tSort = externaliseSort $ sortOfPattern pat | ||
pure $ Right (addHeader $ KoreJson.KJBottom tSort) | ||
(Left (ApplyEquations.EquationLoop _terms), _) -> | ||
pure . Left . RpcError.backendError $ RpcError.Aborted "equation loop detected" | ||
(Left other, _) -> | ||
pure . Left . RpcError.backendError $ RpcError.Aborted (Text.pack . constructorName $ other) | ||
-- evaluate the pattern, checking the constrains for consistency | ||
ApplyEquations.evaluatePattern | ||
def | ||
mLlvmLibrary | ||
solver | ||
mempty | ||
ApplyEquations.CheckConstraintsConsistent | ||
substPat | ||
>>= \case | ||
(Right newPattern, _) -> do | ||
let (term, mbPredicate, mbSubstitution) = externalisePattern newPattern substitution | ||
tSort = externaliseSort (sortOfPattern newPattern) | ||
result = case catMaybes (mbPredicate : mbSubstitution : map Just unsupported) of | ||
[] -> term | ||
ps -> KoreJson.KJAnd tSort $ term : ps | ||
pure $ Right (addHeader result) | ||
(Left ApplyEquations.SideConditionFalse{}, _) -> do | ||
let tSort = externaliseSort $ sortOfPattern pat | ||
pure $ Right (addHeader $ KoreJson.KJBottom tSort) | ||
Comment on lines
+307
to
+309
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. ...another place where we should probably catch |
||
(Left (ApplyEquations.EquationLoop _terms), _) -> | ||
pure . Left . RpcError.backendError $ RpcError.Aborted "equation loop detected" | ||
(Left other, _) -> | ||
pure . Left . RpcError.backendError $ RpcError.Aborted (Text.pack . constructorName $ other) | ||
-- predicate only | ||
Right (Predicates ps) | ||
| null ps.boolPredicates && null ps.ceilPredicates && null ps.substitution && null ps.unsupported -> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,24 +136,31 @@ runImplies def mLlvmLibrary mSMTOptions antecedent consequent = | |
(externaliseExistTerm existsL substPatL.term) | ||
(externaliseExistTerm existsR substPatR.term) | ||
MatchIndeterminate remainder -> | ||
ApplyEquations.evaluatePattern def mLlvmLibrary solver mempty substPatL >>= \case | ||
(Right simplifedSubstPatL, _) -> | ||
if substPatL == simplifedSubstPatL | ||
then -- we are being conservative here for now and returning an error. | ||
-- since we have already simplified the LHS, we may want to eventually return implise, but the condition | ||
-- will contain the remainder as an equality contraint, predicating the implication on that equality being true. | ||
ApplyEquations.evaluatePattern | ||
def | ||
mLlvmLibrary | ||
solver | ||
mempty | ||
ApplyEquations.CheckConstraintsConsistent | ||
substPatL | ||
>>= \case | ||
(Right simplifedSubstPatL, _) -> | ||
if substPatL == simplifedSubstPatL | ||
then -- we are being conservative here for now and returning an error. | ||
-- since we have already simplified the LHS, we may want to eventually return implise, but the condition | ||
-- will contain the remainder as an equality contraint, predicating the implication on that equality being true. | ||
|
||
pure . Left . RpcError.backendError . RpcError.ImplicationCheckError . RpcError.ErrorOnly . pack $ | ||
"match remainder: " | ||
<> renderDefault | ||
( hsep $ | ||
punctuate comma $ | ||
map (\(t1, t2) -> pretty' @mods t1 <+> "==" <+> pretty' @mods t2) $ | ||
NonEmpty.toList remainder | ||
) | ||
else checkImpliesMatchTerms existsL simplifedSubstPatL existsR substPatR | ||
(Left err, _) -> | ||
pure . Left . RpcError.backendError $ RpcError.Aborted (Text.pack . constructorName $ err) | ||
pure . Left . RpcError.backendError . RpcError.ImplicationCheckError . RpcError.ErrorOnly . pack $ | ||
"match remainder: " | ||
<> renderDefault | ||
( hsep $ | ||
punctuate comma $ | ||
map (\(t1, t2) -> pretty' @mods t1 <+> "==" <+> pretty' @mods t2) $ | ||
NonEmpty.toList remainder | ||
) | ||
else checkImpliesMatchTerms existsL simplifedSubstPatL existsR substPatR | ||
(Left err, _) -> | ||
pure . Left . RpcError.backendError $ RpcError.Aborted (Text.pack . constructorName $ err) | ||
Comment on lines
+162
to
+163
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. We should probably also catch |
||
MatchSuccess subst -> do | ||
let filteredConsequentPreds = | ||
Set.map (substituteInPredicate subst) substPatR.constraints `Set.difference` substPatL.constraints | ||
|
Uh oh!
There was an error while loading. Please reload this page.