Skip to content

Global variables in GHC.IO.Encoding have inappropriate inlinings

While looking into #17947 (closed) I noticed that GHC.IO.Encoding.getFileSystemEncoding and friends, which are supposed to be global variables, exposes an unfolding:

$ _build/stage1/bin/ghc --show-iface _build/stage1/libraries/base/build/GHC/IO/Encoding.hi
...
c5f268cd1abea1e17607b29083a07ddf
  getFileSystemEncoding ::
    GHC.Types.IO GHC.IO.Encoding.Types.TextEncoding
  [Unfolding: (case getFileSystemEncoding1 of wild { (,) getFileSystemEncoding81 setFileSystemEncoding1 ->
               getFileSystemEncoding81 })]
877b4ce4c0c06df59a38c01a0a2f65ea
  getFileSystemEncoding1 ::
    (GHC.Types.IO GHC.IO.Encoding.Types.TextEncoding,
     GHC.IO.Encoding.Types.TextEncoding -> GHC.Types.IO ())
  [Unfolding: (case GHC.Magic.runRW#
                      @('GHC.Types.TupleRep
                          '[ 'GHC.Types.TupleRep '[], 'GHC.Types.LiftedRep])
                      @(# GHC.Prim.State# GHC.Prim.RealWorld,
                          (GHC.Types.IO GHC.IO.Encoding.Types.TextEncoding,
                           GHC.IO.Encoding.Types.TextEncoding -> GHC.Types.IO ()) #)
                      getFileSystemEncoding2 of ds { (#,#) ipv ipv1 ->
               ipv1 })]
...
  01c6dd64e835d1d407d95b7dea54fa17
  getFileSystemEncoding2 ::
    GHC.Prim.State# GHC.Prim.RealWorld
    -> (# GHC.Prim.State# GHC.Prim.RealWorld,
          (GHC.Types.IO GHC.IO.Encoding.Types.TextEncoding,
           GHC.IO.Encoding.Types.TextEncoding -> GHC.Types.IO ()) #)
  [Arity: 1, Strictness: <L,U>,
   Unfolding: (\ (s :: GHC.Prim.State# GHC.Prim.RealWorld)[OneShot] ->
               case GHC.Prim.noDuplicate# @GHC.Prim.RealWorld s of s' { DEFAULT ->
               case GHC.Prim.newMutVar#
                      @GHC.IO.Encoding.Types.TextEncoding
                      @GHC.Prim.RealWorld
                      getFileSystemEncoding3
                      s' of ds { (#,#) ipv ipv1 ->
               (# ipv,
                  ((\ (eta :: GHC.Prim.State# GHC.Prim.RealWorld) ->
                    GHC.Prim.readMutVar#
                      @GHC.Prim.RealWorld
                      @GHC.IO.Encoding.Types.TextEncoding
                      ipv1
                      eta)
                     `cast`
                   (Sym (GHC.Types.N:IO[0] <GHC.IO.Encoding.Types.TextEncoding>_R)),
                   (\ (v :: GHC.IO.Encoding.Types.TextEncoding)
                      (eta :: GHC.Prim.State# GHC.Prim.RealWorld) ->
                    case GHC.Prim.writeMutVar#
                           @GHC.Prim.RealWorld
                           @GHC.IO.Encoding.Types.TextEncoding
                           ipv1
                           v
                           eta of s2# { DEFAULT ->
                    (# s2#, GHC.Tuple.() #) })
                     `cast`
                   (<GHC.IO.Encoding.Types.TextEncoding>_R
                    ->_R Sym (GHC.Types.N:IO[0] <()>_R))) #) } })]

This will break the "globalness" of these variables, potentially breaking setFileSystemEncoding and others.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information