[m-rev.] for review: move char_to_doc to pretty_printer.m

Zoltan Somogyi zoltan.somogyi at runbox.com
Fri Dec 30 20:01:38 AEDT 2022


2022-12-21 12:57 GMT+11:00 "Julien Fischer" <jfischer at opturion.com>:
> 
> On Tue, 20 Dec 2022, Zoltan Somogyi wrote:
> 
>> Move X_to_doc functions to pretty_printer.m.
> 
> ...
> 
>> diff --git a/library/pretty_printer.m b/library/pretty_printer.m
>> index 4d47976ac..2a97bd66f 100644
>> --- a/library/pretty_printer.m
>> +++ b/library/pretty_printer.m
>> +array_to_doc(A) =
>> +    docs([str("array(["), array_to_doc_loop(A, 0), str("])")]).
>> +
>> +:- func array_to_doc_loop(array(T), int) = doc.
>> +
>> +array_to_doc_loop(A, I) = Doc :-
>> +    ( if I > array.max(A) then
>> +        Doc = str("")
>> +    else
>> +        array.lookup(A, I, Elem),
> 
> It should be safe to call unsafe_lookup/3 there.

It wasn't, until I fixed the compiler abort bug in termination analysis.
The attached diff requires that fix in the installed compiler,
and switches to calling array.unsafe_lookup.

(The last two rotds have the now-required fix.)

>> +        Doc = docs([
>> +            format_arg(format(Elem)),
>> +            ( if I = array.max(A) then
>> +                str("")
>> +            else
>> +                group([str(", "), nl])
>> +            ),
>> +            format_susp((func) = array_to_doc_loop(A, I + 1))
>> +        ])
>> +    ).
> 
> Ditto for the version_array version.

Actually, version_array.m does not define an unsafe lookup operation.

Zoltan.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DIFF.aul
Type: application/octet-stream
Size: 908 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20221230/314a30b9/attachment.obj>


More information about the reviews mailing list