on master help sign in
Use a separate finder cache for each typecheck call (#148)

* Use a separate finder cache for each typecheck call On a large DAML project, we occasionally saw error about missing modules during typechecking during concurrent compilations. This was caused by the fact that we modified the IORef in the HscEnv which is shared between concurrent compilations.

commited6cf474d3422e2b260311fb78cace1ccbd4dbed authorMoritz Kiefer <moritz.kiefer@purelyfunctional.org> dateWed 2 Oct 2019, 13:58 (7 years ago) parent986bc04
2 files changed+21−7
azure-pipelines.yml+12−4 src/Development/IDE/Core/Compile.hs+9−3
azure-pipelines.yml+12−4
@@ -35,7 +35,9 @@ jobs:
3535 displayName: "HLint via ./fmt.sh"
3636 - bash: |
3737 sudo apt-get install -y g++ gcc libc6-dev libffi-dev libgmp-dev make zlib1g-dev
38− curl -sSL https://get.haskellstack.org/ | sh
38+ if ! which stack >/dev/null 2>&1; then
39+ curl -sSL https://get.haskellstack.org/ | sh
40+ fi
3941 displayName: 'Install Stack'
4042 - bash: stack setup
4143 displayName: 'stack setup'
@@ -79,7 +81,9 @@ jobs:
7981 displayName: "HLint via ./fmt.sh"
8082 - bash: |
8183 sudo apt-get install -y g++ gcc libc6-dev libffi-dev libgmp-dev make zlib1g-dev
82− curl -sSL https://get.haskellstack.org/ | sh
84+ if ! which stack >/dev/null 2>&1; then
85+ curl -sSL https://get.haskellstack.org/ | sh
86+ fi
8387 displayName: 'Install Stack'
8488 - bash: stack setup --stack-yaml=stack84.yaml
8589 displayName: 'stack setup --stack-yaml=stack84.yaml'
@@ -123,7 +127,9 @@ jobs:
123127 displayName: "HLint via ./fmt.sh"
124128 - bash: |
125129 sudo apt-get install -y g++ gcc libc6-dev libffi-dev libgmp-dev make zlib1g-dev
126− curl -sSL https://get.haskellstack.org/ | sh
130+ if ! which stack >/dev/null 2>&1; then
131+ curl -sSL https://get.haskellstack.org/ | sh
132+ fi
127133 displayName: 'Install Stack'
128134 - bash: stack setup --stack-yaml=stack88.yaml
129135 displayName: 'stack setup --stack-yaml=stack88.yaml'
@@ -167,7 +173,9 @@ jobs:
167173 displayName: "HLint via ./fmt.sh"
168174 - bash: |
169175 sudo apt-get install -y g++ gcc libc6-dev libffi-dev libgmp-dev make zlib1g-dev
170− curl -sSL https://get.haskellstack.org/ | sh
176+ if ! which stack >/dev/null 2>&1; then
177+ curl -sSL https://get.haskellstack.org/ | sh
178+ fi
171179 displayName: 'Install Stack'
172180 - bash: stack setup --stack-yaml=stack-ghc-lib.yaml
173181 displayName: 'stack setup --stack-yaml=stack-ghc-lib.yaml'
src/Development/IDE/Core/Compile.hs+9−3
@@ -196,9 +196,15 @@ setupEnv tmsIn = do
196196 -- by putting them in the finder cache.
197197 let ims = map (InstalledModule (thisInstalledUnitId $ hsc_dflags session) . moduleName . ms_mod) mss
198198 ifrs = zipWith (\ms -> InstalledFound (ms_location ms)) mss ims
199− liftIO $ modifyIORef (hsc_FC session) $ \fc ->
200− foldl' (\fc (im, ifr) -> GHC.extendInstalledModuleEnv fc im ifr) fc
201− $ zip ims ifrs
199+ -- We have to create a new IORef here instead of modifying the existing IORef as
200+ -- it is shared between concurrent compilations.
201+ prevFinderCache <- liftIO $ readIORef $ hsc_FC session
202+ let newFinderCache =
203+ foldl'
204+ (\fc (im, ifr) -> GHC.extendInstalledModuleEnv fc im ifr) prevFinderCache
205+ $ zip ims ifrs
206+ newFinderCacheVar <- liftIO $ newIORef $! newFinderCache
207+ modifySession $ \s -> s { hsc_FC = newFinderCacheVar }
202208
203209 -- load dependent modules, which must be in topological order.
204210 mapM_ loadModuleHome tms