Skip to content

Commit

Permalink
restore support for -package-db flags
Browse files Browse the repository at this point in the history
'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
  • Loading branch information
gelisam committed Mar 6, 2022
1 parent 0f1ff22 commit 9df3041
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/Hint/InterpreterT.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit 9df3041

Please sign in to comment.