@@ -46,7 +46,7 @@ import TidyPgm
4646import qualified GHC.LanguageExtensions as LangExt
4747
4848import Control.DeepSeq
49−import Control.Monad
49+import Control.Monad.Extra
5050import Control.Monad.Trans.Except
5151import qualified Data.Text as T
5252import Data.IORef
@@ -127,7 +127,7 @@ typecheckModule opt packageState deps pm =
127127 setupEnv deps
128128 (warnings, tcm) <- withWarnings $ \tweak ->
129129 GHC.typecheckModule pm{pm_mod_summary = tweak $ pm_mod_summary pm}
130− tcm2 <- mkTcModuleResult (WriteInterface $ optWriteIface opt) tcm
130+ tcm2 <- mkTcModuleResult (optIfaceDir opt) tcm
131131 return (warnings, tcm2)
132132
133133-- | Compile a single type-checked module to a 'CoreModule' value, or
@@ -197,18 +197,16 @@ moduleImportPaths pm
197197 rootModDir = takeDirectory . moduleNameSlashes . GHC.moduleName $ mod'
198198
199199
200−newtype WriteInterface = WriteInterface Bool
201−
202200mkTcModuleResult
203201 :: GhcMonad m
204− => WriteInterface
202+ => InterfaceDirectory
205203 -> TypecheckedModule
206204 -> m TcModuleResult
207−mkTcModuleResult (WriteInterface writeIface) tcm = do
205+mkTcModuleResult (InterfaceDirectory mbIfaceDir) tcm = do
208206 session <- getSession
209207 (iface,_) <- liftIO $ mkIfaceTc session Nothing Sf_None details tcGblEnv
210− liftIO $ when writeIface $ do
211− let path = ".interfaces" </> file tcm
208+ liftIO $ whenJust mbIfaceDir $ \ifaceDir -> do
209+ let path = ifaceDir </> file tcm
212210 createDirectoryIfMissing True (takeDirectory path)
213211 writeIfaceFile (hsc_dflags session) (replaceExtension path ".hi") iface
214212 -- For now, we write .hie files whenever we write .hi files which roughly corresponds to