Re: [fpc-devel] Return to pure functions!

2019-09-19 Thread Sven Barth via fpc-devel

Am 19.09.2019 um 20:25 schrieb J. Gareth Moreton:
One thing I've fallen foul of is how to track variables in what will 
become the 'node parser' that the compiler will use to evaluate pure 
functions to calculate their return values.  Because a variable can be 
anything, I was planning on using the Variant type, mainly because it 
contains a union that has everything I need in terms of recording what 
type a variable is and how its value is stored, and I would only end 
up duplicating that. However, the bootstrapper can't find the 
'variants' unit.  Given that no other part of the compiler uses the 
Variant type, is there a rule against using it, or a way to help Make 
find the 'variants' unit?


Only units in the rtl directory can be used. While in theory the 
Variants unit could be moved from packages/rtl-objpas back to rtl I 
doubt that it is desired to have that behemoth used inside the compiler. 
If you need something better use TVarRec instead, it's what is backing 
"array of const" and is available in the System unit.


Submitting everything at once at the end may not be the best approach 
for this, as I or others might find future optimisations for pure 
functions later on (like ascending a pure function call outside of a 
for-loop if it doesn't depend on the loop counter, so it is only 
called once and its return value referenced as needed later on). My 
thought on a first patch is to have the compiler at least recognise 
the 'pure' directive even if it doesn't yet do anything.  Is that 
permissible?
In my opinion the first part that's integrating should be something 
that's already working. Just parsing a dirctive is not something I 
consider "working" (which is also why I'm no fan of parsing, but 
ignoring the "delayed" directive for delay loading), especially as we'd 
want to get a feeling for the feature and its uses. Thus as a first step 
I'd suggest at least simple functions without variables and loops.


Regards,
Sven
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


[fpc-devel] Return to pure functions!

2019-09-19 Thread J. Gareth Moreton

Hi everyone,

The Curious Kit is back!  While I'm still waiting on my optimiser 
overhaul and the node semantic pass to be approved (or rejected), I've 
gone to taking a fresh look at pure functions, especially as I know more 
about the node pass stage (after my work on the semantic pass).


I've managed to resolve the merge conflicts and the compiler at least 
recognises the 'pure' directive and does some preliminary checks.


One thing I've fallen foul of is how to track variables in what will 
become the 'node parser' that the compiler will use to evaluate pure 
functions to calculate their return values.  Because a variable can be 
anything, I was planning on using the Variant type, mainly because it 
contains a union that has everything I need in terms of recording what 
type a variable is and how its value is stored, and I would only end up 
duplicating that. However, the bootstrapper can't find the 'variants' 
unit.  Given that no other part of the compiler uses the Variant type, 
is there a rule against using it, or a way to help Make find the 
'variants' unit?


There's still a few things I'm working out, like originally I thought 
that if a function has a 'var' parameter, then it cannot be pure, but 
this is not always the case, because if the actual parameter (what 
you're passing into it when calling said function) has a value that is 
deterministic, then you can theoretically evaluate the function at 
compile-time so long as it doesn't break any rules like accessing a 
file.  Most likely this will be an on-going project that I'll build in 
segments, and I'll make a full design specification to go with it, at 
least for my own benefit.


Submitting everything at once at the end may not be the best approach 
for this, as I or others might find future optimisations for pure 
functions later on (like ascending a pure function call outside of a 
for-loop if it doesn't depend on the loop counter, so it is only called 
once and its return value referenced as needed later on).  My thought on 
a first patch is to have the compiler at least recognise the 'pure' 
directive even if it doesn't yet do anything.  Is that permissible?


Gareth aka. Kit


---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel