Skip to content

Commit 413428f

Browse files
committed
Do not carry recursion depth in TooManyIterations
1 parent 034078d commit 413428f

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

booster/library/Booster/Pattern/ApplyEquations.hs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ catch_ (EquationT op) hdlr = EquationT $ do
102102

103103
data EquationFailure
104104
= IndexIsNone Term
105-
| TooManyIterations Int Int Term Term
105+
| TooManyIterations Int Term Term
106106
| EquationLoop [Term]
107107
| TooManyRecursions [Term]
108108
| SideConditionFalse Predicate
@@ -114,10 +114,9 @@ instance Pretty (PrettyWithModifiers mods EquationFailure) where
114114
pretty (PrettyWithModifiers f) = case f of
115115
IndexIsNone t ->
116116
"Index 'None' for term " <> pretty' @mods t
117-
TooManyIterations depth count start end ->
117+
TooManyIterations count start end ->
118118
vsep
119119
[ "Unable to finish evaluation in " <> pretty count <> " iterations"
120-
, "at recursion depth " <> pretty depth
121120
, "Started with: " <> pretty' @mods start
122121
, "Stopped at: " <> pretty' @mods end
123122
]
@@ -235,9 +234,6 @@ popRecursion = do
235234
throw $ InternalError "Trying to pop an empty recursion stack"
236235
else eqState $ put s{recursionStack = tail s.recursionStack}
237236

238-
getRecusionDepth :: LoggerMIO io => EquationT io Int
239-
getRecusionDepth = (length . (.recursionStack)) <$> getState
240-
241237
toCache :: Monad io => CacheTag -> Term -> Term -> EquationT io ()
242238
toCache tag orig result = eqState . modify $ \s -> s{cache = updateCache tag s.cache}
243239
where
@@ -335,7 +331,6 @@ iterateEquations direction preference startTerm = do
335331
config <- getConfig
336332
currentCount <- countSteps
337333
when (coerce currentCount > config.maxIterations) $ do
338-
currentRecursionDepth <- getRecusionDepth
339334
-- FIXME if this exception is caught in evaluatePattern',
340335
-- then CtxAbort is a wrong context for it.
341336
-- We should emit this log entry somewhere else.
@@ -349,7 +344,7 @@ iterateEquations direction preference startTerm = do
349344
logMessage . renderOneLineText $
350345
"Final term:" <+> pretty' @mods currentTerm
351346
throw $
352-
TooManyIterations currentRecursionDepth currentCount startTerm currentTerm
347+
TooManyIterations currentCount startTerm currentTerm
353348
pushTerm currentTerm
354349
-- simplify the term using the LLVM backend first
355350
llvmResult <- llvmSimplify currentTerm
@@ -452,12 +447,11 @@ evaluatePattern' pat@Pattern{term, ceilConditions} = withPatternContext pat $ do
452447
-- i.e. not in a recursive evaluation of a side-condition,
453448
-- it is safe to keep the partial result and ignore the exception.
454449
-- Otherwise we would be throwing away useful work.
450+
-- The exceptions thrown in recursion is caught in applyEquation.checkConstraint
455451
keepTopLevelResults :: LoggerMIO io => EquationFailure -> EquationT io Term
456452
keepTopLevelResults = \case
457-
err@(TooManyIterations recursionDepth _ _ partialResult) ->
458-
case recursionDepth of
459-
0 -> pure partialResult
460-
_ -> throw err
453+
TooManyIterations _ _ partialResult ->
454+
pure partialResult
461455
err -> throw err
462456

463457
-- evaluate the given predicate assuming all others

0 commit comments

Comments
 (0)