Skip to content

Commit

Permalink
setSessionDynamicFlags to prevent ghc9 from crashing
Browse files Browse the repository at this point in the history
The only way to set the dynamic linker is with the function `setSessionDynFlags`
so we call it with the result from `getSessionDynFlags` to give it a
(hopefully sensible) argument.

See also this commit:
https://gitlab.haskell.org/ghc/ghc/commit/18757cab04c5c5c48eaceea19469d4811c5d0371
  • Loading branch information
anka-213 committed Jun 1, 2021
1 parent 79f5fee commit 4065ac8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,15 @@ cradleToOptsAndLibDir cradle file = do

emptyHscEnv :: IORef NameCache -> FilePath -> IO HscEnv
emptyHscEnv nc libDir = do
#if MIN_VERSION_ghc(9,0,0)
-- Without the seemingly redundant `getSessionDynFlags >>= setSessionDynFlags`
-- the line `initDynLinker env` would crash with the errror:
-- `Couldn't find a target code interpreter. Try with -fexternal-interpreter`
env <- runGhc (Just libDir) $ getSessionDynFlags >>= setSessionDynFlags >> getSession
#else
env <- runGhc (Just libDir) getSession
#if !MIN_VERSION_ghc(9,0,0)
-- This causes ghc9 to crash with the error:
-- Couldn't find a target code interpreter. Try with -fexternal-interpreter
initDynLinker env
#endif
initDynLinker env
pure $ setNameCache nc env{ hsc_dflags = (hsc_dflags env){useUnicode = True } }

data TargetDetails = TargetDetails
Expand Down

0 comments on commit 4065ac8

Please sign in to comment.