Skip to content

GHC and iserv cannot agree on what an Integer is; insanity ensues

Tested off ghc-8.6.1-alpha1, running on macOS 10.13.5.

  1. Compile a GHC that uses integer-gmp.

  2. Compile a GHC that uses integer-simple.

  3. Make Main.hs:

    {-# LANGUAGE TemplateHaskell #-}
    main = print $([e| 0 |])
  4. Try to compile the file with integer-gmp ghc and integer-simple ghc-iserv.

    • Expected behavior: (compiles fine and executable prints 0) or (outputs to-the-point error message)

    • Actual:

      [1 of 1] Compiling Main             ( Main.hs, Main.o )
      
      Main.hs:2:14: error:
          • Exception when trying to run compile-time code:
              ghc: ghc-iserv terminated (-11)
            Code: [| 0 |]
          • In the untyped splice: $([| 0 |])
        |
      2 | main = print $([e| 0 |])
        |              ^^^^^^^^^^^
  5. Try to compile the file with integer-simple ghc and integer-gmp ghc-iserv.

    • Expected behavior: (compiles fine and executable prints 0) or (outputs to-the-point error message)

    • Actual:

      [1 of 1] Compiling Main             ( Main.hs, Main.o )
      
      Main.hs:2:14: error:
          • Exception when trying to run compile-time code:
              heap overflow
            Code: [| 0 |]
          • In the untyped splice: $([| 0 |])
        |
      2 | main = print $([e| 0 |])
        |              ^^^^^^^^^^^

For more fun, replace the 0 with a 1. gmp ghc + simple iserv continues to explode. This is better than simple ghc + gmp iserv:

$ ./Main
283468057265
$ ./Main
283468057265
$ $simple_ghc -fexternal-interpreter -pgmi=$gmp_iserv Main.hs # again
# ...
$ ./Main
283468057105

Absolutely delicious. There is a similar situation for fractional literals.

It would be nice if there were at least a warning for situations like this.

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