diff --git a/Check.hs b/Check.hs index 3ae4929..e27736b 100644 --- a/Check.hs +++ b/Check.hs @@ -23,12 +23,7 @@ check opt cradle fileName = withGHC fileName $ checkIt `gcatch` handleErrMsg checkIt = do readLog <- initializeFlagsWithCradle opt cradle options True setTargetFile fileName - -- To check TH, a session module graph is necessary. - -- "load" sets a session module graph using "depanal". - -- But we have to set "-fno-code" to DynFlags before "load". - -- So, this is necessary redundancy. - slow <- needsTemplateHaskell <$> depanal [] False - when slow setSlowDynFlags + checkSlowAndSet void $ load LoadAllTargets liftIO readLog options diff --git a/GHCApi.hs b/GHCApi.hs index c34448f..d3eee88 100644 --- a/GHCApi.hs +++ b/GHCApi.hs @@ -5,7 +5,7 @@ module GHCApi ( , initializeFlagsWithCradle , setTargetFile , getDynamicFlags - , setSlowDynFlags + , checkSlowAndSet ) where import CabalApi @@ -122,6 +122,15 @@ setSlowDynFlags :: Ghc () setSlowDynFlags = (flip setFastOrNot False <$> getSessionDynFlags) >>= void . setSessionDynFlags +-- To check TH, a session module graph is necessary. +-- "load" sets a session module graph using "depanal". +-- But we have to set "-fno-code" to DynFlags before "load". +-- So, this is necessary redundancy. +checkSlowAndSet :: Ghc () +checkSlowAndSet = do + slow <- needsTemplateHaskell <$> depanal [] False + when slow setSlowDynFlags + ---------------------------------------------------------------- modifyFlagsWithOpts :: DynFlags -> [String] -> Ghc DynFlags diff --git a/Info.hs b/Info.hs index c9cc467..12f290d 100644 --- a/Info.hs +++ b/Info.hs @@ -4,7 +4,7 @@ module Info (infoExpr, typeExpr) where import Control.Applicative -import Control.Monad (when) +import Control.Monad (void) import CoreUtils import Data.Function import Data.Generics @@ -144,18 +144,16 @@ inModuleContext opt cradle fileName modstr action errmsg = withGHCDummyFile (valid ||> invalid ||> return errmsg) where valid = do - _ <- initializeFlagsWithCradle opt cradle ["-w"] False + void $ initializeFlagsWithCradle opt cradle ["-w"] False setTargetFile fileName - slow <- needsTemplateHaskell <$> depanal [] False - when slow setSlowDynFlags - _ <- load LoadAllTargets + checkSlowAndSet + void $ load LoadAllTargets doif setContextFromTarget action invalid = do - _ <- initializeFlagsWithCradle opt cradle ["-w"] False + void $ initializeFlagsWithCradle opt cradle ["-w"] False setTargetBuffer - slow <- needsTemplateHaskell <$> depanal [] False - when slow setSlowDynFlags - _ <- load LoadAllTargets + checkSlowAndSet + void $ load LoadAllTargets doif setContextFromTarget action setTargetBuffer = do modgraph <- depanal [mkModuleName modstr] True