Skip to content

Commit

Permalink
Deepseq the result of typechecking a module to avoid a space leak.
Browse files Browse the repository at this point in the history
Previously, unevaluated `apSubst` thunks were retaining copies of
a very large `Subst` value.

Fixes #888.
  • Loading branch information
Brian Huffman committed Sep 11, 2020
1 parent 8d7df1c commit efa6db5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Cryptol/TypeCheck.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module Cryptol.TypeCheck
, ppError
) where

import Control.DeepSeq

import Cryptol.ModuleSystem.Name
(liftSupply,mkDeclared,NameSource(..))
import qualified Cryptol.Parser.AST as P
Expand All @@ -48,7 +50,13 @@ import Cryptol.Utils.PP
import Cryptol.Utils.Panic(panic)

tcModule :: P.Module Name -> InferInput -> IO (InferOutput Module)
tcModule m inp = runInferM inp (inferModule m)
tcModule m inp =
do output <- runInferM inp (inferModule m)
-- Evaluate the result (including the module itself and also
-- warnings) to normal form to ensure that all uses of 'apSubst'
-- are fully evaluated and the (possibly very large) substitution
-- itself can be garbage collected.
pure $!! output

-- | Check a module instantiation, assuming that the functor has already
-- been checked.
Expand Down
2 changes: 1 addition & 1 deletion src/Cryptol/TypeCheck/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ data InferOutput a
-- ^ Type inference was successful.


deriving Show
deriving (Show, Generic, NFData)

bumpCounter :: InferM ()
bumpCounter = do RO { .. } <- IM ask
Expand Down

0 comments on commit efa6db5

Please sign in to comment.