@@ -90,6 +90,9 @@ import HieDb.Types
90
90
import HieDb.Utils
91
91
import Maybes (MaybeT (runMaybeT ))
92
92
93
+ -- | Bump this version number when making changes to the format of the data stored in hiedb
94
+ hiedbDataVersion :: String
95
+ hiedbDataVersion = " 1"
93
96
94
97
data CacheDirs = CacheDirs
95
98
{ hiCacheDir , hieCacheDir , oCacheDir :: Maybe FilePath }
@@ -103,6 +106,11 @@ data SessionLoadingOptions = SessionLoadingOptions
103
106
, getCacheDirs :: String -> [String ] -> IO CacheDirs
104
107
-- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags'
105
108
, getInitialGhcLibDir :: IO (Maybe LibDir )
109
+ , fakeUid :: InstalledUnitId
110
+ -- ^ unit id used to tag the internal component built by ghcide
111
+ -- To reuse external interface files the unit ids must match,
112
+ -- thus make sure to build them with `--this-unit-id` set to the
113
+ -- same value as the ghcide fake uid
106
114
}
107
115
108
116
instance Default SessionLoadingOptions where
@@ -111,6 +119,7 @@ instance Default SessionLoadingOptions where
111
119
,loadCradle = HieBios. loadCradle
112
120
,getCacheDirs = getCacheDirsDefault
113
121
,getInitialGhcLibDir = getInitialGhcLibDirDefault
122
+ ,fakeUid = toInstalledUnitId (stringToUnitId " main" )
114
123
}
115
124
116
125
getInitialGhcLibDirDefault :: IO (Maybe LibDir )
@@ -167,7 +176,7 @@ runWithDb fp k = do
167
176
168
177
getHieDbLoc :: FilePath -> IO FilePath
169
178
getHieDbLoc dir = do
170
- let db = dirHash ++ " -" ++ takeBaseName dir++ " - " ++ VERSION_ghc <.> " hiedb"
179
+ let db = intercalate " -" [dirHash, takeBaseName dir, VERSION_ghc , hiedbDataVersion] <.> " hiedb"
171
180
dirHash = B. unpack $ B16. encode $ H. hash $ B. pack dir
172
181
cDir <- IO. getXdgDirectory IO. XdgCache cacheDir
173
182
createDirectoryIfMissing True cDir
@@ -277,7 +286,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
277
286
new_deps' <- forM new_deps $ \ RawComponentInfo {.. } -> do
278
287
-- Remove all inplace dependencies from package flags for
279
288
-- components in this HscEnv
280
- let (df2, uids) = removeInplacePackages inplace rawComponentDynFlags
289
+ let (df2, uids) = removeInplacePackages fakeUid inplace rawComponentDynFlags
281
290
let prefix = show rawComponentUnitId
282
291
-- See Note [Avoiding bad interface files]
283
292
let hscComponents = sort $ map show uids
@@ -716,12 +725,15 @@ getDependencyInfo fs = Map.fromList <$> mapM do_one fs
716
725
-- There are several places in GHC (for example the call to hptInstances in
717
726
-- tcRnImports) which assume that all modules in the HPT have the same unit
718
727
-- ID. Therefore we create a fake one and give them all the same unit id.
719
- removeInplacePackages :: [InstalledUnitId ] -> DynFlags -> (DynFlags , [InstalledUnitId ])
720
- removeInplacePackages us df = (df { packageFlags = ps
728
+ removeInplacePackages
729
+ :: InstalledUnitId -- ^ fake uid to use for our internal component
730
+ -> [InstalledUnitId ]
731
+ -> DynFlags
732
+ -> (DynFlags , [InstalledUnitId ])
733
+ removeInplacePackages fake_uid us df = (df { packageFlags = ps
721
734
, thisInstalledUnitId = fake_uid }, uids)
722
735
where
723
736
(uids, ps) = partitionEithers (map go (packageFlags df))
724
- fake_uid = toInstalledUnitId (stringToUnitId " fake_uid" )
725
737
go p@ (ExposePackage _ (UnitIdArg u) _) = if toInstalledUnitId u `elem` us
726
738
then Left (toInstalledUnitId u)
727
739
else Right p
0 commit comments