Wolfgang Jeltsch pushed to branch wip/jeltsch/system-io-uncovering at Glasgow Haskell Compiler / GHC

Commits:

1 changed file:

Changes:

  • libraries/ghc-internal/src/GHC/Internal/TH/Monad.hs
    ... ... @@ -32,7 +32,6 @@ import Control.Monad.Fix (MonadFix (..))
    32 32
     import Control.Exception (BlockedIndefinitelyOnMVar (..), catch, throwIO)
    
    33 33
     import Control.Exception.Base (FixIOException (..))
    
    34 34
     import Control.Concurrent.MVar (newEmptyMVar, readMVar, putMVar)
    
    35
    -import System.IO        ( hPutStrLn, stderr )
    
    36 35
     import qualified Data.Kind as Kind (Type)
    
    37 36
     import GHC.IO.Unsafe    ( unsafeDupableInterleaveIO )
    
    38 37
     import GHC.Types        (TYPE, RuntimeRep(..))
    
    ... ... @@ -41,7 +40,6 @@ import GHC.Internal.Base hiding (NonEmpty(..),Type, Module, sequence)
    41 40
     import GHC.Internal.Data.Data hiding (Fixity(..))
    
    42 41
     import GHC.Internal.Data.Traversable
    
    43 42
     import GHC.Internal.IORef
    
    44
    -import GHC.Internal.System.IO
    
    45 43
     import GHC.Internal.Data.Foldable
    
    46 44
     import GHC.Internal.Data.Typeable
    
    47 45
     import GHC.Internal.Control.Monad.IO.Class
    
    ... ... @@ -54,6 +52,10 @@ import GHC.Internal.MVar
    54 52
     import GHC.Internal.IO.Exception
    
    55 53
     import qualified GHC.Internal.Types as Kind (Type)
    
    56 54
     #endif
    
    55
    +import GHC.Internal.IO (FilePath)
    
    56
    +import GHC.Internal.IO.Handle.Text (hPutStr, hPutStrLn)
    
    57
    +import GHC.Internal.IO.IOMode (IOMode (WriteMode))
    
    58
    +import GHC.Internal.IO.StdHandles (stderr, withFile)
    
    57 59
     import GHC.Internal.ForeignSrcLang
    
    58 60
     import GHC.Internal.LanguageExtensions
    
    59 61
     import GHC.Internal.TH.Syntax
    
    ... ... @@ -875,6 +877,15 @@ addForeignSource lang src = do
    875 877
       path <- addTempFile suffix
    
    876 878
       runIO $ writeFile path src
    
    877 879
       addForeignFilePath lang path
    
    880
    +  where
    
    881
    +
    
    882
    +    {-
    
    883
    +        This is a copy of the implementation of 'System.IO.writeFile', which we
    
    884
    +        use to avoid forcing 'System.IO.writeFile' being implemented in
    
    885
    +        @ghc-internal@.
    
    886
    +    -}
    
    887
    +    writeFile :: FilePath -> String -> IO ()
    
    888
    +    writeFile f txt = withFile f WriteMode (\ hdl -> hPutStr hdl txt)
    
    878 889
     
    
    879 890
     -- | Same as 'addForeignSource', but expects to receive a path pointing to the
    
    880 891
     -- foreign file instead of a 'String' of its contents. Consider using this in