-
Notifications
You must be signed in to change notification settings - Fork 842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid loading of package caches during build plan construction #2077
Conversation
caches <- getPackageCaches | ||
liftIO $ writeIORef icaches caches | ||
readIORef icaches | ||
inner getPackageCaches' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 i It 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