[Haskell-cafe] source line annotations

Evan Laforge qdunkan at gmail.com
Thu Jan 20 10:48:55 CET 2011


On Thu, Jan 20, 2011 at 12:47 AM, Max Bolingbroke
<batterseapower at hotmail.com> wrote:
> On 19 January 2011 23:59, Evan Laforge <qdunkan at gmail.com> wrote:
>> Another thing is that performance in logging is pretty critical.  When
>> I profile, logging functions wind up in the expensive list if I'm not
>> careful.  I don't know bad an unsafePerformIO plus a catch for every
>> log msg is going to be, but it's not going to be as fast as doing the
>> work at compile time.
>
> It is possible that GHC's optimiser will let-float the "getSourceLoc
> assert" application to the top level, which would ensure that you only
> take the hit the first time. However, I'm not sure about this - do an
> experiment!

I don't read core very well, but with a simple example it appears it
does, and I wind up with the unsafePerformIO stuff in a top level CAF
of type String.  However, when I switch to a more realistic example
with an intermediary function, as in:

warn assert msg = tell (getSourceLoc assert ++ msg)

it looks like each call to 'warn' calls getSourceLoc as a function, so
it should take the performance hit each time.  So it might be possible
to get this to work by embedding all logging logic into the second
argument of 'catch' and being careful to check the core.

> Since logging is in IO anyway, perhaps GHC could provide a new magic
> primitive, (location :: IO String), which was replaced by the compiler
> with an expression like (return "MyLocation:42:1"). Your consumer
> could then look like

Not necessarily!  None of my logging or exceptions are in IO, so it
wouldn't work for me.

I still like the pragma...



More information about the Haskell-Cafe mailing list