13.2. Known bugs or infelicities

The bug tracker lists bugs that have been reported in GHC but not yet fixed: see the GHC Trac. In addition to those, GHC also has the following known bugs or infelicities. These bugs are more permanent; it is unlikely that any of them will be fixed in the short term.

13.2.1. Bugs in GHC

  • GHC can warn about non-exhaustive or overlapping patterns (see Section 4.8, “Warnings and sanity-checking”), and usually does so correctly. But not always. It gets confused by string patterns, and by guards, and can then emit bogus warnings. The entire overlap-check code needs an overhaul really.

  • GHC does not allow you to have a data type with a context that mentions type variables that are not data type parameters. For example:

      data C a b => T a = MkT a
    

    so that MkT's type is

      MkT :: forall a b. C a b => a -> T a
    

    In principle, with a suitable class declaration with a functional dependency, it's possible that this type is not ambiguous; but GHC nevertheless rejects it. The type variables mentioned in the context of the data type declaration must be among the type parameters of the data type.

  • GHC's inliner can be persuaded into non-termination using the standard way to encode recursion via a data type:

      data U = MkU (U -> Bool)
    
      russel :: U -> Bool
      russel u@(MkU p) = not $ p u
    
      x :: Bool
      x = russel (MkU russel)
    

    We have never found another class of programs, other than this contrived one, that makes GHC diverge, and fixing the problem would impose an extra overhead on every compilation. So the bug remains un-fixed. There is more background in Secrets of the GHC inliner.

  • On 32-bit x86 platforms when using the native code generator, the -fexcess-precision option is always on. This means that floating-point calculations are non-deterministic, because depending on how the program is compiled (optimisation settings, for example), certain calculations might be done at 80-bit precision instead of the intended 32-bit or 64-bit precision. Floating-point results may differ when optimisation is turned on. In the worst case, referential transparency is violated, because for example let x = E1 in E2 can evaluate to a different value than E2[E1/x].

    One workaround is to use the -msse2 option (see Section 4.16, “Platform-specific Flags”, which generates code to use the SSE2 instruction set instead of the x87 instruction set. SSE2 code uses the correct precision for all floating-point operations, and so gives deterministic results. However, note that this only works with processors that support SSE2 (Intel Pentium 4 or AMD Athlon 64 and later), which is why the option is not enabled by default. The libraries that come with GHC are probably built without this option, unless you built GHC yourself.

  • There is known to be maleficent interactions between weak references and laziness. Particularly, it has been observed that placing a thunk containing a reference to a weak reference inside of another weak reference may cause runtime crashes. See Trac #11108 for details.

13.2.2. Bugs in GHCi (the interactive GHC)

  • GHCi does not respect the default declaration in the module whose scope you are in. Instead, for expressions typed at the command line, you always get the default default-type behaviour; that is, default(Int,Double).

    It would be better for GHCi to record what the default settings in each module are, and use those of the 'current' module (whatever that is).

  • On Windows, there's a GNU ld/BFD bug whereby it emits bogus PE object files that have more than 0xffff relocations. When GHCi tries to load a package affected by this bug, you get an error message of the form

    Loading package javavm ... linking ... WARNING: Overflown relocation field (# relocs found: 30765)
    

    The last time we looked, this bug still wasn't fixed in the BFD codebase, and there wasn't any noticeable interest in fixing it when we reported the bug back in 2001 or so.

    The workaround is to split up the .o files that make up your package into two or more .o's, along the lines of how the "base" package does it.