Skip to content

Commit

Permalink
Add a command to clear the SAWCore term cache.
Browse files Browse the repository at this point in the history
This cache is used for hash-consing.  It shouldn't affect
correctness to clear it, although it may make hash-consing
less effective.
  • Loading branch information
robdockins committed Jun 21, 2022
1 parent 63c6a0f commit 24def9b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions saw-core/src/Verifier/SAW/SharedTerm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module Verifier.SAW.SharedTerm
, SharedContext
, mkSharedContext
, scGetModuleMap
, scClearTermCache
-- ** Low-level generic term constructors
, scTermF
, scFlatTermF
Expand Down Expand Up @@ -358,6 +359,7 @@ data SharedContext = SharedContext
, scNamingEnv :: IORef SAWNamingEnv
, scGlobalEnv :: IORef (HashMap Ident Term)
, scFreshGlobalVar :: IO VarIndex
, scClearTermCache :: IO ()
}

-- | Create a new term from a lower-level 'FlatTermF' term.
Expand Down Expand Up @@ -2331,6 +2333,7 @@ mkSharedContext = do
, scFreshGlobalVar = freshGlobalVar
, scNamingEnv = envRef
, scGlobalEnv = gr
, scClearTermCache = modifyMVar cr (\_ -> return (emptyAppCache , ()))
}

useChangeCache :: C m => Cache m k (Change v) -> k -> ChangeT m v -> ChangeT m v
Expand Down
5 changes: 5 additions & 0 deletions src/SAWScript/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ getTopLevelPPOpts = do
opts <- fmap rwPPOpts getTopLevelRW
return (SV.sawPPOpts opts)

clear_term_cache :: TopLevel ()
clear_term_cache =
do sc <- getSharedContext
io $ scClearTermCache sc

show_term :: Term -> TopLevel String
show_term t =
do opts <- getTopLevelPPOpts
Expand Down
8 changes: 8 additions & 0 deletions src/SAWScript/Interpreter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,14 @@ primitives = Map.fromList
Current
[ "Return the type of the given term." ]

, prim "clear_term_cache" "TopLevel ()"
(pureVal clear_term_cache)
Experimental
[ "Empty the hash-consing cache for SAWCore terms."
, "This can be useful to help control memory usage, but makes"
, "hash-consing less effective."
]

, prim "show_term" "Term -> String"
(funVal1 show_term)
Current
Expand Down

0 comments on commit 24def9b

Please sign in to comment.