Stefan O'Rear wrote:
Niecza now supports constant folding! If you mark a sub 'is pure' and call
it with sufficiently constant arguments, it will be replaced at compile time
with the result of the call, provided said call does not throw an exception.
What constitutes "sufficiently constant" is not documented, poorly defined,
and subject to change.
You said, "provided said call does not throw an exception".
So does that mean you have also promoted some runtime exceptions to compile time
exceptions, or inlined the exception toss?
That would be useful. You don't have to wait until runtime to know that the
code is going to die unconditionally.
So constant folding can then work like this:
1. If no exception will be thrown when using the constant arguments you have,
replace the call with the result value as per usual.
2. If an exception will certainly be thrown when using the constant arguments,
then either:
2a. Where you would otherwise have put the folded result, place a "fail"/etc.
2b. Throw an exception at compile time.
Generally speaking, the more kinds of errors you can catch at compile time, the
more reliable your program is.
-- Darren Duncan