New Issue: What should ''on myFile'' do?

20242, "benharsh", "What should ''on myFile'' do?", "2022-07-18T21:20:11Z"

On-statements like on expr are usually implemented as on expr.locale. Currently the file type stores the locale on which the file was opened, and channels will use on-statements internally when reading/writing from another locale. Currently an expression like on myFile will use myFile.locale rather than myFIle.home, and these two might not be the same.

Consider the following program:

use IO;
use CommDiagnostics;

proc main() {
  var myFile : file;

  on Locales.last {
    myFile = open("someFile.txt", iomode.cw);
  }

  writeln("myFile.home = ", myFile.home);
  writeln("myFile.locale = ", myFile.locale);

  writeln();
  writeln("'on myFile'");
  startCommDiagnostics();
  on myFile {
    writeln("Writing on: ", here);
    var w = myFile.writer();
    for i in 1..10 do
      w.writeln(i);
  }
  stopCommDiagnostics();
  printCommDiagnosticsTable();
  resetCommDiagnostics();

  writeln();
  writeln("'on myFile.home'");
  startCommDiagnostics();
  on myFile.home {
    writeln("Writing on: ", here);
    var w = myFile.writer();
    for i in 1..10 do
      w.writeln(i);
  }
  stopCommDiagnostics();
  printCommDiagnosticsTable();
}

Running with two locales:

myFile.home = LOCALE1
myFile.locale = LOCALE0

'on myFile'
Writing on: LOCALE0
> locale | get_nb | put_nb | execute_on | cache_get_hits | cache_get_misses | cache_put_hits | cache_put_misses |
> -----: | -----: | -----: | ---------: | -------------: | ---------------: | -------------: | ---------------: |
>      0 |      0 |      0 |         13 |              0 |                0 |              0 |                0 |
>      1 |     15 |      4 |          1 |             15 |               15 |              1 |                4 |

'on myFile.home'
Writing on: LOCALE1
> locale | get_nb | execute_on | cache_get_hits | cache_get_misses |
> -----: | -----: | ---------: | -------------: | ---------------: |
>      0 |      9 |          1 |              5 |                9 |
>      1 |      2 |          1 |              8 |                2 |

We see 13 on-statements in the on myFile case, indicating that we're not executing on the locale where IO writes are actually occurring.

Some relevant questions:

Should we provide a way to override/implement .locale ?

Should we define a method on file that exposes the home value?