RE: [Template-haskell] Profiling with Template Haskell

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 where import Language.Haskell.THSyntax d_fun = [d| fun = putStrLn "I am a function" |] ---------- {- Main.hs -} import Splices $(d_fun) main = putStrLn "hello" -------- #Makefile 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 code. 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). Sean
participants (1)
-
Sean Seefried