GHC bug?

Posted in:

What do you do when you are dealing with what seems like a bizarre compiler bug, with the compiler being nothing less than GHC? First, pinch yourself — check; then try again, 3 times to be sure – check; clear out 'dist/' and any temporary build files – check; sleep on it – check.

And it's still happening.

I'm trying to use HStringTemplate for my personal blog software, in particular the renderf function. I was getting tricky compilation errors, and in the course of messing around I found the following:

GHC cannot compile a certain function, call it func1 for now, which uses renderf. But it compiles and works just fine if another function func2 (which doesn't use renderf, but does use a related HStringTemplate function render) is present in the module, even though func2 is not used anywhere in the project. Changing some of the details of what func2 does causes compilation to fail again, though other details can be changed.

That has to be impossible, right? Am I losing my mind?

Ideally I'd create a nice simple test case, but that might take hours, and changing small things about the voodoo function func2 seems to destroy its magical properties, and I'm suspecting the problem is in me. So I'll just post all my code. The bad news is there are lots of dependencies. The good news is I have used cabal, so the following instructions should suffice if you have cabal installed.

Download and install 'ella' (CGI web framework I'm writing) and dependencies:

git clone https://github.com/spookylukey/ella/
cd ella/
git checkout ba74e25b6275f27c3832ac9529d05e076e5f4f43
cabal configure --user && cabal build && cabal install --user
cd ..

Download and build the blog software:

git clone https://github.com/spookylukey/haskellblog/
cd haskellblog/
git checkout e9dfecbcdd14b297d818c224707499cb75b0e24e
cabal configure --user && cabal build

The build should succeed. Now, the voodoo function is at the end of src/Blog/Views.hs. Comment it out:

perl -pi -e 's/this_is_not_used/-- this_is_not_used/' src/Blog/Views.hs

Build again:

cabal build

Result - this compilation error.

I don't know whether that compilation error is correct or not, but either way, it seems crazy that it could depend on the existence and implementation of a completely unused function.

For reference, I'm using GHC 6.10.1.

Any ideas?


2017 Update - looks like I was bitten by the monomorphism restriction ‘feature’.

Comments §

Comments should load when you scroll to here...