Enable -dcmm-lint by default for handwritten Cmm sources
I’ve been working recently on implementing my delimited continuations proposal, which has involved writing some RTS Cmm code by hand. At one point, I made the mistake of using an I32
where an I64
was expected, by writing something like this:
W_ y;
y = SomeClosure_some_i32_field(x);
This was not caught by the compiler and instead simply led to incorrect codegen (as it did not do any implicit widening). This unfortunately took me quite some time to track down, as the compiler gave me no indication that anything might be amiss.
However, this issue is caught reliably by -dcmm-lint
, and I would argue that it’s more than mere “linting” when the Cmm source is handwritten. In that case, -dcmm-lint
is really functioning more like the typechecker, since lint failures might respresent legitimate problems in the source program rather than issues internal to the compiler.
For that reason, I propose -dcmm-lint
be enabled by default when directly compiling any .cmm
source file. The overhead of doing this should be essentially invisible, as GHC’s ability to compile Cmm sources is not really a user-facing feature, and it mostly only exists for ease of implementation of the RTS. At the time of this writing, the RTS includes a grand total of 10 .cmm
source files, so enabling -dcmm-lint
in those cases would be essentially free.
(Since the only use of .cmm
compilation is really in the GHC build process, it would also be fine to just adjust the GHC build systems to automatically pass -dcmm-lint
when compiling Cmm files, on all build flavours, but adding this logic in the compiler itself seems entirely reasonable to me and would be slightly neater.)