Annotation for unfolding wanted

Bulat Ziganshin bulat.ziganshin at gmail.com
Tue Jul 31 06:18:36 EDT 2007


Hello Simon,

Tuesday, July 31, 2007, 1:22:14 PM, you wrote:

> GHC never inlines recursive functions.  Why not?  Because doing so
> exposes a new inline opportunity.  How many times would you like it inlined?  Not forever, I assume!

really, state of things in this area is not pleasant. making
polymorphic function recursive kills the performance because it's no
more inlined nor specialized - it may be called only with real
dictionary. because i'm wrote polymorphic i/o library, i had many
situations when in rare cases functions should call itself recursively
like this:

getChar = if bufferEmpty
            then fillBuffer; getChar
            else return *p++

(sorry for some pseudocode) and it was very inefficient. at the last
end, i was need to create special functions to handle recursive calls
and call it when buffer empty so that main function becomes
non-recursive:

getChar = if bufferEmpty
            then getChar'
            else return *p++

getChar' = fillBuffer; getChar


it will be great if specifying INLINE for recursive function will mean
that it should be inlined at least once and then call to
non-polymorphic specialized version should be made. at least it will
be ideal for code like this


-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Glasgow-haskell-users mailing list