[m-dev.] more things to move from io.m.
Julien Fischer
jfischer at opturion.com
Mon Mar 14 18:52:00 AEDT 2022
On Mon, 14 Mar 2022, Zoltan Somogyi wrote:
> io.m is now down to 6700 lines (from more than 13k originally).
> Nevertheless, there are more things we can move from it to other places.
>
> One is the predicates flush_output_2 and flush_binary_output_2.
> We could move these to either io.stream_ops, io.primitives_write,
> or to a new submodule that writes out non-primitive items. I think
> stream_ops is the right place.
stream_ops seems fine.
> Another is the implementations of read_word, read_line, read_file
> and their variants. I think these can be moved to a new submodule
> (leaving the top-level predicates in io.m); the main question is what this
> new submodule should be named. These are the only non-primitive things
> io.m reads that take up any space in io.m itself. Reading terms is done by
> mercury_term_parser.m; reading bitmaps is now done by bitmap.m.
> How about io.read_text.m, or io.text_read.m to fit in with io.primitives_read.m?
io.text_read seems fine.
> I just checked, and there are three uses of the input_stream_foldl
> predicates in the Mercury implementation. All three would be simpler
> and probably faster if they were replaced by code that read in the relevant
> file as a string and operated on that. So I have no objection to Julien's
> proposal a while ago to mark them all as obsolete. However, I do think
> that before we do so, we should add a version of list.foldl that does
> two-level iteration, to reduce the max recursion depth to tolerable levels
> in grades that do not have tail recursion (mainly debug and profiling grades).
> And that throws up the obvious $64k question: exactly which subset
> of the gazillion foldl predicates should get such a version? I envision
> those versions would have an extra input arg specifying the chunk size.
Based on a quick grep of the compiler source code:
list.foldl 1542
list.foldl2 327
list.foldl3 76
list.foldl4 31
list.foldl5 9
list.foldl6 2
list.foldl7 0
list.foldl8 0
list.foldl9 0
(This is counting module qualified calls only, so it is indicative only.)
The distribution is similiar for map_foldl. Calls with more than four
accumulators are very rare.
> I also intend to remove from io.m the internal-only with_input_stream
> predicates, by making their callers use explicit streams.
No objection from me.
Julien.
More information about the developers
mailing list