Skip to content

Commit

Permalink
Log ceil analysis with -l Ceil (#510)
Browse files Browse the repository at this point in the history
When starting the server with `-l Ceil`, with this change, we will emit
the logs of the ceil analysis of rewrite rules in the given definition
file, e.g.:

```
[Ceil#booster] Partial symbols found in rule /Users/sam/git/hs-backend-booster/bug_reports/concurrency_crash/imp.k :  ( 54
, 8 )
  non-total symbol Lbl_modInt_
rule does NOT preserve definedness. Partially computed ceils:
  _=/=Int_(Rule#VarI2:SortInt{}, "0")
  #Ceil( Rule#VarI2:SortInt{} )
```

---------

Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
goodlyrottenapple and github-actions authored Mar 26, 2024
1 parent f18a030 commit c2b6455
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions library/Booster/CLOptions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ allowedLogLevels =
, ("Depth", "Log the current depth of the state")
, ("SMT", "Log the SMT-solver interactions")
, ("ErrorDetails", "Log error conditions with extensive details")
, ("Ceil", "Log results of the ceil analysis")
]

-- Partition provided log levels into standard and custom ones, and
Expand Down
35 changes: 30 additions & 5 deletions tools/booster/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ import System.Exit
import System.IO qualified as IO

import Booster.CLOptions
import Booster.Definition.Ceil (computeCeilsDefinition)
import Booster.Definition.Attributes.Base (ComputedAxiomAttributes (notPreservesDefinednessReasons))
import Booster.Definition.Base (HasSourceRef (sourceRef), RewriteRule (computedAttributes))
import Booster.Definition.Ceil (ComputeCeilSummary (..), computeCeilsDefinition)
import Booster.GlobalState
import Booster.JsonRpc qualified as Booster
import Booster.LLVM.Internal (mkAPI, withDLib)
import Booster.Prettyprinter (renderText)
import Booster.SMT.Base qualified as SMT (SExpr (..), SMTId (..))
import Booster.SMT.Interface (SMTOptions (..))
import Booster.Syntax.ParsedKore (loadDefinition)
Expand Down Expand Up @@ -79,6 +82,7 @@ import Kore.Log.Registry qualified as Log
import Kore.Rewrite.SMT.Lemma (declareSMTLemmas)
import Kore.Syntax.Definition (ModuleName (ModuleName), SentenceAxiom)
import Options.SMT as KoreSMT (KoreSolverOptions (..), Solver (..))
import Prettyprinter qualified as Pretty
import Proxy (KoreServer (..), ProxyConfig (..))
import Proxy qualified
import SMT qualified as KoreSMT
Expand Down Expand Up @@ -151,17 +155,38 @@ main = do

withLogger reportDirectory koreLogOptions $ \actualLogAction -> do
mLlvmLibrary <- maybe (pure Nothing) (fmap Just . mkAPI) mdl
definitions <-
definitionsWithCeilSummaries <-
liftIO $
loadDefinition definitionFile
>>= mapM (mapM ((fst <$>) . runNoLoggingT . computeCeilsDefinition mLlvmLibrary))
>>= mapM (mapM (runNoLoggingT . computeCeilsDefinition mLlvmLibrary))
>>= evaluate . force . either (error . show) id
unless (isJust $ Map.lookup mainModuleName definitions) $ do
unless (isJust $ Map.lookup mainModuleName definitionsWithCeilSummaries) $ do
flip runLoggingT monadLogger $
Logger.logErrorNS "proxy" $
"Main module " <> mainModuleName <> " not found in " <> Text.pack definitionFile
liftIO exitFailure

flip runLoggingT monadLogger $
forM_ (Map.elems definitionsWithCeilSummaries) $ \(_, summaries) ->
forM_ summaries $ \ComputeCeilSummary{rule, ceils} ->
Logger.logOtherNS "booster" (Logger.LevelOther "Ceil") $
renderText $
Pretty.vsep $
[ "Partial symbols found in rule"
, Pretty.pretty (sourceRef rule)
, Pretty.indent 2 . Pretty.vsep $
map Pretty.pretty rule.computedAttributes.notPreservesDefinednessReasons
]
<> if null ceils
then ["discharged all ceils, rule preserves definedness"]
else
[ "rule does NOT preserve definedness. Partially computed ceils:"
, Pretty.indent 2 . Pretty.vsep $
map
(either Pretty.pretty (\t -> "#Ceil(" Pretty.<+> Pretty.pretty t Pretty.<+> ")"))
(Set.toList ceils)
]

mvarLogAction <- newMVar actualLogAction
let logAction = swappableLogger mvarLogAction

Expand All @@ -172,7 +197,7 @@ main = do
liftIO $
newMVar
Booster.ServerState
{ definitions
{ definitions = Map.map fst definitionsWithCeilSummaries
, defaultMain = mainModuleName
, mLlvmLibrary
, mSMTOptions = if boosterSMT then smtOptions else Nothing
Expand Down

0 comments on commit c2b6455

Please sign in to comment.