From 9907fa788d6c0a4ad31b3728c35039ec207aacf8 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Tue, 23 Feb 2021 22:55:49 +0000 Subject: [PATCH 1/6] Customize the unitId used for the internal component --- ghcide/session-loader/Development/IDE/Session.hs | 12 ++++++++---- ghcide/src/Development/IDE/Types/Options.hs | 3 +++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ghcide/session-loader/Development/IDE/Session.hs b/ghcide/session-loader/Development/IDE/Session.hs index 286eec87ee..9ee74398e9 100644 --- a/ghcide/session-loader/Development/IDE/Session.hs +++ b/ghcide/session-loader/Development/IDE/Session.hs @@ -225,6 +225,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do , optCheckProject = getCheckProject , optCustomDynFlags , optExtensions + , optFakeUid } <- getIdeOptions -- populate the knownTargetsVar with all the @@ -277,7 +278,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do new_deps' <- forM new_deps $ \RawComponentInfo{..} -> do -- Remove all inplace dependencies from package flags for -- components in this HscEnv - let (df2, uids) = removeInplacePackages inplace rawComponentDynFlags + let (df2, uids) = removeInplacePackages optFakeUid inplace rawComponentDynFlags let prefix = show rawComponentUnitId -- See Note [Avoiding bad interface files] let hscComponents = sort $ map show uids @@ -716,12 +717,15 @@ getDependencyInfo fs = Map.fromList <$> mapM do_one fs -- There are several places in GHC (for example the call to hptInstances in -- tcRnImports) which assume that all modules in the HPT have the same unit -- ID. Therefore we create a fake one and give them all the same unit id. -removeInplacePackages :: [InstalledUnitId] -> DynFlags -> (DynFlags, [InstalledUnitId]) -removeInplacePackages us df = (df { packageFlags = ps +removeInplacePackages + :: InstalledUnitId -- ^ fake uid to use for our internal component + -> [InstalledUnitId] + -> DynFlags + -> (DynFlags, [InstalledUnitId]) +removeInplacePackages fake_uid us df = (df { packageFlags = ps , thisInstalledUnitId = fake_uid }, uids) where (uids, ps) = partitionEithers (map go (packageFlags df)) - fake_uid = toInstalledUnitId (stringToUnitId "fake_uid") go p@(ExposePackage _ (UnitIdArg u) _) = if toInstalledUnitId u `elem` us then Left (toInstalledUnitId u) else Right p diff --git a/ghcide/src/Development/IDE/Types/Options.hs b/ghcide/src/Development/IDE/Types/Options.hs index 24e96a7435..f47a32e260 100644 --- a/ghcide/src/Development/IDE/Types/Options.hs +++ b/ghcide/src/Development/IDE/Types/Options.hs @@ -85,6 +85,8 @@ data IdeOptions = IdeOptions -- ^ Will be called right after setting up a new cradle, -- allowing to customize the Ghc options used , optShakeOptions :: ShakeOptions + , optFakeUid :: InstalledUnitId + -- ^ unit id used to tag the internal component built by ghcide } optShakeFiles :: IdeOptions -> Maybe FilePath @@ -137,6 +139,7 @@ defaultIdeOptions session = IdeOptions ,optCheckParents = pure CheckOnSaveAndClose ,optHaddockParse = HaddockParse ,optCustomDynFlags = id + ,optFakeUid = toInstalledUnitId (stringToUnitId "fake_uid") } From d9907618a16cf4795b230ee5e8e197b6ea18c05a Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Wed, 24 Feb 2021 10:20:38 +0000 Subject: [PATCH 2/6] add comment --- ghcide/src/Development/IDE/Types/Options.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ghcide/src/Development/IDE/Types/Options.hs b/ghcide/src/Development/IDE/Types/Options.hs index f47a32e260..db83346c8d 100644 --- a/ghcide/src/Development/IDE/Types/Options.hs +++ b/ghcide/src/Development/IDE/Types/Options.hs @@ -87,6 +87,9 @@ data IdeOptions = IdeOptions , optShakeOptions :: ShakeOptions , optFakeUid :: InstalledUnitId -- ^ unit id used to tag the internal component built by ghcide + -- To reuse external interface files the unit ids must match, + -- thus make sure to build them with `--this-unit-id` set to the + -- same value as the ghcide fake uid } optShakeFiles :: IdeOptions -> Maybe FilePath From affaa5d74770f6128f9fc97f2897d3a144008d60 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Wed, 24 Feb 2021 11:10:15 +0000 Subject: [PATCH 3/6] change default fake uid to "main" --- ghcide/src/Development/IDE/Types/Options.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ghcide/src/Development/IDE/Types/Options.hs b/ghcide/src/Development/IDE/Types/Options.hs index db83346c8d..ebb6946f3d 100644 --- a/ghcide/src/Development/IDE/Types/Options.hs +++ b/ghcide/src/Development/IDE/Types/Options.hs @@ -142,7 +142,7 @@ defaultIdeOptions session = IdeOptions ,optCheckParents = pure CheckOnSaveAndClose ,optHaddockParse = HaddockParse ,optCustomDynFlags = id - ,optFakeUid = toInstalledUnitId (stringToUnitId "fake_uid") + ,optFakeUid = toInstalledUnitId (stringToUnitId "main") } From abc412316fbd1cb1a38908b641b972b597380d8e Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Sat, 27 Feb 2021 10:36:44 +0000 Subject: [PATCH 4/6] move config setting to session loading options (where it really belongs) --- ghcide/session-loader/Development/IDE/Session.hs | 9 +++++++-- ghcide/src/Development/IDE/Types/Options.hs | 6 ------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ghcide/session-loader/Development/IDE/Session.hs b/ghcide/session-loader/Development/IDE/Session.hs index 9ee74398e9..85a6e67898 100644 --- a/ghcide/session-loader/Development/IDE/Session.hs +++ b/ghcide/session-loader/Development/IDE/Session.hs @@ -103,6 +103,11 @@ data SessionLoadingOptions = SessionLoadingOptions , getCacheDirs :: String -> [String] -> IO CacheDirs -- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags' , getInitialGhcLibDir :: IO (Maybe LibDir) + , fakeUid :: InstalledUnitId + -- ^ unit id used to tag the internal component built by ghcide + -- To reuse external interface files the unit ids must match, + -- thus make sure to build them with `--this-unit-id` set to the + -- same value as the ghcide fake uid } instance Default SessionLoadingOptions where @@ -111,6 +116,7 @@ instance Default SessionLoadingOptions where ,loadCradle = HieBios.loadCradle ,getCacheDirs = getCacheDirsDefault ,getInitialGhcLibDir = getInitialGhcLibDirDefault + ,fakeUid = toInstalledUnitId (stringToUnitId "main") } getInitialGhcLibDirDefault :: IO (Maybe LibDir) @@ -225,7 +231,6 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do , optCheckProject = getCheckProject , optCustomDynFlags , optExtensions - , optFakeUid } <- getIdeOptions -- populate the knownTargetsVar with all the @@ -278,7 +283,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do new_deps' <- forM new_deps $ \RawComponentInfo{..} -> do -- Remove all inplace dependencies from package flags for -- components in this HscEnv - let (df2, uids) = removeInplacePackages optFakeUid inplace rawComponentDynFlags + let (df2, uids) = removeInplacePackages fakeUid inplace rawComponentDynFlags let prefix = show rawComponentUnitId -- See Note [Avoiding bad interface files] let hscComponents = sort $ map show uids diff --git a/ghcide/src/Development/IDE/Types/Options.hs b/ghcide/src/Development/IDE/Types/Options.hs index ebb6946f3d..24e96a7435 100644 --- a/ghcide/src/Development/IDE/Types/Options.hs +++ b/ghcide/src/Development/IDE/Types/Options.hs @@ -85,11 +85,6 @@ data IdeOptions = IdeOptions -- ^ Will be called right after setting up a new cradle, -- allowing to customize the Ghc options used , optShakeOptions :: ShakeOptions - , optFakeUid :: InstalledUnitId - -- ^ unit id used to tag the internal component built by ghcide - -- To reuse external interface files the unit ids must match, - -- thus make sure to build them with `--this-unit-id` set to the - -- same value as the ghcide fake uid } optShakeFiles :: IdeOptions -> Maybe FilePath @@ -142,7 +137,6 @@ defaultIdeOptions session = IdeOptions ,optCheckParents = pure CheckOnSaveAndClose ,optHaddockParse = HaddockParse ,optCustomDynFlags = id - ,optFakeUid = toInstalledUnitId (stringToUnitId "main") } From 5aabcacdb489bad0781bc82e9fcf8da9e75261ca Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Sat, 27 Feb 2021 10:40:56 +0000 Subject: [PATCH 5/6] hiedb versioning --- ghcide/session-loader/Development/IDE/Session.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ghcide/session-loader/Development/IDE/Session.hs b/ghcide/session-loader/Development/IDE/Session.hs index 85a6e67898..e725c6acc4 100644 --- a/ghcide/session-loader/Development/IDE/Session.hs +++ b/ghcide/session-loader/Development/IDE/Session.hs @@ -90,6 +90,9 @@ import HieDb.Types import HieDb.Utils import Maybes (MaybeT (runMaybeT)) +-- | Bump this version number when making changes to the format of the data stored in hiedb +hiedbDataVersion :: String +hiedbDataVersion = "1" data CacheDirs = CacheDirs { hiCacheDir, hieCacheDir, oCacheDir :: Maybe FilePath} @@ -173,7 +176,7 @@ runWithDb fp k = do getHieDbLoc :: FilePath -> IO FilePath getHieDbLoc dir = do - let db = dirHash++"-"++takeBaseName dir++"-"++VERSION_ghc <.> "hiedb" + let db = intercalate "-" [dirHash, takeBaseName dir, VERSION_ghc, hiedbDataVersion] <.> "hiedb" dirHash = B.unpack $ B16.encode $ H.hash $ B.pack dir cDir <- IO.getXdgDirectory IO.XdgCache cacheDir createDirectoryIfMissing True cDir From 26bd4e7d2c7b55de96cb6c72cbc9d1c9a507b8e3 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Sat, 27 Feb 2021 10:44:08 +0000 Subject: [PATCH 6/6] (unrelated) fix some progress messages --- ghcide/src/Development/IDE/Core/Compile.hs | 2 +- ghcide/src/Development/IDE/Core/Rules.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ghcide/src/Development/IDE/Core/Compile.hs b/ghcide/src/Development/IDE/Core/Compile.hs index 1e007b6ccc..f8fdcd36c4 100644 --- a/ghcide/src/Development/IDE/Core/Compile.hs +++ b/ghcide/src/Development/IDE/Core/Compile.hs @@ -571,7 +571,7 @@ indexHieFile se mod_summary srcPath hash hf = atomically $ do LSP.sendNotification LSP.SProgress $ LSP.ProgressParams tok $ LSP.Report $ LSP.WorkDoneProgressReportParams { _cancellable = Nothing - , _message = Just $ T.pack (show srcPath) <> progress + , _message = Just $ T.pack (fromNormalizedFilePath srcPath) <> progress , _percentage = Nothing } diff --git a/ghcide/src/Development/IDE/Core/Rules.hs b/ghcide/src/Development/IDE/Core/Rules.hs index 0846593bdc..c307a9c1b0 100644 --- a/ghcide/src/Development/IDE/Core/Rules.hs +++ b/ghcide/src/Development/IDE/Core/Rules.hs @@ -842,7 +842,7 @@ getModIfaceFromDiskAndIndexRule = defineEarlyCutoff $ \GetModIfaceFromDiskAndInd Left err -> fail $ "failed to read .hie file " ++ show hie_loc ++ ": " ++ displayException err -- can just re-index the file we read from disk Right hf -> liftIO $ do - L.logDebug (logger se) $ "Re-indexing hie file for" <> T.pack (show f) + L.logDebug (logger se) $ "Re-indexing hie file for" <> T.pack (fromNormalizedFilePath f) indexHieFile se ms f hash hf let fp = hiFileFingerPrint x