Skip to content

Commit a580cfc

Browse files
committed
Merge remote-tracking branch 'origin/master' into georgy/booster-remainders
2 parents 70817d4 + def3190 commit a580cfc

File tree

92 files changed

+98968
-1951
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+98968
-1951
lines changed

booster/library/Booster/CLOptions.hs

+68-40
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module Booster.CLOptions (
77
CLOptions (..),
88
EquationOptions (..),
99
LogFormat (..),
10+
LogOptions (..),
11+
RewriteOptions (..),
1012
TimestampFormat (..),
1113
clOptionsParser,
1214
adjustLogLevels,
@@ -25,6 +27,7 @@ import Data.Maybe (fromMaybe)
2527
import Data.Text (Text, pack)
2628
import Data.Text.Encoding (decodeASCII)
2729
import Data.Version (Version (..), showVersion)
30+
import Numeric.Natural (Natural)
2831
import Options.Applicative
2932

3033
import Booster.GlobalState (EquationOptions (..))
@@ -41,18 +44,23 @@ data CLOptions = CLOptions
4144
, mainModuleName :: Text
4245
, llvmLibraryFile :: Maybe FilePath
4346
, port :: Int
44-
, logLevels :: [LogLevel]
47+
, logOptions :: LogOptions
48+
, smtOptions :: Maybe SMTOptions
49+
, equationOptions :: EquationOptions
50+
, rewriteOptions :: RewriteOptions
51+
}
52+
deriving stock (Show)
53+
54+
data LogOptions = LogOptions
55+
{ logLevels :: [LogLevel]
4556
, logTimeStamps :: Bool
4657
, timeStampsFormat :: TimestampFormat
4758
, logFormat :: LogFormat
4859
, logContexts :: [ContextFilter]
4960
, logFile :: Maybe FilePath
50-
, smtOptions :: Maybe SMTOptions
51-
, equationOptions :: EquationOptions
52-
, indexCells :: [Text]
5361
, prettyPrintOptions :: [ModifierT]
5462
}
55-
deriving (Show)
63+
deriving stock (Show)
5664

5765
data LogFormat
5866
= Standard
@@ -76,6 +84,12 @@ instance Show TimestampFormat where
7684
Pretty -> "pretty"
7785
Nanoseconds -> "nanoseconds"
7886

87+
data RewriteOptions = RewriteOptions
88+
{ indexCells :: [Text]
89+
, interimSimplification :: Maybe Natural
90+
}
91+
deriving stock (Show, Eq)
92+
7993
clOptionsParser :: Parser CLOptions
8094
clOptionsParser =
8195
CLOptions
@@ -103,7 +117,15 @@ clOptionsParser =
103117
<> help "Port for the RPC server to bind to"
104118
<> showDefault
105119
)
106-
<*> many
120+
<*> parseLogOptions
121+
<*> parseSMTOptions
122+
<*> parseEquationOptions
123+
<*> parseRewriteOptions
124+
125+
parseLogOptions :: Parser LogOptions
126+
parseLogOptions =
127+
LogOptions
128+
<$> many
107129
( option
108130
(eitherReader readLogLevel)
109131
( metavar "LEVEL"
@@ -154,15 +176,6 @@ clOptionsParser =
154176
"Log file to output the logs into"
155177
)
156178
)
157-
<*> parseSMTOptions
158-
<*> parseEquationOptions
159-
<*> option
160-
(eitherReader $ mapM (readCellName . trim) . splitOn ",")
161-
( metavar "CELL-NAME[,CELL-NAME]"
162-
<> long "index-cells"
163-
<> help "Names of configuration cells to index rewrite rules with (default: 'k')"
164-
<> value []
165-
)
166179
<*> option
167180
(eitherReader $ mapM (readModifierT . trim) . splitOn ",")
168181
( metavar "PRETTY_PRINT"
@@ -202,18 +215,6 @@ clOptionsParser =
202215
"nanoseconds" -> Right Nanoseconds
203216
other -> Left $ other <> ": Unsupported timestamp format"
204217

205-
readCellName :: String -> Either String Text
206-
readCellName input
207-
| null input =
208-
Left "Empty cell name"
209-
| all isAscii input
210-
, all isPrint input =
211-
Right $ "Lbl'-LT-'" <> enquote input <> "'-GT-'"
212-
| otherwise =
213-
Left $ "Illegal non-ascii characters in `" <> input <> "'"
214-
215-
enquote = decodeASCII . encodeLabel . BS.pack
216-
217218
-- custom log levels that can be selected
218219
allowedLogLevels :: [(String, String)]
219220
allowedLogLevels =
@@ -364,13 +365,6 @@ parseSMTOptions =
364365
where
365366
smtDefaults = defaultSMTOptions
366367

367-
nonnegativeInt :: ReadM Int
368-
nonnegativeInt =
369-
auto >>= \case
370-
i
371-
| i < 0 -> readerError "must be a non-negative integer."
372-
| otherwise -> pure i
373-
374368
readTactic =
375369
either (readerError . ("Invalid s-expression. " <>)) pure . SMT.parseSExpr . BS.pack =<< str
376370

@@ -397,12 +391,46 @@ parseEquationOptions =
397391
defaultMaxIterations = 100
398392
defaultMaxRecursion = 5
399393

400-
nonnegativeInt :: ReadM Int
401-
nonnegativeInt =
402-
auto >>= \case
403-
i
404-
| i < 0 -> readerError "must be a non-negative integer."
405-
| otherwise -> pure i
394+
parseRewriteOptions :: Parser RewriteOptions
395+
parseRewriteOptions =
396+
RewriteOptions
397+
<$> option
398+
(eitherReader $ mapM (readCellName . trim) . splitOn ",")
399+
( metavar "CELL-NAME[,CELL-NAME]"
400+
<> long "index-cells"
401+
<> help "Names of configuration cells to index rewrite rules with (default: 'k')"
402+
<> value []
403+
)
404+
<*> optional
405+
( option
406+
(intWith (> 0))
407+
( metavar "DEPTH"
408+
<> long "simplify-each"
409+
<> help "If given: Simplify the term each time the given rewrite depth is reached"
410+
)
411+
)
412+
where
413+
readCellName :: String -> Either String Text
414+
readCellName input
415+
| null input =
416+
Left "Empty cell name"
417+
| all isAscii input
418+
, all isPrint input =
419+
Right $ "Lbl'-LT-'" <> enquote input <> "'-GT-'"
420+
| otherwise =
421+
Left $ "Illegal non-ascii characters in `" <> input <> "'"
422+
423+
enquote = decodeASCII . encodeLabel . BS.pack
424+
425+
intWith :: Integral i => (Integer -> Bool) -> ReadM i
426+
intWith p =
427+
auto >>= \case
428+
i
429+
| not (p i) -> readerError $ show i <> ": Invalid integer value."
430+
| otherwise -> pure (fromIntegral i)
431+
432+
nonnegativeInt :: Integral i => ReadM i
433+
nonnegativeInt = intWith (>= 0)
406434

407435
versionInfoParser :: Parser (a -> a)
408436
versionInfoParser =

booster/library/Booster/Definition/Ceil.hs

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Booster.Log
1818
import Booster.Pattern.Bool
1919
import Booster.Pattern.Pretty
2020
import Booster.Pattern.Util (isConcrete, sortOfTerm)
21+
import Booster.SMT.Interface
2122
import Booster.Util (Flag (..))
2223
import Control.DeepSeq (NFData)
2324
import Control.Monad (foldM)
@@ -101,7 +102,8 @@ computeCeilRule ::
101102
computeCeilRule mllvm def r@RewriteRule.RewriteRule{lhs, requires, rhs, attributes, computedAttributes}
102103
| null computedAttributes.notPreservesDefinednessReasons = pure Nothing
103104
| otherwise = do
104-
(res, _) <- runEquationT def mllvm Nothing mempty mempty $ do
105+
ns <- noSolver
106+
(res, _) <- runEquationT def mllvm ns mempty mempty $ do
105107
lhsCeils <- Set.fromList <$> computeCeil lhs
106108
requiresCeils <- Set.fromList <$> concatMapM (computeCeil . coerce) (Set.toList requires)
107109
let subtractLHSAndRequiresCeils = (Set.\\ (lhsCeils `Set.union` requiresCeils)) . Set.fromList

0 commit comments

Comments
 (0)