ghc feature request: core notes

Alastair Reid alastair@reid-consulting-uk.ltd.uk
Thu, 06 Feb 2003 11:27:39 +0000


"Hal Daume III" <hdaume@ISI.EDU> writes:
> I'm not sure how "generally useful" this would be, but I would
> find it useful to be able to attach notes to core expressions from
> the Haskell code.  The idea being something along the lines of a
> code annotation like a pragma. [...]

Simon Peyton-Jones <simonpj@microsoft.com> writes:
> [...] There is an annotation facility in Core, but it's easy for the notes
> to be discarded.  So if they are conveying important info, it might
> easily get lost... and if not, what's it doing there in the first
> place.  What do you expect to happen to these annotations? [...]

It seems like _scc_ is (almost) exactly what you need here.  When used
for profiling, you mark subexpressions you want profiled and ghc takes
care to preserve and propagate them in a semantically meaningful way.
Any _scc_ annotations that ghc chooses to drop can be reported as
bugs :-)

I say "almost" because what the semantics used when profiling may not
be the right ones for your purposes.  (I'm being vague because I don't
know your purposes.)

Naturally, you'd want to be able to use these notes independently of
profiling - which can probably be done with a little preprocessor
hackery.  Assuming that the 1st argument to 'NOTE' is a literal string
in the following:

#ifdef TRACK_NOTES
#define NOTE(x,y) (_scc_ "<NOTE " x ">" (y))
#else
#define NOTE(x,y) {- nothing -}
#endif

--
Alastair Reid