Avoid loading of package caches during build plan construction#2077
Avoid loading of package caches during build plan construction#2077mgsloan merged 1 commit intocommercialhaskell:masterfrom
Conversation
| caches <- getPackageCaches | ||
| liftIO $ writeIORef icaches caches | ||
| readIORef icaches | ||
| inner getPackageCaches' |
There was a problem hiding this comment.
I've been looking how to do this properly with MonadBaseControl but failed. My impression was that you'd always have to evaluate getPackageCaches before you could pass it to inner.
|
I don't see what this buys us. Perhaps that caching isn't working in practice (could happen from initializing multiple |
|
Does this make it any clearer? -- | Access the package caches from 'IO'.
withPackageCaches
:: (MonadIO m, MonadReader env m, HasConfig env, MonadLogger m, HasHttpManager env, MonadBaseControl IO m, MonadCatch m)
=> (IO (Map PackageIdentifier (PackageIndex, PackageCache)) -> m a)
-> m a
withPackageCaches inner = do
getCaches <- toIO getPackageCaches
inner getCaches
toIO :: (MonadIO m, MonadBaseControl IO m) => m a -> m (IO a)
toIO m = do
-- TODO: Use monad base control properly.
runInBase <- liftBaseWith $ \run -> return (void . run)
return $ do
i <- newIORef (error "Impossible evaluation in toIO")
runInBase $ do
x <- m
liftIO $ writeIORef i x
readIORef iIt looks rather illegal to me. Alas, we want to access (and update!) the package caches and index during build plan construction, but deserialize the caches only when necessary. The functions in I can only speculate why this hasn't been solved differently:
Some ideas how to improve the situation: For the case where we want to make nice error messages ( Regarding Maybe we could make a simpler alternative to Or we just add the monad transformers. |
|
Ah, I think what confused me is that The changes to ConstructPlan look reasonable, but I haven't thought too hard about it.
It surprised me that we'd need the package index if the appropriate |
via IORef trickery
8ae1cd8 to
8751030
Compare
Good point, I've updated the PR!
Looks like we should take a closer look! 😄 |
|
LGTM, thanks! Yes, probably a close look at that case should be taken before closing out #1892 |
|
Thanks for reviewing! |
via IORef trickery