Skip to content

Needless call to fromInteger for literals

For the code below, ghc 6.7 puts the literal 65 in a static closure (S#) and calls fromInteger on it.

import Foreign.C ( CChar )

foreign import ccall putchar :: CChar -> IO ()

main = putchar 65

GHC 6.7 generates the following code; note the static closure Main.lvl and the call to fromInteger:

==================== STG syntax: ====================
Main.lvl = NO_CCS GHC.Num.S#! [65];
SRT(Main.lvl): []
Main.main =
    \u []
        case GHC.Int.fromInteger Main.lvl of ds_sSd {
          GHC.Int.I8# ds1_sS2 ->
              let {
                sat_sSf =
                    \r [ds2_sS3]
                        case __ccall_GC putchar [ds1_sS2 ds2_sS3] of wild_sSe {
                          (##) ds3_sS7 -> (#,#) [ds3_sS7 GHC.Base.()];
                        };
              } in  sat_sSf;
        };
SRT(Main.main): []
:Main.main =
    \r srt:(0,*bitmap*) [eta_sSc] GHC.TopHandler.runMainIO Main.main eta_sSc;
SRT(:Main.main): [GHC.TopHandler.runMainIO, Main.main]

GHC 6.6 just passes the 65 to putchar as an unboxed constant.

Trac metadata
Trac field Value
Version 6.7
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Multiple
Architecture Multiple
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information