[fpc-devel] Pure function Wiki page

Thorsten Engler thorsten.engler at gmx.net
Mon Jul 9 01:18:20 CEST 2018


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.

 

And, once more, NOT A KEYWORD. It will not conflict with the use of the word “pure” in any existing code. And it will not conflict with any further uses of the word pure in any other context. It’s a context-sensitive directive, and the only context in which it can occur (and is checked for) is one in which arbitrary identifiers can NOT occur.

 

From: fpc-devel <fpc-devel-bounces at lists.freepascal.org> On Behalf Of Dmitry Boyarintsev
Sent: Monday, 9 July 2018 09:00
To: FPC developers' list <fpc-devel at lists.freepascal.org>
Subject: Re: [fpc-devel] Pure function Wiki page

 

On Sun, Jul 8, 2018 at 6:47 PM, Thorsten Engler <thorsten.engler at gmx.net <mailto:thorsten.engler at gmx.net> > wrote:

You are thinking about something like:

 

const

  x = FunctionCall(42);

 

In which case, yes, the compiler could possibly see that as in implicit “check if that function is pure”.

 

But “constant expressions” can also be something like:

 

If FunctionCall(42) > 0 then 

 

In which case you don’t want the compiler to have to test every single expression in your program to see if it is composed (all the way down) of pure functions.

 

Maybe a different approach should be taken?

Determine how much performance impact is made to determine the purity of a function. and then consider adding a new directive and a keyword.

 

thanks,

Dmitry

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20180709/4be83bda/attachment.html>


More information about the fpc-devel mailing list