[fpc-devel] Pure function Wiki page
J. Gareth Moreton
gareth at moreton-family.com
Sun Jul 8 18:06:47 CEST 2018
What Florian said. Only particular functions can be pure, and even if they
are marked as such, the compiler has to make sure they are fulfil a strict
set of criteria that requires a degree of data flow analysis, and this can
quickly take far too long to complete, especially if the function contains
a loop of some kind.
It is a slightly tricky design, because I want to make sure a programmer
can't write something that will crash the compiler (which is why I mention
the Ackermann Function as a test case).
Anything that dereferences a pointer or accesses a dynamic array (which,
internally, is a pointer to something on the heap) cannot be pure, and this
covers the vast majority of the functions, but depending on how the
function is written, it may not be apparent until the compiler has analysed
the majority of the compiled nodes.
Just note... though strictly speaking, only functions can be pure, I
haven't explicitly forbidden procedures from being pure, because if they
have out parameters, then as long as they fulfil all the other criteria,
they can be considered a function with multiple return values. Note that
the presence of a var parameter instantly makes a function impure on
account that the argument is, by definition, not constant.
Gareth
On Sun 08/07/18 17:59 , Florian Klämpfl florian at freepascal.org sent:
Am 08.07.2018 um 18:55 schrieb Marco van de Voort:
> In our previous episode, J. Gareth Moreton said:
>> wiki.freepascal.org/Pure_functions
>> I hope it proves useful to explain what I'm doing. How do the proposals
>> look so far, Florian?
>
> It doesn't explain why you chose for a modifier rather than preprocessor
> switch.
Why a preprocessor switch for something which applies to a particular
function?
_______________________________________________
fpc-devel maillist - fpc-devel at lists.freepascal.org [1]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
[2]">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
Links:
------
[1] mailto:fpc-devel at lists.freepascal.org
[2] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180708/69ac9ebe/attachment.html>
More information about the fpc-devel
mailing list