[m-dev.] diff: fix bug in pprint__to_doc

Fergus Henderson fjh at cs.mu.OZ.AU
Tue May 9 23:49:46 AEST 2000


On 09-May-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> > library/pprint.m:
> > 	Fix a bug: there was an infinite loop in the code for `to_doc'.
> > 	The recursive call to convert the term's arguments was
> > 	happening even in the case where the term had no arguments.
> 
> This I don't understand.

Sorry, my original description of the bug was wrong.
I didn't notice that when Arity is 0, UnivArgs will be []
and so there will be no recursive call.

> The only place where a recursive call
> ocurrs in the original source is in the clausal part of the
> function:
> 
> :-
>     deconstruct(X, Name, Arity, UnivArgs),
>     Args = list__map(
>         ( func(UnivArg) = to_doc(Depth - 1, univ_value(UnivArg)) ),
>         UnivArgs
>     ).
> 
> Now, I would (did) assume that after the call to deconstruct/4 that
> (Arity = 0) <=> (UnivArgs = []), in which case the call to list__map/2
> shouldn't have made any calls to to_doc/2 - if this is indeed the
> error case.
> 
> Got it!  The error case is actually when Arity > 0, but Depth =< 0.
> This will lead to unwanted recursive calls.

Right.

> Still, unless you've somehow created a circular structure, I don't
> see how this would turn into an infinite loop (surely all terms are
> finite trees?)  Maybe your `infinite loop' was really just `very deep
> recursion'?

I think you may be right.  I think the real problem I encountered
was the exponential performance bug in pprint:be/4.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list