Skip to content
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

Minimal Shake rebuilds #9

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ packages:
./plugins/hls-pragmas-plugin
./plugins/hls-module-name-plugin
./plugins/hls-ormolu-plugin

source-repository-package
type: git
location: https://github.com/pepeiborra/shake.git
tag: 857044d668c9054ac7da6446bc980bcd250eeda3

tests: true

package *
Expand Down
4 changes: 2 additions & 2 deletions ghcide/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ main = do
then Test.plugin
else mempty

,Main.argsIdeOptions = \config sessionLoader ->
let defOptions = defaultIdeOptions sessionLoader
,Main.argsIdeOptions = \config sessionLoader ->
let defOptions = Main.argsIdeOptions def config sessionLoader
in defOptions
{ optShakeProfiling = argsShakeProfiling
, optOTMemoryProfiling = IdeOTMemoryProfiling argsOTMemoryProfiling
Expand Down
5 changes: 3 additions & 2 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,6 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
-- Version of the mappings above
version <- newVar 0
let returnWithVersion fun = IdeGhcSession fun <$> liftIO (readVar version)
let invalidateShakeCache = do
void $ modifyVar' version succ
-- This caches the mapping from Mod.hs -> hie.yaml
cradleLoc <- liftIO $ memoIO $ \v -> do
res <- findCradle v
Expand All @@ -253,6 +251,9 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
return $ do
extras@ShakeExtras{logger, restartShakeSession, ideNc, knownTargetsVar, lspEnv
} <- getShakeExtras
let invalidateShakeCache = do
void $ modifyVar' version succ
recordDirtyKeys extras GhcSessionIO [emptyFilePath]

IdeOptions{ optTesting = IdeTesting optTesting
, optCheckProject = getCheckProject
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Development.IDE.Core.FileExists as X (getFileExists)
import Development.IDE.Core.FileStore as X (getFileContents)
import Development.IDE.Core.IdeConfiguration as X (IdeConfiguration (..),
isWorkspaceFile)
import Development.IDE.Core.OfInterest as X (getFilesOfInterest)
import Development.IDE.Core.OfInterest as X (getFilesOfInterestUntracked)
import Development.IDE.Core.RuleTypes as X
import Development.IDE.Core.Rules as X (IsHiFileStable (..),
getClientConfigAction,
Expand Down
2 changes: 1 addition & 1 deletion ghcide/src/Development/IDE/Core/Actions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ highlightAtPoint file pos = runMaybeT $ do
refsAtPoint :: NormalizedFilePath -> Position -> Action [Location]
refsAtPoint file pos = do
ShakeExtras{hiedb} <- getShakeExtras
fs <- HM.keys <$> getFilesOfInterest
fs <- HM.keys <$> getFilesOfInterestUntracked
asts <- HM.fromList . mapMaybe sequence . zip fs <$> usesWithStale GetHieAst fs
AtPoint.referencesAtPoint hiedb file pos (AtPoint.FOIReferences asts)

Expand Down
27 changes: 12 additions & 15 deletions ghcide/src/Development/IDE/Core/FileExists.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Control.Monad.IO.Class
import qualified Data.ByteString as BS
import Data.HashMap.Strict (HashMap)
import qualified Data.HashMap.Strict as HashMap
import Data.List (partition)
import Data.Maybe
import Development.IDE.Core.FileStore
import Development.IDE.Core.IdeConfiguration
Expand All @@ -25,9 +26,9 @@ import Development.IDE.Core.Shake
import Development.IDE.Graph
import Development.IDE.Types.Location
import Development.IDE.Types.Options
import Ide.Plugin.Config (Config)
import Language.LSP.Server hiding (getVirtualFile)
import Language.LSP.Types
import Language.LSP.Types.Capabilities
import qualified System.Directory as Dir
import qualified System.FilePath.Glob as Glob

Expand Down Expand Up @@ -91,22 +92,25 @@ modifyFileExists :: IdeState -> [FileEvent] -> IO ()
modifyFileExists state changes = do
FileExistsMapVar var <- getIdeGlobalState state
changesMap <- evaluate $ HashMap.fromList $
[ (toNormalizedFilePath' f, newState)
[ (toNormalizedFilePath' f, change)
| FileEvent uri change <- changes
, Just f <- [uriToFilePath uri]
, Just newState <- [fromChange change]
]
-- Masked to ensure that the previous values are flushed together with the map update
mask $ \_ -> do
-- update the map
void $ modifyVar' var $ HashMap.union changesMap
void $ modifyVar' var $ HashMap.union (HashMap.mapMaybe fromChange changesMap)
-- See Note [Invalidating file existence results]
-- flush previous values
mapM_ (deleteValue (shakeExtras state) GetFileExists) (HashMap.keys changesMap)
let (fileModifChanges, fileExistChanges) =
partition ((== FcChanged) . snd) (HashMap.toList changesMap)
recordDirtyKeys (shakeExtras state) GetFileExists $ map fst fileExistChanges
recordDirtyKeys (shakeExtras state) GetModificationTime $ map fst fileModifChanges

fromChange :: FileChangeType -> Maybe Bool
fromChange FcCreated = Just True
fromChange FcDeleted = Just True
fromChange FcDeleted = Just False
fromChange FcChanged = Nothing

-------------------------------------------------------------------------------------
Expand Down Expand Up @@ -153,18 +157,11 @@ allExtensions opts = [extIncBoot | ext <- optExtensions opts, extIncBoot <- [ext
-- | Installs the 'getFileExists' rules.
-- Provides a fast implementation if client supports dynamic watched files.
-- Creates a global state as a side effect in that case.
fileExistsRules :: Maybe (LanguageContextEnv c) -> VFSHandle -> Rules ()
fileExistsRules :: Maybe (LanguageContextEnv Config) -> VFSHandle -> Rules ()
fileExistsRules lspEnv vfs = do
supportsWatchedFiles <- case lspEnv of
Just lspEnv' -> liftIO $ runLspT lspEnv' $ do
ClientCapabilities {_workspace} <- getClientCapabilities
case () of
_ | Just WorkspaceClientCapabilities{_didChangeWatchedFiles} <- _workspace
, Just DidChangeWatchedFilesClientCapabilities{_dynamicRegistration} <- _didChangeWatchedFiles
, Just True <- _dynamicRegistration
-> pure True
_ -> pure False
Nothing -> pure False
Nothing -> pure False
Just lspEnv' -> liftIO $ runLspT lspEnv' isWatchSupported
-- Create the global always, although it should only be used if we have fast rules.
-- But there's a chance someone will send unexpected notifications anyway,
-- e.g. https://github.com/haskell/ghcide/issues/599
Expand Down
Loading