[fpc-devel] Pure function Wiki page

Dmitry Boyarintsev skalogryz.lists at gmail.com
Mon Jul 9 02:21:14 CEST 2018


On Sun, Jul 8, 2018 at 7:18 PM, Thorsten Engler <thorsten.engler at gmx.net>
wrote:

> Maybe you don’t understand what “determine the purity of a function” means?
>
>
>
> It means that every time any function is called, the compiler has to try
> to execute the function at compile time (by working through the nodes like
> an interpreter) until it hits a point that is non-deterministic. This can
> potentially take forever (the halting problem is real!), so the only thing
> limiting it is basically some form of timeout (defined as either time spend
> or nodes traverse).
>
>
>
> If you are talking about always considering every function as pure until
> proven otherwise, you are talking about slowing down the compiler by orders
> of magnitude.
>

I'm taking about considering every function that's **used to calculate a
constant expression** as a pure function (not just every function).
(how many of:
If FunctionCall(42) > 0 then
vs
If FunctionCall(x) > 0 then
is out there?)

Naturally, if a parameters of pure function are variable of any kind, the
evaluation cannot be done in compile time anyway.

So, if a function (even if it's a pure function) is not used for constant
expression valuation, there's no point in the actual "determination of
purity" (in it's full meaning).

The compiler knows if a function potentially impure w/o the actual
evaluation or interpretation, solely based on what data it's using.

Even if you deal with functions marked by a developer as "pure", the
problem of full determination of purity remains.

thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180708/55ff3d45/attachment.html>


More information about the fpc-devel mailing list