New Issue: IO module: proposed changes to iohints

20141, "jhh67", "IO module: proposed changes to iohints", "2022-07-01T18:14:25Z"

The iohints type is passed as an argument to the open*, file.reader, file.lines, and file.writer methods, and defines a set of hints about the I/O that the file or channel will perform.

The following iohints constants are provided:

  • IOHINT_NONE defines an empty set, which provides no hints.
  • IOHINT_RANDOM suggests to expect random access.
  • IOHINT_SEQUENTIAL suggests to expect sequential access
  • IOHINT_CACHED suggests that the file data is or should be cached in memory, possibly all at once.
  • IOHINT_PARALLEL suggests to expect many channels working with this file in parallel.

The following binary operators are defined on iohints:

  • | for set union
  • & for set intersection
  • == for set equality
  • != for set inequality


As a result of the discussion during the recent module review the current proposal is to replace the current iohints with a ioHints record type that has parenless methods for the individual hints, e.g.

record ioHints {
 pragma "no doc"
 var fieldForActualValue: int;

 proc type sequential {
   return new iohints(valueCorrespondingToSequential);

The ioHints type provides the |, &, ==, and != operators for manipulating and comparing ioHints.

The following hints will be supported:

ioHints.none: the default
ioHints.sequential: suggests that the file will be accessed sequentially
ioHints.random: suggests that the file will be accessed randomly
ioHints.prefetch: suggests that the runtime/OS should immediately begin prefetching the file contents
ioHints.mmap: suggests that mmap should be used to access the file contents

The first four of these hints map directly to hints provided to posix_fadvise and posix_madvise, with ioHints.none corresponding to POSIX_*_NORMAL and ioHints.prefetch corresponding to POSIX_*_WILLNEED. Note that ioHints.mmap does not correspond to a Posix hint, but instead suggests that mmap should be used to access the file instead of read/write. Also note that we will not support POSIX_*_DONTNEED because we currently only support ioHints when a file is opened or channel created and there is little benefit to specifying that the file contents won't be needed at that time.