diff options
author | Ben Gamari <ben@smart-cactus.org> | 2020-03-28 09:32:20 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-03-31 10:56:19 -0400 |
commit | 95bccdd034ce4dd2d1bc36db9f1ba5e172550249 (patch) | |
tree | a515843aad331031d860b9dcddf511ececd6b585 | |
parent | 09a36e80ecaefcfb60eccda98bd06461d0aeca70 (diff) | |
download | haskell-95bccdd034ce4dd2d1bc36db9f1ba5e172550249.tar.gz |
base: Ensure that encoding global variables aren't inlined
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.hs | 10 |
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 |