[m-dev.] For review: pprint performance bug fix and misc. cha nges

Ralph Becket rbeck at microsoft.com
Wed Feb 28 01:29:52 AEDT 2001


I've just checked this in... (sorry Fergus, I haven't had time to see
if it can handle dumping the MLDS).

Cheers,

Ralph

Estimated hours taken: 2

Fixed the performance problem with the pretty printer; runtime
should now be linear in the size of the input (the previous
version suffered from being a somewhat optimistic direct
transliteration of a Haskell program).

Also made one or two other minor changes.

library/pprint.m
        Changed the formatting decision procedure from
        flatten/1 + be/3 + fits/2 (short and sweet and
        works fine if you have laziness) to a new set of
        predicates flattening_works/3 + fits_flattened/3 +
        fits_on_rest/2 which ensure linear run-time
        behaviour and reduce structure creation.

        In doing so, removed Mark's optimisation of flatten
        (it was only a partial solution, alas).

        Changed to_doc/[1,2] so that closing parentheses
        don't appear on separate lines, so as to reduce
        the amount of vertical space consumed.

        Changed to_doc/2 so that `foo/N' is output rather
        than `foo(...)' when the depth limit is reached.

        Extended the comment for separated/3 to include a
        useful idiom and changed the implementation so that
        docs created by separated/3 nest to the right.

        Simplified the definition of word_wrapped/1 to use
        the above idiom.

        Changed the core function be/3 into a predicate be/5
        to use an accumulator and hence be tail recursive.
        This made it possible to do away with the complex
        definition of simple_doc and replace it with just a
        list of strings.  This in turn simplified the
        definition of layout/2.


--
Ralph Becket      |      MSR Cambridge      |      rbeck at microsoft.com 
--------------------------------------------------------------------------
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