From efa6db51f59db694e34820f2bf73b12ed0ee3ed6 Mon Sep 17 00:00:00 2001 From: Brian Huffman Date: Fri, 11 Sep 2020 16:08:01 -0700 Subject: [PATCH] Deepseq the result of typechecking a module to avoid a space leak. Previously, unevaluated `apSubst` thunks were retaining copies of a very large `Subst` value. Fixes #888. --- src/Cryptol/TypeCheck.hs | 10 +++++++++- src/Cryptol/TypeCheck/Monad.hs | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Cryptol/TypeCheck.hs b/src/Cryptol/TypeCheck.hs index d12d87e44..1add1e364 100644 --- a/src/Cryptol/TypeCheck.hs +++ b/src/Cryptol/TypeCheck.hs @@ -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 @@ -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. diff --git a/src/Cryptol/TypeCheck/Monad.hs b/src/Cryptol/TypeCheck/Monad.hs index f050e22cf..225c41ced 100644 --- a/src/Cryptol/TypeCheck/Monad.hs +++ b/src/Cryptol/TypeCheck/Monad.hs @@ -105,7 +105,7 @@ data InferOutput a -- ^ Type inference was successful. - deriving Show + deriving (Show, Generic, NFData) bumpCounter :: InferM () bumpCounter = do RO { .. } <- IM ask