MLton/mlton

Internal compiler error when trying to build RedPRL

Closed this issue · 2 comments

Trying to build a newly-cloned RedPRL, (using today's git master mlton), results in the attached exception:
typescript.txt

Confirmed; seems to have been introduced by #304, because compiling RedPRL with 05004a0 works without error. There are no type errors reported for any of the IR programs. Hopefully a git bisect will help to narrow down the error; my suspicion would be 136f357 .

As I suspected, the first bad commit was 136f357, although I thought the error would be with a CReturn block, but instead it was with a Jump block.

The intended purpose of 136f357 was to omit copying values returned via the ML stack on non-tail calls to Cont (normal return) and Handle (exceptional return) blocks and to omit copying a result returned from a CCall to a CReturn block; essentially, the receiving block is required to accept those arguments due to calling convention, but the argument may not be otherwise used, so the copies are extraneous.

The implementation of 136f357 simply omitted allocating a location (Machine IR stack slot or register (local)) for any unused argument of any block. The assumption was that only Cont, Handle, and CReturn blocks could have unused arguments; it was assumed that previous optimizations would eliminate any argument of a Jump block that was unused. However, with RedPRL, there is (at least one) Jump block with an unused argument; that argument is not assigned a location, so the Option exception is raised when trying to implement a Goto transfer that copies the actual operands to the formal arguments (and the corresponding formal argument doesn't exist).

The fix should be relatively straight forward: only copy the actual arguments that correspond to formal arguments that are used; this is essentially the same filtering that is used to implement the prologue of Cont and Handle blocks. However, I am curious about why the argument of this Jump block is unused in the RSSA IR, but was not eliminated by the removeUnused optimization passes in the SSA and SSA2 IRs.