-
Notifications
You must be signed in to change notification settings - Fork 42
Check consistency of constraints before evaluating a pattern #4013
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
Changes from 22 commits
99988c1
f368038
32b08b7
59bd44b
fd3ea50
bb6a765
29524b8
8852282
8f13183
1948b15
8bef12a
432ff02
7fe9293
2483a57
25afc73
c9f107d
2ef21ab
64147e3
24b8126
10f6b18
7f7d667
80d1675
1fce254
d82576f
575428c
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -439,7 +439,11 @@ evaluateTerm' :: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evaluateTerm' direction = iterateEquations direction PreferFunctions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {- | Simplify a Pattern, processing its constraints independently. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns either the first failure or the new pattern if no failure was encountered | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Before evaluating the term of the pattern, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| the constraints of the pattern are checked for consistency with an SMT solver. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns either the first failure or the new pattern if no failure was encountered. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evaluatePattern :: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LoggerMIO io => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -458,14 +462,43 @@ evaluatePattern' :: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pattern -> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EquationT io Pattern | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evaluatePattern' pat@Pattern{term, ceilConditions} = withPatternContext pat $ do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| newTerm <- withTermContext term $ evaluateTerm' BottomUp term `catch_` keepTopLevelResults | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- after evaluating the term, evaluate all (existing and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- newly-acquired) constraints, once | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| traverse_ simplifyAssumedPredicate . predicates =<< getState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- this may yield additional new constraints, left unevaluated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evaluatedConstraints <- predicates <$> getState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pure Pattern{constraints = evaluatedConstraints, term = newTerm, ceilConditions} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| solver <- (.smtSolver) <$> getConfig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- check the pattern's constraints for consistency, reporting an error if they are Bottom | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| withContext CtxConstraint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| . withContext CtxDetail | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| . withTermContext (coerce $ collapseAndBools pat.constraints) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $ pure () | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| consistent <- withContext CtxConstraint $ SMT.isSat solver pat.constraints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| withContext CtxConstraint $ do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logMessage $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Constraints consistency check returns: " <> show consistent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case consistent of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Right False -> do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- the constraints are unsatisfiable, which means that the patten is Bottom | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw . SideConditionFalse . collapseAndBools $ pat.constraints | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Left SMT.SMTSolverUnknown{} -> do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- unlikely case of an Unknown response to a consistency check. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- continue to preserver the old behaviour. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| withContext CtxConstraint . logWarn . Text.pack $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Constraints consistency UNKNOWN: " <> show consistent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Left other -> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- fail hard on SMT error other than @SMT.SMTSolverUnknown@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| liftIO $ Exception.throw other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Right True -> do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- constraints are consistent, continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| where | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue = do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| newTerm <- withTermContext term $ evaluateTerm' BottomUp term `catch_` keepTopLevelResults | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- after evaluating the term, evaluate all (existing and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- newly-acquired) constraints, once | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| traverse_ simplifyAssumedPredicate . predicates =<< getState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -- this may yield additional new constraints, left unevaluated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| evaluatedConstraints <- predicates <$> getState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pure Pattern{constraints = evaluatedConstraints, term = newTerm, ceilConditions} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| withContext CtxConstraint | |
| . withContext CtxDetail | |
| . withTermContext (coerce $ collapseAndBools pat.constraints) | |
| $ pure () | |
| consistent <- withContext CtxConstraint $ SMT.isSat solver pat.constraints | |
| withContext CtxConstraint $ do | |
| logMessage $ | |
| "Constraints consistency check returns: " <> show consistent | |
| case consistent of | |
| Right False -> do | |
| -- the constraints are unsatisfiable, which means that the patten is Bottom | |
| throw . SideConditionFalse . collapseAndBools $ pat.constraints | |
| Left SMT.SMTSolverUnknown{} -> do | |
| -- unlikely case of an Unknown response to a consistency check. | |
| -- continue to preserver the old behaviour. | |
| withContext CtxConstraint . logWarn . Text.pack $ | |
| "Constraints consistency UNKNOWN: " <> show consistent | |
| continue | |
| Left other -> | |
| -- fail hard on SMT error other than @SMT.SMTSolverUnknown@ | |
| liftIO $ Exception.throw other | |
| Right True -> do | |
| -- constraints are consistent, continue | |
| continue | |
| where | |
| continue = do | |
| newTerm <- withTermContext term $ evaluateTerm' BottomUp term `catch_` keepTopLevelResults | |
| -- after evaluating the term, evaluate all (existing and | |
| -- newly-acquired) constraints, once | |
| traverse_ simplifyAssumedPredicate . predicates =<< getState | |
| -- this may yield additional new constraints, left unevaluated | |
| evaluatedConstraints <- predicates <$> getState | |
| pure Pattern{constraints = evaluatedConstraints, term = newTerm, ceilConditions} | |
| withContext CtxConstraint $ do | |
| consistent <- | |
| withContext CtxDetail . withTermContext (coerce $ collapseAndBools pat.constraints) $ | |
| SMT.isSat solver pat.constraints | |
| logMessage $ "Constraints consistency check returns: " <> show consistent | |
| case consistent of | |
| Right False -> do | |
| -- the constraints are unsatisfiable, which means that the patten is Bottom | |
| throw . SideConditionFalse . collapseAndBools $ pat.constraints | |
| Left SMT.SMTSolverUnknown{} -> do | |
| -- unlikely case of an Unknown response to a consistency check. | |
| -- continue to preserver the old behaviour. | |
| logWarn . Text.pack $ "Constraints consistency UNKNOWN: " <> show consistent | |
| Left other -> | |
| -- fail hard on SMT error other than @SMT.SMTSolverUnknown@ | |
| liftIO $ Exception.throw other | |
| Right True -> -- constraints are consistent, continue | |
| pure () | |
| newTerm <- withTermContext term $ evaluateTerm' BottomUp term `catch_` keepTopLevelResults | |
| -- after evaluating the term, evaluate all (existing and | |
| -- newly-acquired) constraints, once | |
| traverse_ simplifyAssumedPredicate . predicates =<< getState | |
| -- this may yield additional new constraints, left unevaluated | |
| evaluatedConstraints <- predicates <$> getState | |
| pure Pattern{constraints = evaluatedConstraints, term = newTerm, ceilConditions} |
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.
- after discussing in the daily meeting, we have decided to proceed with checking the constrains as is
- I've introduced some stylistic corrections --- thanks!
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.
o/t ...maybe we should just remove all code for
log-timing...What I am using is the proxy-level
timinglog, not this level underneath.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.
I've prepared a separate PR that removes
"log-timing"and"log-fallbacks": #4015