adding isWHNF primop to 5.00.2 native code generator

Bernard James POPE bjpop@cs.mu.OZ.AU
Fri, 3 Aug 2001 15:05:54 +1000 (EST)


Hi all,

Hack alert!

I took Julian's advice and looked over the assembly output from
ghc.

In all the cases I tried, the info pointer in the closure header
pointed to the end of the info table. Although a comment in
ghc/includes/ClosureMacros.h worries me:

       "info pointer"    The first word of the closure.  Might point
                         to either the end or the beginning of the
                         info table, depending on whether we're using
                         the mini interpretter or not.  GET_INFO(c)
                         retrieves the info pointer of a closure.

Can someone please clarify when the info pointer will point to
the beginning or end of the table?

Basically I have assumed for the moment that it points to the end
of the table, as that is what some other code in ghc seems to 
assume.

This makes it easy (hack?) to find the "type" field of the info table,
its just the bottom (or top, depending on which way you look at it)
16 bits prior to the address that the info pointer contains. Essentially
dataToTag# gives you these bits. I don't think "dataToTag#" is a great
name for this primop, something like: closureType#, or classifyClosure#
might be better.

My current strategy is to simply compare the type field with 
the constants from ClosureTypes.h, using the Haskellised names 
re-exported from SMRep.lhs as suggested by Simon Marlow.

My problem is that this is a dodgy assumption since the design of the 
info table may change in the future, and you get a nasty 
unchecked dependency between the primops in the NCG and the design
of the rts. 

It seems hard to get the kind of automatic offset calculation in the 
NCG as you get with the C version of primops. My current idea
is to make some C primops that do the structure and array indexing
for me, and then use them in the NCG. i.e. primops that essentially
export 'closure_flags[type]' and 'get_itbl(c)->type' to the NCG.

Does anyone know of a better solution?

In any case I am happy for the moment with my hacky solution, since it
gives the right results and it is what I need to write up my
paper.

Cheers,
Bernie.