Skip to content

Commit

Permalink
Remove extra call to newHscEnvEqWithImportPaths (#3676)
Browse files Browse the repository at this point in the history
* 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 <me@michaelpj.com>
  • Loading branch information
nlander and michaelpj authored Jul 2, 2023
1 parent d14d9e5 commit 7e56257
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 6 additions & 1 deletion ghcide/src/Development/IDE/Core/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,12 @@ ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
#endif
session' <- liftIO $ mergeEnvs hsc moduleNode inLoadOrder depSessions

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

-- | Load a iface from disk, or generate it if there isn't one or it is out of date
-- This rule also ensures that the `.hie` and `.o` (if needed) files are written out.
Expand Down
9 changes: 8 additions & 1 deletion ghcide/src/Development/IDE/Types/HscEnvEq.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Development.IDE.Types.HscEnvEq
hscEnvWithImportPaths,
newHscEnvEqPreserveImportPaths,
newHscEnvEqWithImportPaths,
updateHscEnvEq,
envImportPaths,
envPackageExports,
envVisibleModuleNames,
Expand Down Expand Up @@ -32,7 +33,8 @@ import System.Directory (makeAbsolute)
import System.FilePath

-- | An 'HscEnv' with equality. Two values are considered equal
-- if they are created with the same call to 'newHscEnvEq'.
-- if they are created with the same call to 'newHscEnvEq' or
-- 'updateHscEnvEq'.
data HscEnvEq = HscEnvEq
{ envUnique :: !Unique
, hscEnv :: !HscEnv
Expand All @@ -51,6 +53,11 @@ data HscEnvEq = HscEnvEq
-- If Nothing, 'listVisibleModuleNames' panic
}

updateHscEnvEq :: HscEnvEq -> HscEnv -> IO HscEnvEq
updateHscEnvEq oldHscEnvEq newHscEnv = do
let update newUnique = oldHscEnvEq { envUnique = newUnique, hscEnv = newHscEnv }
update <$> Unique.newUnique

-- | Wrap an 'HscEnv' into an 'HscEnvEq'.
newHscEnvEq :: FilePath -> HscEnv -> [(UnitId, DynFlags)] -> IO HscEnvEq
newHscEnvEq cradlePath hscEnv0 deps = do
Expand Down

0 comments on commit 7e56257

Please sign in to comment.