summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-03-28 09:32:20 -0400
committerBen Gamari <ben@smart-cactus.org>2020-03-28 09:34:49 -0400
commit05266a81f99dd5ee003c3f409d4837080487e737 (patch)
treeb80dd3fc8e209677911c1cd930d15e3b9a38c513
parent2643ba465cd2a133b6f495f34fc59cd1a6d23525 (diff)
downloadhaskell-wip/T17970.tar.gz
base: Ensure that encoding global variables aren't inlinedwip/T17970
As noted in #17970, these (e.g. `getFileSystemEncoding` and `setFileSystemEncoding`) previously had unfoldings, which would break their global-ness. While not strictly necessary, I also add a NOINLINE on `initLocaleEncoding` since it is used in `System.IO`, ensuring that we only system's query the locale encoding once. Fixes #17970.
-rw-r--r--libraries/base/GHC/IO/Encoding.hs10
1 files changed, 10 insertions, 0 deletions
diff --git a/libraries/base/GHC/IO/Encoding.hs b/libraries/base/GHC/IO/Encoding.hs
index d607b7e7b5..9bad2c6b58 100644
--- a/libraries/base/GHC/IO/Encoding.hs
+++ b/libraries/base/GHC/IO/Encoding.hs
@@ -107,6 +107,7 @@ utf32be = UTF32.utf32be
--
-- @since 4.5.0.0
getLocaleEncoding :: IO TextEncoding
+{-# NOINLINE getLocaleEncoding #-}
-- | The Unicode encoding of the current locale, but allowing arbitrary
-- undecodable bytes to be round-tripped through it.
@@ -120,6 +121,7 @@ getLocaleEncoding :: IO TextEncoding
--
-- @since 4.5.0.0
getFileSystemEncoding :: IO TextEncoding
+{-# NOINLINE getFileSystemEncoding #-}
-- | The Unicode encoding of the current locale, but where undecodable
-- bytes are replaced with their closest visual match. Used for
@@ -127,9 +129,13 @@ getFileSystemEncoding :: IO TextEncoding
--
-- @since 4.5.0.0
getForeignEncoding :: IO TextEncoding
+{-# NOINLINE getForeignEncoding #-}
-- | @since 4.5.0.0
setLocaleEncoding, setFileSystemEncoding, setForeignEncoding :: TextEncoding -> IO ()
+{-# NOINLINE setLocaleEncoding #-}
+{-# NOINLINE setFileSystemEncoding #-}
+{-# NOINLINE setForeignEncoding #-}
(getLocaleEncoding, setLocaleEncoding) = mkGlobal initLocaleEncoding
(getFileSystemEncoding, setFileSystemEncoding) = mkGlobal initFileSystemEncoding
@@ -139,9 +145,13 @@ mkGlobal :: a -> (IO a, a -> IO ())
mkGlobal x = unsafePerformIO $ do
x_ref <- newIORef x
return (readIORef x_ref, writeIORef x_ref)
+{-# NOINLINE mkGlobal #-}
-- | @since 4.5.0.0
initLocaleEncoding, initFileSystemEncoding, initForeignEncoding :: TextEncoding
+{-# NOINLINE initLocaleEncoding #-}
+-- N.B. initLocaleEncoding is exported for use in System.IO.localeEncoding.
+-- NOINLINE ensures that this result is shared.
#if !defined(mingw32_HOST_OS)
-- It is rather important that we don't just call Iconv.mkIconvEncoding here