[fpc-devel] Pure function development

Florian Klämpfl florian at freepascal.org
Sat May 2 19:51:17 CEST 2020


Am 01.05.20 um 11:41 schrieb J. Gareth Moreton:
> I'm still learning these things - bear with me!  I'll get one set up 
> when I have something preliminary working.
> 
> At the moment I haven't been able to unite the constant propagation code 
> with my pure functions because they work in fundamentally different ways 
> - for inline functions constant propagation makes a copy of a node tree 
> then transmorphs them as it propagates the constants, while my code just 
> takes the node tree and steps through it without modifying it. 

I see no sense in doing so. It adds another method to do constant 
folding which needs to be maintained.

There needs to be a procedure/approach to check if a function can be 
pure. That's it. Rest can be done using the currently available constant 
folding/propagation code.

> I guess 
> there's merits for both approaches, but because of pure functions' 
> ability to be recursive, I'm worried about malicious functions causing a 
> massive ballooning of nodes and memory issues before the compiler 
> detects an infinite loop (or one that is simply too long) before 
> destroying all of the nodes again, throwing a warning and keeping the 
> original call node.  Also, there are places where nodes can't actually 
> be used, like in the definition of constants, and they simply have to 
> have their results calculated.
> 


More information about the fpc-devel mailing list