GHC bug?

Posted in: Web development, Haskell

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:

hg clone -r 30aa625a3f51
cd ella/
cabal configure --user && cabal build && cabal install --user
cd ..

(You can download a tarball if you don’t have mercurial)

Download and build the blog software:

hg clone -r e1015168e56b
cd haskellblog/
cabal configure --user && cabal build

(Again, download the tarball if you don’t have mercurial)

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 §

blog comments powered by Disqus