@@ -33,6 +33,7 @@ import System.FilePath ((</>), (<.>))
3333import qualified AST.Canonical as Can
3434import qualified AST.Source as Src
3535import qualified AST.Optimized as Opt
36+import qualified BackgroundWriter as BW
3637import qualified Compile
3738import qualified Deps.Registry as Registry
3839import qualified Deps.Solver as Solver
@@ -120,11 +121,11 @@ loadInterfaces root (Details _ _ _ _ extras) =
120121-- VERIFY INSTALL -- used by Install
121122
122123
123−verifyInstall :: FilePath -> Solver.Env -> Outline.Outline -> IO (Either Exit.Details ())
124−verifyInstall root (Solver.Env cache manager connection registry) outline =
124+verifyInstall :: BW.Scope -> FilePath -> Solver.Env -> Outline.Outline -> IO (Either Exit.Details ())
125+verifyInstall scope root (Solver.Env cache manager connection registry) outline =
125126 do time <- File.getTime (root </> "elm.json")
126127 let key = Reporting.ignorer
127− let env = Env key root cache manager connection registry
128+ let env = Env key scope root cache manager connection registry
128129 case outline of
129130 Outline.Pkg pkg -> Task.run (verifyPkg env time pkg >> return ())
130131 Outline.App app -> Task.run (verifyApp env time app >> return ())
@@ -134,28 +135,28 @@ verifyInstall root (Solver.Env cache manager connection registry) outline =
134135-- LOAD -- used by Make, Repl, Reactor
135136
136137
137−load :: Reporting.Style -> FilePath -> IO (Either Exit.Details Details)
138−load style root =
138+load :: Reporting.Style -> BW.Scope -> FilePath -> IO (Either Exit.Details Details)
139+load style scope root =
139140 do newTime <- File.getTime (root </> "elm.json")
140141 maybeDetails <- File.readBinary (Stuff.details root)
141142 case maybeDetails of
142143 Nothing ->
143− generate style root newTime
144+ generate style scope root newTime
144145
145146 Just details@(Details oldTime _ _ _ _) ->
146147 if oldTime == newTime
147148 then return (Right details)
148− else generate style root newTime
149+ else generate style scope root newTime
149150
150151
151152
152153-- GENERATE
153154
154155
155−generate :: Reporting.Style -> FilePath -> File.Time -> IO (Either Exit.Details Details)
156−generate style root time =
156+generate :: Reporting.Style -> BW.Scope -> FilePath -> File.Time -> IO (Either Exit.Details Details)
157+generate style scope root time =
157158 Reporting.trackDetails style $ \key ->
158− do result <- initEnv key root
159+ do result <- initEnv key scope root
159160 case result of
160161 Left exit ->
161162 return (Left exit)
@@ -173,6 +174,7 @@ generate style root time =
173174data Env =
174175 Env
175176 { _key :: Reporting.DKey
177+ , _scope :: BW.Scope
176178 , _root :: FilePath
177179 , _cache :: Stuff.PackageCache
178180 , _manager :: Http.Manager
@@ -181,8 +183,8 @@ data Env =
181183 }
182184
183185
184−initEnv :: Reporting.DKey -> FilePath -> IO (Either Exit.Details (Env, Outline.Outline))
185−initEnv key root =
186+initEnv :: Reporting.DKey -> BW.Scope -> FilePath -> IO (Either Exit.Details (Env, Outline.Outline))
187+initEnv key scope root =
186188 do mvar <- fork Solver.initEnv
187189 eitherOutline <- Outline.read root
188190 case eitherOutline of
@@ -196,7 +198,7 @@ initEnv key root =
196198 return $ Left $ Exit.DetailsCannotGetRegistry problem
197199
198200 Right (Solver.Env cache manager connection registry) ->
199− return $ Right (Env key root cache manager connection registry, outline)
201+ return $ Right (Env key scope root cache manager connection registry, outline)
200202
201203
202204
@@ -243,7 +245,7 @@ checkAppDeps (Outline.AppOutline _ _ direct indirect testDirect testIndirect) =
243245
244246
245247verifyConstraints :: Env -> Map.Map Pkg.Name Con.Constraint -> Task (Map.Map Pkg.Name Solver.Details)
246−verifyConstraints (Env _ _ cache _ connection registry) constraints =
248+verifyConstraints (Env _ _ _ cache _ connection registry) constraints =
247249 do result <- Task.io $ Solver.verify cache connection registry constraints
248250 case result of
249251 Solver.Ok details -> return details
@@ -289,7 +291,7 @@ fork work =
289291
290292
291293verifyDependencies :: Env -> File.Time -> ValidOutline -> Map.Map Pkg.Name Solver.Details -> Map.Map Pkg.Name a -> Task Details
292−verifyDependencies env@(Env key root _ _ _ _) time outline solution directDeps =
294+verifyDependencies env@(Env key scope root _ _ _ _) time outline solution directDeps =
293295 Task.eio id $
294296 do Reporting.report key (Reporting.DStart (Map.size solution))
295297 mvar <- newEmptyMVar
@@ -309,11 +311,9 @@ verifyDependencies env@(Env key root _ _ _ _) time outline solution directDeps =
309311 foreigns = Map.map (OneOrMore.destruct Foreign) $ Map.foldrWithKey gatherForeigns Map.empty artifacts
310312 details = Details time outline Map.empty foreigns (ArtifactsFresh ifaces objs)
311313 in
312− do -- PERF fork all three of these writes, but need to make sure
313− -- they complete before main thread with some MVar check at end
314− File.writeBinary (Stuff.objects root) objs
315− File.writeBinary (Stuff.interfaces root) ifaces
316− File.writeBinary (Stuff.details root) details
314+ do BW.writeBinary scope (Stuff.objects root) objs
315+ BW.writeBinary scope (Stuff.interfaces root) ifaces
316+ BW.writeBinary scope (Stuff.details root) details
317317 return (Right details)
318318
319319
@@ -357,7 +357,7 @@ type Dep =
357357
358358
359359verifyDep :: Env -> MVar (Map.Map Pkg.Name (MVar Dep)) -> Map.Map Pkg.Name Solver.Details -> Pkg.Name -> Solver.Details -> IO Dep
360−verifyDep (Env key _ cache manager _ _) depsMVar solution pkg details@(Solver.Details vsn directDeps) =
360+verifyDep (Env key _ _ cache manager _ _) depsMVar solution pkg details@(Solver.Details vsn directDeps) =
361361 let
362362 fingerprint = Map.intersectionWith (\(Solver.Details v _) _ -> v) solution directDeps
363363 in