Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print sharing control #1330

Merged
merged 3 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions saw-core/src/Verifier/SAW/Term/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ type SawDoc = Doc SawStyle
data PPOpts = PPOpts { ppBase :: Int
, ppColor :: Bool
, ppShowLocalNames :: Bool
, ppMaxDepth :: Maybe Int }
, ppMaxDepth :: Maybe Int
, ppMinSharing :: Int }

-- | Default options for pretty-printing
defaultPPOpts :: PPOpts
defaultPPOpts = PPOpts { ppBase = 10, ppColor = False,
ppShowLocalNames = True, ppMaxDepth = Nothing }
ppShowLocalNames = True, ppMaxDepth = Nothing, ppMinSharing = 2 }

-- | Options for printing with a maximum depth
depthPPOpts :: Int -> PPOpts
Expand Down Expand Up @@ -575,16 +576,18 @@ shouldMemoizeTerm t =
-- let-bindings for the entries in the memoization table. If the flag is true,
-- compute a global table, otherwise compute a local table.
ppTermWithMemoTable :: Prec -> Bool -> Term -> PPM SawDoc
ppTermWithMemoTable prec global_p trm = ppLets occ_map_elems [] where
ppTermWithMemoTable prec global_p trm = do
min_occs <- ppMinSharing <$> ppOpts <$> ask
ppLets (occ_map_elems min_occs) [] where

-- Generate an occurrence map for trm, filtering out terms that only occur
-- once, that are "too small" to memoize, and, for the global table, terms
-- that are not closed
occ_map_elems =
occ_map_elems min_occs =
IntMap.assocs $
IntMap.filter
(\(t,cnt) ->
cnt > 1 && shouldMemoizeTerm t &&
cnt >= min_occs && shouldMemoizeTerm t &&
(if global_p then looseVars t == emptyBitSet else True)) $
scTermCount global_p trm

Expand Down
11 changes: 11 additions & 0 deletions src/SAWScript/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,11 @@ set_color b = do
let b' = b && useColor opts
putTopLevelRW rw { rwPPOpts = (rwPPOpts rw) { ppOptsColor = b' } }

set_min_sharing :: Int -> TopLevel ()
set_min_sharing b = do
rw <- getTopLevelRW
putTopLevelRW rw { rwPPOpts = (rwPPOpts rw) { ppOptsMinSharing = b } }

print_value :: Value -> TopLevel ()
print_value (VString s) = printOutLnTop Info (Text.unpack s)
print_value (VTerm t) = do
Expand Down Expand Up @@ -811,6 +816,12 @@ primitives = Map.fromList
Current
[ "Select whether to pretty-print SAWCore terms using color." ]

, prim "set_min_sharing" "Int -> TopLevel ()"
(pureVal set_min_sharing)
Current
[ "Set the number times a subterm must be shared for it to be"
, "let-bound in printer output." ]

, prim "set_timeout" "Int -> ProofScript ()"
(pureVal set_timeout)
Experimental
Expand Down
4 changes: 3 additions & 1 deletion src/SAWScript/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ data PPOpts = PPOpts
, ppOptsAscii :: Bool
, ppOptsBase :: Int
, ppOptsColor :: Bool
, ppOptsMinSharing :: Int
}

defaultPPOpts :: PPOpts
defaultPPOpts = PPOpts False False 10 False
defaultPPOpts = PPOpts False False 10 False 2

cryptolPPOpts :: PPOpts -> C.PPOpts
cryptolPPOpts opts =
Expand All @@ -225,6 +226,7 @@ sawPPOpts opts =
SAWCorePP.defaultPPOpts
{ SAWCorePP.ppBase = ppOptsBase opts
, SAWCorePP.ppColor = ppOptsColor opts
, SAWCorePP.ppMinSharing = ppOptsMinSharing opts
}

quietEvalOpts :: C.EvalOpts
Expand Down