Add tail-recursion modulo cons (TMC) optimisation #1089
Labels
enhancement
medium effort
medium reward
Easy to measure but may not be noticed by itself
performance
Runtime of a plausible real cakeml-generated binary
student project
can be done as a student project (at various levels)
This issue is about adding tail-recursion modulo cons (TMC) as a new optimisation to the CakeML compiler. The idea is to automatically transform non-tail-recursive functions such as
into tail-recursive functions:
or, if the original function is large and we don't want to duplicate it, into
append'
as above and the following:Concretely, the the context
ctxt
is a reference to aMutableBlock
and an offset where the primitive for plugging (→
) the hole inMutableBlock
is to add the new element.This optimisation is to happen around bvl-to-bvi in the compiler. It uses mutable state as a temporary, but returns on completion exactly the same immutable result as the original version of the code.
This is suitable as a student project. Contact me (myreen) on the CakeML Discord to discuss details.
The text was updated successfully, but these errors were encountered: