[m-dev.] more things to move from io.m.

Zoltan Somogyi zoltan.somogyi at runbox.com
Mon Mar 14 17:59:12 AEDT 2022


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.

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?

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.

I also intend to remove from io.m the internal-only with_input_stream
predicates, by making their callers use explicit streams.

Opinions? Objections?

Zoltan.


More information about the developers mailing list