Skip to content

Commit 035f224

Browse files
authored
HOTFIX more comments and error handling in constraint pre-evaluation (#4105)
The previous change contained some incomplete code that would forward errors from the constraint pre-evaluation to RPC caller. This change is to handle some, and log all other, errors that could arise.
1 parent 08f0cbd commit 035f224

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

booster/library/Booster/Pattern/Rewrite.hs

+25-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import Data.Map qualified as Map
4040
import Data.Maybe (catMaybes, fromMaybe)
4141
import Data.Sequence as Seq (Seq, fromList, (|>))
4242
import Data.Set qualified as Set
43-
import Data.Text as Text (Text, pack)
43+
import Data.Text as Text (Text, pack, unpack)
4444
import Numeric.Natural
4545
import Prettyprinter
4646

@@ -1001,16 +1001,32 @@ performRewrite ::
10011001
Pattern ->
10021002
io (Natural, Seq (RewriteTrace ()), RewriteResult Pattern)
10031003
performRewrite rewriteConfig pat = do
1004+
-- simplify all constraints (individually) before starting to rewrite
10041005
simplifiedConstraints <-
10051006
withContext CtxSimplify $ evaluateConstraints definition llvmApi smtSolver pat.constraints
1006-
case simplifiedConstraints of
1007-
Right constraints ->
1008-
(flip runStateT rewriteStart $ doSteps False pat{constraints})
1009-
>>= \(rr, RewriteStepsState{counter, traces}) -> pure (counter, traces, rr)
1010-
Left r@(SideConditionFalse{}) ->
1011-
pure (0, fromList [RewriteSimplified (Just r)], error "Just return #Bottom here")
1012-
Left err ->
1013-
error (show err)
1007+
(rr, RewriteStepsState{counter, traces}) <-
1008+
case simplifiedConstraints of
1009+
Right constraints ->
1010+
flip runStateT rewriteStart $ doSteps False pat{constraints}
1011+
Left r@SideConditionFalse{} ->
1012+
-- a side condition was found to be false, return a vacuous state
1013+
pure (RewriteTrivial pat, rewriteStart{traces = Seq.fromList [RewriteSimplified (Just r)]})
1014+
Left (InternalError msg) -> do
1015+
-- fail hard on internal errors
1016+
withContext CtxSimplify $ withContext CtxError $ logMessage msg
1017+
error $ Text.unpack msg
1018+
Left err -> do
1019+
-- log but ignore other actual errors (IndexIsNone,
1020+
-- TooManyIterations, EquationLoop, TooManyRecursions,
1021+
-- EquationLoop, UndefinedTerm), proceeding with the
1022+
-- original constraints (to fail later when processing
1023+
-- the constraints during rewriting or at the end).
1024+
getPrettyModifiers >>= \case
1025+
ModifiersRep (_ :: FromModifiersT mods => Proxy mods) ->
1026+
withContext CtxSimplify . withContext CtxWarn . logMessage $
1027+
renderOneLineText (pretty' @mods err)
1028+
flip runStateT rewriteStart $ doSteps False pat
1029+
pure (counter, traces, rr)
10141030
where
10151031
RewriteConfig
10161032
{ definition

0 commit comments

Comments
 (0)