From 9df3041b972c2a7cf4eae7c0af46a67c02546552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20G=C3=A9lineau?= Date: Sun, 6 Mar 2022 07:42:03 -0500 Subject: [PATCH] restore support for -package-db flags 'unsafeRunInterpreterWithArgs' is often used to specify the path to a non-default package database, using the @-package-db@ flag. Unfortunately, a previous refactoring accidentally broke this workflow. The refactoring seems innocent on the surface, so it's worth explaining how that refactoring managed to break anything. The refactoring defined a 'modifyLogger' shim corresponding to the ghc-9.2 function of the same name. In older versions of ghc, 'modifyLogger' is implemented using 'setSessionDynFlags'. As a result, it now matters whether the logger is configured before other calls to 'setSessionDynFlags'. In particular, the logger was configured too early, before the @-package-db@ flags were given to ghc using a second call to 'setSessionDynFlags'. As a result, the first call to 'setSessionDynFlags', the one hidden inside 'modifyLogger', was reading the default package databases and setting internal flag indicating that the package databases have been read. Then, the second call to 'setSessionDynFlags' which specifies non-default package databases with @-package-db@ flags, saw this internal flag and decided not to read the package databases a second time. fixes #142 --- src/Hint/InterpreterT.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Hint/InterpreterT.hs b/src/Hint/InterpreterT.hs index 9ce6733..7edfbed 100644 --- a/src/Hint/InterpreterT.hs +++ b/src/Hint/InterpreterT.hs @@ -77,8 +77,6 @@ initialize :: (MonadIO m, MonadThrow m, MonadMask m, Functor m) -> InterpreterT m () initialize args = do logger <- fromSession ghcLogger - runGhc $ GHC.modifyLogger (const logger) - -- Set a custom log handler, to intercept error messages :S df0 <- runGhc GHC.getSessionDynFlags @@ -91,6 +89,7 @@ initialize args = -- Observe that, setSessionDynFlags loads info on packages -- available; calling this function once is mandatory! + runGhc $ GHC.modifyLogger (const logger) _ <- runGhc $ GHC.setSessionDynFlags df2 let extMap = [ (GHC.flagSpecName flagSpec, GHC.flagSpecFlag flagSpec)