Skip to content

Improve memory characteristics of ExportsMap #3231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Core/Shake.hs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ shakeOpen recorder lspEnv defaultConfig idePlugins logger debouncer
let readValuesCounter = fromIntegral . countRelevantKeys checkParents <$> getStateKeys shakeExtras
readDirtyKeys = fromIntegral . countRelevantKeys checkParents . toListKeySet <$> readTVarIO(dirtyKeys shakeExtras)
readIndexPending = fromIntegral . HMap.size <$> readTVarIO (indexPending $ hiedbWriter shakeExtras)
readExportsMap = fromIntegral . HMap.size . getExportsMap <$> readTVarIO (exportsMap shakeExtras)
readExportsMap = fromIntegral . ExportsMap.exportsMapSize <$> readTVarIO (exportsMap shakeExtras)
readDatabaseCount = fromIntegral . countRelevantKeys checkParents . map fst <$> shakeGetDatabaseKeys shakeDb
readDatabaseStep = fromIntegral <$> shakeGetBuildStep shakeDb

Expand Down
11 changes: 11 additions & 0 deletions ghcide/src/Development/IDE/GHC/Compat.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ module Development.IDE.GHC.Compat(
#endif

FastStringCompat,
bytesFS,
mkFastStringByteString,
nodeInfo',
getNodeIds,
sourceNodeInfo,
Expand All @@ -53,6 +55,8 @@ module Development.IDE.GHC.Compat(
mkAstNode,
combineRealSrcSpans,

nonDetOccEnvElts,

isQualifiedImport,
GhcVersion(..),
ghcVersion,
Expand Down Expand Up @@ -206,6 +210,7 @@ import VarEnv (emptyInScopeSet,
#endif

#if MIN_VERSION_ghc(9,0,0)
import GHC.Data.FastString
import GHC.Core
import GHC.Data.StringBuffer
import GHC.Driver.Session hiding (ExposePackage)
Expand All @@ -224,6 +229,7 @@ import GHC.Iface.Make (mkIfaceExports)
import qualified GHC.SysTools.Tasks as SysTools
import qualified GHC.Types.Avail as Avail
#else
import FastString
import qualified Avail
import DynFlags hiding (ExposePackage)
import HscTypes
Expand Down Expand Up @@ -264,6 +270,11 @@ import GHC.Types.Error
import GHC.Driver.Config.Stg.Pipeline
#endif

#if !MIN_VERSION_ghc(9,3,0)
nonDetOccEnvElts :: OccEnv a -> [a]
nonDetOccEnvElts = occEnvElts
#endif

type ModIfaceAnnotation = Annotation

#if MIN_VERSION_ghc(9,3,0)
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Plugin/Completions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ getCompletionsLSP ide plId
let exportsMap = fromMaybe mempty packageExportsMap <> projectExportsMap

let moduleExports = getModuleExportsMap exportsMap
exportsCompItems = foldMap (map (fromIdentInfo uri) . Set.toList) . Map.elems . getExportsMap $ exportsMap
exportsCompItems = foldMap (map (fromIdentInfo uri) . Set.toList) . nonDetOccEnvElts . getExportsMap $ exportsMap
exportsCompls = mempty{anyQualCompls = exportsCompItems}
let compls = (fst <$> localCompls) <> (fst <$> nonLocalCompls) <> Just exportsCompls <> Just lModules

Expand Down
28 changes: 15 additions & 13 deletions ghcide/src/Development/IDE/Plugin/Completions/Logic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -287,25 +287,27 @@ mkExtCompl label =


fromIdentInfo :: Uri -> IdentInfo -> Maybe T.Text -> CompItem
fromIdentInfo doc IdentInfo{..} q = CI
fromIdentInfo doc id@IdentInfo{..} q = CI
{ compKind= occNameToComKind name
, insertText=rendered
, provenance = DefinedIn moduleNameText
, label=rendered
, insertText=rend
, provenance = DefinedIn mod
, label=rend
, typeText = Nothing
, isInfix=Nothing
, isTypeCompl= not isDatacon && isUpper (T.head rendered)
, isTypeCompl= not (isDatacon id) && isUpper (T.head rend)
, additionalTextEdits= Just $
ExtendImport
{ doc,
thingParent = parent,
importName = moduleNameText,
thingParent = occNameText <$> parent,
importName = mod,
importQual = q,
newThing = rendered
newThing = rend
}
, nameDetails = Nothing
, isLocalCompletion = False
}
where rend = rendered id
mod = moduleNameText id

cacheDataProducer :: Uri -> [ModuleName] -> Module -> GlobalRdrEnv-> GlobalRdrEnv -> [LImportDecl GhcPs] -> CachedCompletions
cacheDataProducer uri visibleMods curMod globalEnv inScopeEnv limports =
Expand Down Expand Up @@ -528,7 +530,7 @@ getCompletions
-> PosPrefixInfo
-> ClientCapabilities
-> CompletionsConfig
-> HM.HashMap T.Text (HashSet.HashSet IdentInfo)
-> ModuleNameEnv (HashSet.HashSet IdentInfo)
-> Uri
-> IO [Scored CompletionItem]
getCompletions plugins ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls, qualCompls, importableModules}
Expand Down Expand Up @@ -660,10 +662,10 @@ getCompletions plugins ideOpts CC {allModNamesAsNS, anyQualCompls, unqualCompls,
&& (List.length (words (T.unpack fullLine)) >= 2)
&& "(" `isInfixOf` T.unpack fullLine
-> do
let moduleName = T.pack $ words (T.unpack fullLine) !! 1
funcs = HM.lookupDefault HashSet.empty moduleName moduleExportsMap
funs = map (show . name) $ HashSet.toList funcs
return $ filterModuleExports moduleName $ map T.pack funs
let moduleName = words (T.unpack fullLine) !! 1
funcs = lookupWithDefaultUFM moduleExportsMap HashSet.empty $ mkModuleName moduleName
funs = map (renderOcc . name) $ HashSet.toList funcs
return $ filterModuleExports (T.pack moduleName) funs
| "import " `T.isPrefixOf` fullLine
-> return filtImportCompls
-- we leave this condition here to avoid duplications and return empty list
Expand Down
Loading