[Git][ghc/ghc][master] base: Ensure that encoding global variables aren't inlined

Marge Bot gitlab at gitlab.haskell.org
Tue Mar 31 14:56:29 UTC 2020



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
95bccdd0 by Ben Gamari at 2020-03-31T10:56:19-04:00
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.

- - - - -


1 changed file:

- libraries/base/GHC/IO/Encoding.hs


Changes:

=====================================
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



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/95bccdd034ce4dd2d1bc36db9f1ba5e172550249

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/95bccdd034ce4dd2d1bc36db9f1ba5e172550249
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200331/9af4f4c5/attachment-0001.html>


More information about the ghc-commits mailing list