Speculative evaluation of expressions
We should try to speculatively evaluate expressions that are known to terminate "rapidly" (more on that below). In particular, that concerns turning let bindings that are ok-for-spec according to
exprOkForSpeculation (which will be our oracle regarding which expressions terminate rapidly) into case bindings and similarly for arguments in an application.
The most obvious place where this should be done is
CorePrep, where we already decide whether to turn call-by-need into call-by-name or call-by-value. Speculative execution would turn call-by-need into call-by-value for rapidly terminating arguments and RHSs.
What does it mean for an expression to terminate rapidly? Well, it better not diverge in any way! There are a few other conditions which all perfectly fit what's written in the haddock for
exprOfForSpeculation. The only fuzzy thing there is the "soon" bit, which is equally fuzzy as saying "rapidly". We should probably find a cost metric at some point, but let's first explore what we can do in this space.
The hope is that the "terminates rapidly" property can be vastly improved by the termination analysis that is needed for Nested CPR in !1866.