From 209061f9e563c4cedccc576109bbfe8e4a787c9d Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Tue, 15 Mar 2022 19:13:00 +0000 Subject: [PATCH] Fix 2 space leaks (#2774) * Fix a space leak in hls-graph * Fix leak in ExportsMap and optimize --- ghcide/src/Development/IDE/Types/Exports.hs | 12 +++++------- .../src/Development/IDE/Graph/Internal/Types.hs | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ghcide/src/Development/IDE/Types/Exports.hs b/ghcide/src/Development/IDE/Types/Exports.hs index 539444a642a..f66167a6887 100644 --- a/ghcide/src/Development/IDE/Types/Exports.hs +++ b/ghcide/src/Development/IDE/Types/Exports.hs @@ -22,7 +22,7 @@ import qualified Data.HashMap.Strict as Map import Data.HashSet (HashSet) import qualified Data.HashSet as Set import Data.Hashable (Hashable) -import Data.List (isSuffixOf) +import Data.List (isSuffixOf, foldl') import Data.Text (Text, pack) import Development.IDE.GHC.Compat import Development.IDE.GHC.Orphans () @@ -32,8 +32,8 @@ import HieDb data ExportsMap = ExportsMap - { getExportsMap :: HashMap IdentifierText (HashSet IdentInfo) - , getModuleExportsMap :: HashMap ModuleNameText (HashSet IdentInfo) + { getExportsMap :: !(HashMap IdentifierText (HashSet IdentInfo)) + , getModuleExportsMap :: !(HashMap ModuleNameText (HashSet IdentInfo)) } deriving (Show) @@ -134,13 +134,11 @@ createExportsMapMg modGuts = do concatMap (fmap (second Set.fromList) . unpackAvail getModuleName) (mg_exports mi) updateExportsMapMg :: [ModGuts] -> ExportsMap -> ExportsMap -updateExportsMapMg modGuts old = - old' <> new +updateExportsMapMg modGuts old = old' <> new where new = createExportsMapMg modGuts old' = deleteAll old (Map.keys $ getModuleExportsMap new) - deleteAll = foldr deleteEntriesForModule - + deleteAll = foldl' (flip deleteEntriesForModule) createExportsMapTc :: [TcGblEnv] -> ExportsMap createExportsMapTc modIface = do diff --git a/hls-graph/src/Development/IDE/Graph/Internal/Types.hs b/hls-graph/src/Development/IDE/Graph/Internal/Types.hs index 5a37ade6a9b..02a11293904 100644 --- a/hls-graph/src/Development/IDE/Graph/Internal/Types.hs +++ b/hls-graph/src/Development/IDE/Graph/Internal/Types.hs @@ -120,12 +120,12 @@ getDatabaseValues = atomically . databaseValues data Status - = Clean Result + = Clean !Result | Dirty (Maybe Result) | Running { runningStep :: !Step, runningWait :: !(IO ()), - runningResult :: Result, + runningResult :: Result, -- LAZY runningPrev :: !(Maybe Result) } @@ -145,7 +145,7 @@ data Result = Result { resultVisited :: !Step, -- ^ the step when it was last looked up resultDeps :: !ResultDeps, resultExecution :: !Seconds, -- ^ How long it took, last time it ran - resultData :: BS.ByteString + resultData :: !BS.ByteString } data ResultDeps = UnknownDeps | AlwaysRerunDeps ![Key] | ResultDeps ![Key]