Skip to content
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

Make sure GHC versions match #630

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 53 additions & 26 deletions src/Language/Haskell/Liquid/GHC/Interface.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
Expand Down Expand Up @@ -111,32 +112,58 @@ runLiquidGhc hscEnv cfg act =
withSystemTempDirectory "liquid" $ \tmp ->
runGhc (Just libdir) $ do
maybe (return ()) setSession hscEnv
df <- getSessionDynFlags
(df',_,_) <- parseDynamicFlags df (map noLoc $ ghcOptions cfg)
loud <- liftIO isLoud
let df'' = df' { importPaths = nub $ idirs cfg ++ importPaths df'
, libraryPaths = nub $ idirs cfg ++ libraryPaths df'
, includePaths = nub $ idirs cfg ++ includePaths df'
, packageFlags = ExposePackage (PackageArg "ghc-prim") (ModRenaming True []) : packageFlags df'
-- , profAuto = ProfAutoCalls
, ghcLink = LinkInMemory
--FIXME: this *should* be HscNothing, but that prevents us from
-- looking up *unexported* names in another source module..
, hscTarget = HscInterpreted -- HscNothing
, ghcMode = CompManager
-- prevent GHC from printing anything, unless in Loud mode
, log_action = if loud
then defaultLogAction
else \_ _ _ _ _ -> return ()
-- redirect .hi/.o/etc files to temp directory
, objectDir = Just tmp
, hiDir = Just tmp
, stubDir = Just tmp
} `xopt_set` Opt_MagicHash
`gopt_set` Opt_ImplicitImportQualified
`gopt_set` Opt_PIC
setSessionDynFlags df''
defaultCleanupHandler df'' act
ensureCorrectGhcVersion
df <- configureDynFlags cfg tmp
defaultCleanupHandler df act

configureDynFlags :: Config -> FilePath -> Ghc DynFlags
configureDynFlags cfg tmp = do
loud <- liftIO isLoud
df <- getSessionDynFlags
(df',_,_) <- parseDynamicFlags df (map noLoc $ ghcOptions cfg)
let df'' = df' { importPaths = nub $ idirs cfg ++ importPaths df'
, libraryPaths = nub $ idirs cfg ++ libraryPaths df'
, includePaths = nub $ idirs cfg ++ includePaths df'
, packageFlags = ExposePackage (PackageArg "ghc-prim") (ModRenaming True []) : packageFlags df'
-- , profAuto = ProfAutoCalls
, ghcLink = LinkInMemory
--FIXME: this *should* be HscNothing, but that prevents us from
-- looking up *unexported* names in another source module..
, hscTarget = HscInterpreted -- HscNothing
, ghcMode = CompManager
-- prevent GHC from printing anything, unless in Loud mode
, log_action = if loud
then defaultLogAction
else \_ _ _ _ _ -> return ()
-- redirect .hi/.o/etc files to temp directory
, objectDir = Just tmp
, hiDir = Just tmp
, stubDir = Just tmp
} `xopt_set` Opt_MagicHash
`gopt_set` Opt_ImplicitImportQualified
`gopt_set` Opt_PIC
setSessionDynFlags df''
return df''

--------------------------------------------------------------------------------
-- GHC Version Check -----------------------------------------------------------
--------------------------------------------------------------------------------

compiledGhcVersion :: String
compiledGhcVersion = VERSION_ghc

getGhcApiVersion :: Ghc String
getGhcApiVersion = projectVersion <$> getSessionDynFlags

ensureCorrectGhcVersion :: Ghc ()
ensureCorrectGhcVersion = do
ghcApiVersion <- getGhcApiVersion
unless (ghcApiVersion == compiledGhcVersion) $ panic Nothing $
"LiquidHaskell was compiled against GHC "
++ compiledGhcVersion
++ ", but is currently running against version "
++ ghcApiVersion
++ " of the GHC library. Please ensure that these versions match."

--------------------------------------------------------------------------------
-- Parse, Find, & Load Targets -------------------------------------------------
Expand Down