From 032d7d78ca845983c334471a0583c0bf8165c3bf Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Thu, 20 Jun 2019 15:46:22 +0200 Subject: [PATCH 1/2] Fix a memory leak found by mpickering --- hie-plugin-api/Haskell/Ide/Engine/ModuleCache.hs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hie-plugin-api/Haskell/Ide/Engine/ModuleCache.hs b/hie-plugin-api/Haskell/Ide/Engine/ModuleCache.hs index aa80778d2..6f7dad940 100644 --- a/hie-plugin-api/Haskell/Ide/Engine/ModuleCache.hs +++ b/hie-plugin-api/Haskell/Ide/Engine/ModuleCache.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE BangPatterns #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE FlexibleContexts #-} @@ -53,7 +54,8 @@ import Haskell.Ide.Engine.PluginsIdeMonads modifyCache :: (HasGhcModuleCache m) => (GhcModuleCache -> GhcModuleCache) -> m () modifyCache f = do mc <- getModuleCache - setModuleCache (f mc) + let !cached = f mc -- Avoid a space leak by forcing the cache calculation + setModuleCache cached -- --------------------------------------------------------------------- -- | Runs an IdeM action with the given Cradle From b7fb445fa51154dcaac715094586cb1bdbe9e0ed Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Fri, 21 Jun 2019 09:50:55 +0200 Subject: [PATCH 2/2] Making setCache strict in it's first argument instead --- hie-plugin-api/Haskell/Ide/Engine/ModuleCache.hs | 4 +--- hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/hie-plugin-api/Haskell/Ide/Engine/ModuleCache.hs b/hie-plugin-api/Haskell/Ide/Engine/ModuleCache.hs index 6f7dad940..aa80778d2 100644 --- a/hie-plugin-api/Haskell/Ide/Engine/ModuleCache.hs +++ b/hie-plugin-api/Haskell/Ide/Engine/ModuleCache.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE BangPatterns #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE FlexibleContexts #-} @@ -54,8 +53,7 @@ import Haskell.Ide.Engine.PluginsIdeMonads modifyCache :: (HasGhcModuleCache m) => (GhcModuleCache -> GhcModuleCache) -> m () modifyCache f = do mc <- getModuleCache - let !cached = f mc -- Avoid a space leak by forcing the cache calculation - setModuleCache cached + setModuleCache (f mc) -- --------------------------------------------------------------------- -- | Runs an IdeM action with the given Cradle diff --git a/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs b/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs index 468d9cbce..06bf7b7eb 100644 --- a/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs +++ b/hie-plugin-api/Haskell/Ide/Engine/PluginsIdeMonads.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE BangPatterns #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveAnyClass #-} @@ -499,7 +500,7 @@ instance HasGhcModuleCache IdeM where tvar <- lift ask state <- liftIO $ readTVarIO tvar return (moduleCache state) - setModuleCache mc = do + setModuleCache !mc = do tvar <- lift ask liftIO $ atomically $ modifyTVar' tvar (\st -> st { moduleCache = mc })