[fpc-devel] Compile time functions
Martok
listbox at martoks-place.de
Sun Jul 22 15:57:59 CEST 2018
Am 22.07.2018 um 06:03 schrieb J. Gareth Moreton:
> Pure functions cannot be
> evaluated at compile time if one of the arguments is a variable (or at the very
> least, not deterministic)
Do you have an idea how to prove that yet? The way I see it now, this is the
only hard issue, every other component is already present somewhere in some form.
> although there
> might still be issues in exceptional conditions (e.g. division by zero or trying
> to calculate tan(pi/2), for example).
Good point - what should happen in that case?
const
x = Pi / 0;
begin
writeln(x);
end.
That writes "+Inf".
> The other point with a "pure" modifier is that, assuming the compiler determines
> that the function is indeed pure, it would permit their assignment to a constant.
So: on processing a call to a pure function,
if arguments are constant, emit (interpreted) result of function
otherwise, emit regular call
?
What would error/warning cases be? I'd want to avoid a situation like that with
the insightful, but unfixable and thus spammy "06058_N_Call to subroutine "$1"
marked as inline is not inlined" message.
> The final issue is that while a function might be pure, you might not want to
> inline it because of its complexity, especially if it's called multiple times
> with variable arguments.
That is very true. Should the "interpretation complexity" be limited, or should
the compiler keep going and maybe run into a stack overflow?
--
Regards,
Martok
More information about the fpc-devel
mailing list