[mercury-users] Tail call optimisation in hlc grades

Julien Fischer juliensf at csse.unimelb.edu.au
Mon Aug 20 17:39:24 AEST 2007


On Sun, 19 Aug 2007, Michael Day wrote:

>> I have a predicate operating on a list that appears to be tail recursive, 
>> yet in hlc grades it crashes when applied to a list containing around 600k 
>> elements. Is tail call optimisation performed in hlc grades?
>
> To answer myself, yes tail call optimisation is performed, and in fact it 
> appears to be performed on the predicate for which I thought it wasn't being 
> performed.
>
> However, it does not seem to be performed for the array.insert_items 
> predicate, used by array.from_list, which means array.from_list will crash in 
> hlc grades when given a long list. I don't know why the optimisation isn't 
> being applied to this predicate, as it looks tail recursive to me. Something 
> to do with the array modes perhaps?

I don't think so, you still don't get tail recursion for insert_items/4
even if you make the modes `in' and `out'.  I think it's more likely
the type that may be causing the problem here (in fact if you change the
arguments to make what was the array, polymorphic you do get tail
recursion.)  I'll keep looking into this one.

> One change that could be made to insert_items is to use unsafe_set, as the 
> size of the array has been set in advance and the bounds checks performed by 
> array.set are redundant.

Good idea.

Julien.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list