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

Reply via email to