[fpc-devel] Progress on pure functions

J. Gareth Moreton gareth at moreton-family.com
Thu Dec 15 22:47:48 CET 2022


What I mean is that if a function is marked as "pure" or "inline" (or 
both), only one copy of the unoptimised node tree is stored in the 
"inlininginfo" field, and both "pass1_pure" and "pass1_inline" duplicate 
this tree and transform it as needed.  Because only the unoptimised tree 
is stored, I felt there was no need to store this twice (doing so would 
also increase the size of PPU files).

Kit

On 15/12/2022 21:39, Sven Barth wrote:
> Am 14.12.2022 um 12:15 schrieb J. Gareth Moreton via fpc-devel:
>>
>> To better explain how purity analysis currently works (I'm sure 
>> there's a better name than "purity analysis"), it takes a copy of the 
>> unoptimised node tree (this is the same as the tree used for inline, 
>> and for a space saving, they share the same field), adds explicit 
>> definitions for the formal parameters so they equal the constants 
>> passed in, and then tries to collapse the node tree down to a single 
>> assignment to the result.  This is done by running the following 
>> operations in this order:
>>
>
> What do you mean with “share the same field”? A pure function might 
> still be called and inlined like a normal function and for that you 
> shouldn't transform the node tree needlessly as that might influence 
> the debugging experience. So you should have two different copies, one 
> for inlining and one for pure related transformations.
>
> Regards,
> Sven
>


More information about the fpc-devel mailing list