Skip to content

Commit baa73d3

Browse files
goodlyrottenapplegithub-actionsrv-jenkins
authored
Add options to the kore term pretty printer (#3963)
Add the following options when pretty printing terms: * `decode` - decode symbol labels and strip the `Lbl` prefix * `truncate` - truncate long domain values * `infix` - try to re-assemble infix notation from the holes in label syntax (may not always be correct). For example: ``` ... Uncertain about match with rule. Remainder: #range( Eq#VarB1:SortBytes{} , Eq#VarS2:SortInt{} , Eq#VarW2:SortInt{} ) == buf("32", lookup(VarCONTRACT-FAKEETH_STORAGE:SortMap{}, keccak( buf("32", VarCALLER_ID:SortInt{}) +Bytes "\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL" ))), #range( Eq#VarB1:SortBytes{} , Eq#VarS1:SortInt{} , Eq#VarW1:SortInt{} ) == buf("32", lookup(VarCONTRACT-FAKEETH_STORAGE:SortMap{}, keccak( buf("32", VarCONTRACT_ID:SortInt{}) +Bytes buf("32", keccak( buf("32", VarCALLER_ID:SortInt{}) +Bytes "\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\NUL\SOH" )) ))) ``` These can now be passed to the server via the `--pretty-print` flag. E.g. `--pretty-print truncated,decode` will preserve current behaviour (and is set as default when no explicit option is provided) --------- Co-authored-by: github-actions <[email protected]> Co-authored-by: rv-jenkins <[email protected]>
1 parent af1fd21 commit baa73d3

File tree

24 files changed

+1195
-901
lines changed

24 files changed

+1195
-901
lines changed

booster/library/Booster/Builtin/Base.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Data.Text.Encoding qualified as Text
2121
import Prettyprinter (pretty)
2222

2323
import Booster.Pattern.Base
24+
import Booster.Pattern.Pretty
2425
import Booster.Pattern.Util
2526
import Booster.Prettyprinter
2627

@@ -68,5 +69,5 @@ t `shouldHaveSort` s
6869
throwE $
6970
Text.unlines
7071
[ "Argument term has unexpected sort (expected " <> Text.decodeLatin1 s <> "):"
71-
, renderText (pretty t)
72+
, renderText (pretty (PrettyWithModifiers @['Decoded, 'Truncated] t))
7273
]

booster/library/Booster/Builtin/KEQUAL.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Prettyprinter
2222
import Booster.Builtin.Base
2323
import Booster.Pattern.Base
2424
import Booster.Pattern.Bool
25+
import Booster.Pattern.Pretty
2526
import Booster.Pattern.Util (isConstructorSymbol, sortOfTerm)
2627
import Booster.Prettyprinter (renderText)
2728

@@ -40,8 +41,8 @@ iteHook args
4041
unless (sortOfTerm thenVal == sortOfTerm elseVal) $
4142
throwE . Text.unlines $
4243
[ "Different sorts in alternatives:"
43-
, renderText $ pretty thenVal
44-
, renderText $ pretty elseVal
44+
, renderText $ pretty (PrettyWithModifiers @['Decoded, 'Truncated] thenVal)
45+
, renderText $ pretty (PrettyWithModifiers @['Decoded, 'Truncated] elseVal)
4546
]
4647
case cond of
4748
TrueBool -> pure $ Just thenVal

booster/library/Booster/CLOptions.hs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Text.Read (readMaybe)
2828

2929
import Booster.GlobalState (EquationOptions (..))
3030
import Booster.Log.Context (ContextFilter, ctxt, readContextFilter)
31+
import Booster.Pattern.Pretty
3132
import Booster.SMT.Interface (SMTOptions (..), defaultSMTOptions)
3233
import Booster.SMT.LowLevelCodec qualified as SMT (parseSExpr)
3334
import Booster.Trace (CustomUserEventType)
@@ -48,6 +49,7 @@ data CLOptions = CLOptions
4849
, smtOptions :: Maybe SMTOptions
4950
, equationOptions :: EquationOptions
5051
, indexCells :: [Text]
52+
, prettyPrintOptions :: [ModifierT]
5153
, -- developer options below
5254
eventlogEnabledUserEvents :: [CustomUserEventType]
5355
}
@@ -162,6 +164,14 @@ clOptionsParser =
162164
<> help "Names of configuration cells to index rewrite rules with (default: 'k')"
163165
<> value []
164166
)
167+
<*> option
168+
(eitherReader $ mapM (readModifierT . trim) . splitOn ",")
169+
( metavar "PRETTY_PRINT"
170+
<> value [Decoded, Truncated]
171+
<> long "pretty-print"
172+
<> help "Prety print options for kore terms: decode, infix, truncated"
173+
<> showDefault
174+
)
165175
-- developer options below
166176
<*> many
167177
( option
@@ -201,6 +211,13 @@ clOptionsParser =
201211
"json" -> Right Json
202212
other -> Left $ other <> ": Unsupported log format"
203213

214+
readModifierT :: String -> Either String ModifierT
215+
readModifierT = \case
216+
"truncated" -> Right Truncated
217+
"infix" -> Right Infix
218+
"decoded" -> Right Decoded
219+
other -> Left $ other <> ": Unsupported prettry printer option"
220+
204221
readTimeStampFormat :: String -> Either String TimestampFormat
205222
readTimeStampFormat = \case
206223
"pretty" -> Right Pretty

booster/library/Booster/Definition/Ceil.hs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Booster.Pattern.Base
1616
import Booster.LLVM as LLVM (API, simplifyBool)
1717
import Booster.Log
1818
import Booster.Pattern.Bool
19+
import Booster.Pattern.Pretty
1920
import Booster.Pattern.Util (isConcrete, sortOfTerm)
2021
import Booster.Util (Flag (..))
2122
import Control.DeepSeq (NFData)
@@ -43,20 +44,20 @@ data ComputeCeilSummary = ComputeCeilSummary
4344
deriving stock (Eq, Ord, Show, GHC.Generic)
4445
deriving anyclass (NFData)
4546

46-
instance Pretty ComputeCeilSummary where
47-
pretty ComputeCeilSummary{rule, ceils} =
47+
instance FromModifiersT mods => Pretty (PrettyWithModifiers mods ComputeCeilSummary) where
48+
pretty (PrettyWithModifiers ComputeCeilSummary{rule, ceils}) =
4849
Pretty.vsep $
4950
[ "\n\n----------------------------\n"
5051
, pretty $ sourceRef rule
51-
, pretty rule.lhs
52+
, pretty' @mods rule.lhs
5253
, "=>"
53-
, pretty rule.rhs
54+
, pretty' @mods rule.rhs
5455
]
5556
<> ( if null rule.requires
5657
then []
5758
else
5859
[ "requires"
59-
, Pretty.indent 2 . Pretty.vsep $ map pretty $ Set.toList rule.requires
60+
, Pretty.indent 2 . Pretty.vsep $ map (pretty' @mods) $ Set.toList rule.requires
6061
]
6162
)
6263
<> [ Pretty.line
@@ -69,7 +70,9 @@ instance Pretty ComputeCeilSummary where
6970
[ Pretty.line
7071
, "computed ceils:"
7172
, Pretty.indent 2 . Pretty.vsep $
72-
map (either pretty (\t -> "#Ceil(" Pretty.<+> pretty t Pretty.<+> ")")) (Set.toList ceils)
73+
map
74+
(either (pretty' @mods) (\t -> "#Ceil(" Pretty.<+> pretty' @mods t Pretty.<+> ")"))
75+
(Set.toList ceils)
7376
]
7477

7578
computeCeilsDefinition ::
@@ -209,7 +212,7 @@ mkInKeys inKeysSymbols k m =
209212
Nothing ->
210213
error $
211214
"in_keys for key sort '"
212-
<> show (pretty $ sortOfTerm k)
215+
<> show (pretty $ PrettyWithModifiers @'[Decoded, Truncated] $ sortOfTerm k)
213216
<> "' and map sort '"
214-
<> show (pretty $ sortOfTerm m)
217+
<> show (pretty $ PrettyWithModifiers @'[Decoded, Truncated] $ sortOfTerm m)
215218
<> "' does not exist."

booster/library/Booster/Definition/Util.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import Booster.Definition.Base
3131
import Booster.Definition.Ceil (ComputeCeilSummary (..))
3232
import Booster.Pattern.Base
3333
import Booster.Pattern.Index (CellIndex (..), TermIndex (..))
34+
import Booster.Pattern.Pretty
3435
import Booster.Prettyprinter
3536
import Booster.Util
3637

@@ -92,7 +93,8 @@ prettySummary :: Bool -> Summary -> String
9293
prettySummary veryVerbose summary@Summary{computeCeilsSummary} =
9394
Pretty.renderString . layoutPrettyUnbounded $
9495
Pretty.vcat $
95-
pretty summary : if veryVerbose then map pretty computeCeilsSummary else []
96+
pretty summary
97+
: if veryVerbose then map (pretty' @['Decoded, 'Truncated] $) computeCeilsSummary else []
9698

9799
instance Pretty Summary where
98100
pretty summary =
@@ -146,7 +148,8 @@ instance Pretty Summary where
146148
prettyCellIndex None = "None"
147149

148150
prettyCeilRule :: RewriteRule r -> Doc a
149-
prettyCeilRule RewriteRule{lhs, rhs} = "#Ceil(" <+> pretty lhs <+> ") =>" <+> pretty rhs
151+
prettyCeilRule RewriteRule{lhs, rhs} =
152+
"#Ceil(" <+> pretty' @['Decoded, 'Truncated] lhs <+> ") =>" <+> pretty' @['Decoded, 'Truncated] rhs
150153

151154
sourceRefText :: HasSourceRef a => a -> Text
152155
sourceRefText = renderOneLineText . pretty . sourceRef

0 commit comments

Comments
 (0)