First, let's see how require should behave:
In accordance with (non-automatic) design documents ,
Alternatively, you can specify a file name directly, which installs a package that is actually anonymous for the current lexical field, and can be accessed only for any global names that the module installs:
and
Only names explicitly imported can be imported. To protect the harmfulness of the lexical panel, it cannot be changed to require .
In conjunction with S06
This call is made if and only if:
a) the compilation unit was directly called, and not required by another compilation unit [...]
As I understand it, you should not run sub MAIN that is not explicitly imported into the lexical area of ββmainline.
Unfortunately, the user documentation is quiet in case of importing the runtime via the file name and a quick look at the (authoritarian) test suite (in particular S11-modules / require.t ) do not give an answer, although I may have missed it.
Now let's see how Rakudo behaves:
As expected, import runtime through a static or dynamic module name
require main;
or
require ::('main');
will not start MAIN unless it is declared as is export and explicitly imported, i.e.
require main <&MAIN>;
and
require ::('main') <&MAIN>;
respectively.
Import via file name however
require 'main.pm6';
will start MAIN immediately.
In fact, if you do the right import through
require 'main.pm6' <&MAIN>;
sub will be executed twice: once when loading the compilation module and the second time when the runtime does its job, scanning and launching any MAIN sub in the mainline area.
Rakudo seems to refer to require with a file name argument more or less similar to EVALFILE , and executes its main line, including any sub MAIN it encounters.
This is not what I would expect and maybe just a mistake.