Hi, I’m Fraser and I work on the compiler team.
I’d like to propose a small change to how mojo run (and mojo debug) handle the split between compiler and program arguments. I’m looking for community feedback and whether people would find it valuable.
As you probably know, mojo run has the following form:
mojo [compiler-options] input.mojo [program-args]
That is, everything before the input filename is treated as a compiler option, and everything after the filename is passed on to the program when it’s run.
I and others have in the past found this behaviour unintuitive. My primary concern is a user thinking they are passing a compiler option when in fact it’s silently being passed to a program that ignores it. For example: wondering why a compiled program doesn’t set the right define; why it doesn’t enable an optimization you’re asking for; why it doesn’t compile for the right CPU:
mojo input.mojo --mcpu=haswell -Dfoo=42 --make-it-fast
These scenarios could all do the wrong thing quite silently.
I therefore propose that we split compiler and program arguments with a double-dash --.
mojo [compiler-options-or-input-file] [-- [program-args]]
This form would make clear the distinction between the two options categories. This could be useful, e.g., if the compiler and program accept similar-looking options (e.g., --help). It also allows compiler options to be interleaved with the input file.
For example:
mojo run --A --B input.mojo --C -- --D E F
With this form, options --A, --B, and --C are passed to the compiler, and arguments --D, E, and F are passed to the program.
There is precedent for this sort of argument handling, including in POSIX guidelines and amongst some other common developer tools.
This would be a breaking change, as any scripts or workflows currently passing arguments to the program (after the input file) would suddenly start passing them to the compiler. This would more likely than not result in a compiler error (as it will error on any unrecognized arguments) but that’s not universally true.
I look forward to your feedback!