[Template-haskell] Profiling with Template Haskell

Sean Seefried sseefried@cse.unsw.EDU.AU
Thu, 7 Aug 2003 11:54:27 +1000 (EST)

  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.
  Send mail to mime@docserver.cac.washington.edu for more info.

Content-Type: TEXT/PLAIN; charset=US-ASCII

Hi Simon,

> Hmm, yes good point.  GHC compiles different binaries for profiled and
> non-profiled execution.  Splice code that runs at compile time should
> presumably be non-profiled (though I'm sure someone will want to
> profile it too).  So TH should link non-profiled libraries at compile
> time, but it's not clever enough to realise this.
> I'll put this on my list of things to fix.  I'm in the middle of a
> heart transplant on GHC at the moment, aimed at making a better
> substrate for TH, so I may not fix this very quickly unless it's
> important to you.
> It will mean that you'll have to compile your own program modules both
> profiled and non-profiled -- the former for run-time and the latter
> for compile time -- unless you keep compile-time code and run-time
> code in separate modules.  That's annoying but I don't see an easy
> alternative.

It was quite easy to trick GHC into linking in the non-profiled code
while splicing. I'll use the same example as last time

{- Splices.hs -}
module Splices

import Language.Haskell.THSyntax

d_fun =
     fun = putStrLn "I am a function"
{- Main.hs -}

import Splices


main = putStrLn "hello"


GHC=ghc -fglasgow-exts -package haskell-src

all: Main

Main: Main.p_o Splices.p_o
	$(GHC) -prof  Main.p_o Splices.p_o -o Main

%.hi: %.o

%.o: %.hs
	$(GHC) -c $< -o $@

%.p_hi: %.p_o

%.p_o: %.hs
	$(GHC) -prof -hisuf p_hi -c $< -o $@

Main.o: Splices.hi
Main.p_o: Splices.hi Splices.p_hi


Now this actually compiles with no problems. But when run gives a Bus
error.  On another more complicated program in which I tried this
trick I received a "Illegal instruction" error, which makes me think
that control was passed to an area of memory that did not contain

My supervisor Manuel suggested that the infotables are different in
the code for profiling.  It seems that the process of linking in
non-profiled code during splicing, yet linking profiled code at the
end mixes the two types of code and this results in jumps to incorrect
locations in memory at run-time.

I have attached all the files necessary to test this out yourself.
(I'm using GHC HEAD but I think it should work on older versions of GHC).

Content-Type: APPLICATION/octet-stream; name="th_prof.tar.gz"
Content-Transfer-Encoding: BASE64
Content-ID: <Pine.LNX.4.53.0308071154270.23223@pill0.orchestra.cse.unsw.EDU.AU>
Content-Disposition: attachment; filename="th_prof.tar.gz"