Skip to content

Commit 7e56257

Browse files
nlandermichaelpj
andauthored
Remove extra call to newHscEnvEqWithImportPaths (#3676)
* Remove extra call to newHscEnvEqWithImportPaths * Revert "Remove extra call to newHscEnvEqWithImportPaths" This reverts commit 376ada0. * Add updateHscEnvEq helper function * Add comment to updateHscEnvEq call * Update HscEnvEq equality comment --------- Co-authored-by: Michael Peyton Jones <[email protected]>
1 parent d14d9e5 commit 7e56257

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

ghcide/src/Development/IDE/Core/Rules.hs

+6-1
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,12 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
799799
#endif
800800
session' <- liftIO $ mergeEnvs hsc moduleNode inLoadOrder depSessions
801801

802-
Just <$> liftIO (newHscEnvEqWithImportPaths (envImportPaths env) session' [])
802+
-- Here we avoid a call to to `newHscEnvEqWithImportPaths`, which creates a new
803+
-- ExportsMap when it is called. We only need to create the ExportsMap once per
804+
-- session, while `ghcSessionDepsDefinition` will be called for each file we need
805+
-- to compile. `updateHscEnvEq` will refresh the HscEnv (session') and also
806+
-- generate a new Unique.
807+
Just <$> liftIO (updateHscEnvEq env session')
803808

804809
-- | Load a iface from disk, or generate it if there isn't one or it is out of date
805810
-- This rule also ensures that the `.hie` and `.o` (if needed) files are written out.

ghcide/src/Development/IDE/Types/HscEnvEq.hs

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Development.IDE.Types.HscEnvEq
44
hscEnvWithImportPaths,
55
newHscEnvEqPreserveImportPaths,
66
newHscEnvEqWithImportPaths,
7+
updateHscEnvEq,
78
envImportPaths,
89
envPackageExports,
910
envVisibleModuleNames,
@@ -32,7 +33,8 @@ import System.Directory (makeAbsolute)
3233
import System.FilePath
3334

3435
-- | An 'HscEnv' with equality. Two values are considered equal
35-
-- if they are created with the same call to 'newHscEnvEq'.
36+
-- if they are created with the same call to 'newHscEnvEq' or
37+
-- 'updateHscEnvEq'.
3638
data HscEnvEq = HscEnvEq
3739
{ envUnique :: !Unique
3840
, hscEnv :: !HscEnv
@@ -51,6 +53,11 @@ data HscEnvEq = HscEnvEq
5153
-- If Nothing, 'listVisibleModuleNames' panic
5254
}
5355

56+
updateHscEnvEq :: HscEnvEq -> HscEnv -> IO HscEnvEq
57+
updateHscEnvEq oldHscEnvEq newHscEnv = do
58+
let update newUnique = oldHscEnvEq { envUnique = newUnique, hscEnv = newHscEnv }
59+
update <$> Unique.newUnique
60+
5461
-- | Wrap an 'HscEnv' into an 'HscEnvEq'.
5562
newHscEnvEq :: FilePath -> HscEnv -> [(UnitId, DynFlags)] -> IO HscEnvEq
5663
newHscEnvEq cradlePath hscEnv0 deps = do

0 commit comments

Comments
 (0)