@@ -29,7 +29,6 @@ module Booster.Pattern.ApplyEquations (
29
29
simplifyConstraint ,
30
30
simplifyConstraints ,
31
31
SimplifierCache ,
32
- logWarn ,
33
32
) where
34
33
35
34
import Control.Applicative (Alternative (.. ))
@@ -384,16 +383,17 @@ fromCache tag t = eqState $ Map.lookup t <$> gets (select tag . (.cache))
384
383
385
384
logWarn :: MonadLogger m => Text -> m ()
386
385
logWarn msg =
387
- logWarnNS " booster" $ msg <> " For more details, enable context logging '--log-context \" *abort\" '"
386
+ logWarnNS " booster" $
387
+ msg <> " For more details, enable context logging '--log-context \" *abort*detail\" '"
388
388
389
389
checkForLoop :: MonadLoggerIO io => Term -> EquationT io ()
390
390
checkForLoop t = do
391
391
EquationState {termStack} <- getState
392
392
whenJust (Seq. elemIndexL t termStack) $ \ i -> do
393
- withContext " abort" $
393
+ withContext " abort" . withContext " detail " $
394
394
logMessage $
395
395
renderOneLineText $
396
- " Equation loop:"
396
+ " Equation loop detected :"
397
397
<+> hsep
398
398
( intersperse " ," $
399
399
map (\ (Term attrs _) -> " term" <+> pretty (showHashHex attrs. hash)) $
@@ -451,9 +451,14 @@ iterateEquations direction preference startTerm = do
451
451
checkCounter counter = do
452
452
config <- getConfig
453
453
when (counter > config. maxRecursion) $ do
454
- let msg =
455
- " Recursion limit exceeded. The limit can be increased by restarting the server with '--equation-max-recursion N'."
456
- withContext " abort" $ logMessage msg
454
+ let msg, details :: Text
455
+ msg =
456
+ " Recursion limit exceeded. The limit can be increased by \
457
+ \ restarting the server with '--equation-max-recursion N'."
458
+ details =
459
+ " Recursion limit exceeded. \
460
+ \Previous \" term*detail\" messages show the terms involved."
461
+ withContext " abort" . withContext " detail" $ logMessage details
457
462
logWarn msg
458
463
throw . TooManyRecursions . (. recursionStack) =<< getState
459
464
@@ -465,10 +470,10 @@ iterateEquations direction preference startTerm = do
465
470
currentCount <- countSteps
466
471
when (coerce currentCount > config. maxIterations) $ do
467
472
let msg =
468
- renderOneLineText $
469
- " Unable to finish evaluation in " <+> pretty currentCount <+> " iterations. "
470
- withContext " abort " $ logMessage msg
471
- logWarn msg
473
+ " Unable to finish evaluation in " <+> pretty currentCount <+> " iterations. "
474
+ withContext " abort " . withContext " detail " . logMessage . renderOneLineText $
475
+ msg <+> " Final term: " <+> pretty currentTerm
476
+ logWarn $ renderOneLineText msg
472
477
throw $
473
478
TooManyIterations currentCount startTerm currentTerm
474
479
pushTerm currentTerm
@@ -498,14 +503,16 @@ llvmSimplify term = do
498
503
where
499
504
evalLlvm definition api cb t@ (Term attributes _)
500
505
| attributes. isEvaluated = pure t
501
- | isConcrete t && attributes. canBeEvaluated = do
506
+ | isConcrete t && attributes. canBeEvaluated = withContext " llvm " $ do
502
507
LLVM. simplifyTerm api definition t (sortOfTerm t)
503
508
>>= \ case
504
509
Left (LlvmError e) -> do
505
- withContext " llvm" $ withContext " abort" $ logMessage $ Text. decodeUtf8 e
506
- logWarn $ " LLVM backend error detected: " <> Text. decodeUtf8 e <> " ."
510
+ let msg = " LLVM backend error detected: " <> Text. decodeUtf8 e
511
+ details = msg <> " while evaluating " <> renderOneLineText (pretty t)
512
+ withContext " abort" . withContext " detail" $ logMessage details
513
+ logWarn msg
507
514
throw $ UndefinedTerm t $ LlvmError e
508
- Right result -> withContext " llvm " $ do
515
+ Right result -> do
509
516
when (result /= t) $ do
510
517
setChanged
511
518
withContext " success" $
@@ -693,12 +700,15 @@ applyHooksAndEquations pref term = do
693
700
case term of
694
701
SymbolApplication sym _sorts args
695
702
| Just hook <- flip Map. lookup Builtin. hooks =<< sym. attributes. hook -> do
696
- withContext (LogContext $ " hook " <> maybe " UNKNOWN" Text. decodeUtf8 sym. attributes. hook)
697
- $ either
698
- (\ e -> withContext " abort" (logMessage e) >> logWarn e >> throw (InternalError e))
699
- checkChanged
700
- . runExcept
701
- $ hook args
703
+ let hookName = maybe " UNKNOWN" Text. decodeUtf8 sym. attributes. hook
704
+ onError e = do
705
+ withContext " abort" . withContext " detail" . logMessage $
706
+ e <> " while evaluating " <> renderOneLineText (pretty term)
707
+ logWarn e
708
+ throw (InternalError e)
709
+ withContext (LogContext $ " hook " <> hookName) $
710
+ either onError checkChanged $
711
+ runExcept (hook args)
702
712
_other -> pure Nothing
703
713
704
714
-- for the (unlikely) case that a built-in reproduces itself, we
@@ -1074,8 +1084,12 @@ simplifyConstraint' recurseIntoEvalBool = \case
1074
1084
withContext " llvm" $
1075
1085
LLVM. simplifyBool api t >>= \ case
1076
1086
Left (LlvmError e) -> do
1077
- withContext " abort" $ logMessage $ Text. decodeUtf8 e
1078
- logWarn $ " LLVM backend error detected: " <> Text. decodeUtf8 e <> " ."
1087
+ let msg =
1088
+ " LLVM backend error detected: " <> Text. decodeUtf8 e
1089
+ details =
1090
+ msg <> " while evaluating " <> renderOneLineText (pretty t)
1091
+ withContext " abort" . withContext " detail" $ logMessage details
1092
+ logWarn msg
1079
1093
throw $ UndefinedTerm t $ LlvmError e
1080
1094
Right res -> do
1081
1095
let result =
0 commit comments