@@ -102,7 +102,7 @@ catch_ (EquationT op) hdlr = EquationT $ do
102
102
103
103
data EquationFailure
104
104
= IndexIsNone Term
105
- | TooManyIterations Int Term Term
105
+ | TooManyIterations Int Int Term Term
106
106
| EquationLoop [Term ]
107
107
| TooManyRecursions [Term ]
108
108
| SideConditionFalse Predicate
@@ -114,9 +114,10 @@ instance Pretty (PrettyWithModifiers mods EquationFailure) where
114
114
pretty (PrettyWithModifiers f) = case f of
115
115
IndexIsNone t ->
116
116
" Index 'None' for term " <> pretty' @ mods t
117
- TooManyIterations count start end ->
117
+ TooManyIterations depth count start end ->
118
118
vsep
119
119
[ " Unable to finish evaluation in " <> pretty count <> " iterations"
120
+ , " at recursion depth " <> pretty depth
120
121
, " Started with: " <> pretty' @ mods start
121
122
, " Stopped at: " <> pretty' @ mods end
122
123
]
@@ -334,6 +335,7 @@ iterateEquations direction preference startTerm = do
334
335
config <- getConfig
335
336
currentCount <- countSteps
336
337
when (coerce currentCount > config. maxIterations) $ do
338
+ currentRecursionDepth <- getRecusionDepth
337
339
-- FIXME if this exception is caught in evaluatePattern',
338
340
-- then CtxAbort is a wrong context for it.
339
341
-- We should emit this log entry somewhere else.
@@ -347,7 +349,7 @@ iterateEquations direction preference startTerm = do
347
349
logMessage . renderOneLineText $
348
350
" Final term:" <+> pretty' @ mods currentTerm
349
351
throw $
350
- TooManyIterations currentCount startTerm currentTerm
352
+ TooManyIterations currentRecursionDepth currentCount startTerm currentTerm
351
353
pushTerm currentTerm
352
354
-- simplify the term using the LLVM backend first
353
355
llvmResult <- llvmSimplify currentTerm
@@ -446,13 +448,14 @@ evaluatePattern' pat@Pattern{term, ceilConditions} = withPatternContext pat $ do
446
448
evaluatedConstraints <- predicates <$> getState
447
449
pure Pattern {constraints = evaluatedConstraints, term = newTerm, ceilConditions}
448
450
where
449
- -- when TooManyIterations exception occurs while evaluating the top-level term (not a side-condition),
450
- -- it is safe to keep the partial result and ignore the exception. Otherwise we
451
- -- would be throwing away useful work.
451
+ -- when TooManyIterations exception occurred while evaluating the top-level term,
452
+ -- i.e. not in a recursive evaluation of a side-condition,
453
+ -- it is safe to keep the partial result and ignore the exception.
454
+ -- Otherwise we would be throwing away useful work.
452
455
keepTopLevelResults :: LoggerMIO io => EquationFailure -> EquationT io Term
453
456
keepTopLevelResults = \ case
454
- err@ (TooManyIterations _ _ partialResult) ->
455
- getRecusionDepth >>= \ case
457
+ err@ (TooManyIterations recursionDepth _ _ partialResult) ->
458
+ case recursionDepth of
456
459
0 -> pure partialResult
457
460
_ -> throw err
458
461
err -> throw err
0 commit comments