<HTML>
I've fixed the reference in the Wiki - it now calls "pure" a directive, not a keyword.<br>
<div><br>
</div><div>I predict that evaluating the purity of a function to be an expensive operation and something that should be avoided where possible, especially when compiling something large like Lazarus or the compiler itself.<br>
</div><div><br>
</div><div>In the Wiki, I mention the use of the Ackermann Function as an extreme test case for the compiler to see if it spots that it will take too long to evaluate, or maybe even manage some optimizations by remembering some partial results (the Wikipedia article states that the Ackermann Function is a good case for testing a compiler's ability to optimise recursion). Using a timeout is too unreliable and random, so it will have to be some kind of node count and stack depth limit... I'm pondering about 4,096 and 64 respectively, but these can be changed based on empirical tests. A node count limit will also allow the compiler to break out if you try to be malicious by writing a pure function with an infinite loop.<br>
</div><div><br>
</div><div>Originally I thought about using PascalScript to test a function for purity, but Florian turned this down due to portability issues, licensing issues and the fact that there are bugs present (it sometimes still compiles even if the script is missing essential semicolons). I hope that one can interpret the pre-compiled nodes with relative efficiency, since this will be a cross-platform solution.<br>
</div><div><br>
</div><div>Florian spoke about different compiler versions, and the more I think of it, I believe this will be an iterated development. For example, initially I will try to get it to work with ordinal and floating-point types, while strings and record types will come later, especially the former since they are dynamic memory objects and might be a bit tricky to work with. Who knows... maybe they aren't that bad in practice.</div><div><br>
</div><div>As a side-note, it might also be possible to make assembler routines pure (e.g. the Int and Frac functions if they weren't internal compiler procedures), but this will require a different kind of interpretation that I consider low-priority for now, especially as it will have to be different for each platform. I might still research this as part of my work on my deep optimizer.<br>
</div> <div><br>
</div><div>Gareth</div><div><br>
</div><br>
<span style="font-weight: bold;">On Mon 09/07/18 00:18 , "Thorsten Engler" thorsten.engler@gmx.net sent:<br>
</span><blockquote style="BORDER-LEFT: #F5F5F5 2px solid; MARGIN-LEFT: 5px; MARGIN-RIGHT:0px; PADDING-LEFT: 5px; PADDING-RIGHT: 0px"><defanged_meta http-equiv="Content-Type" content="text/html; charset=utf-8"><defanged_meta name="Generator" content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:PMingLiU;
panose-1:2 2 5 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@PMingLiU";
panose-1:2 2 5 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--><defanged_body link="blue" vlink="purple" lang="EN-AU"><div class="WordSection1"><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Maybe you don’t understand what “determine the purity of a function” means?<o:p></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">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).<o:p>
</o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">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.<o:p></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span>
</p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">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.<o:p></o:p></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">
<o:p> </o:p></span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt"><div><div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm"><p class="MsoNormal"><span style="font-size: 11pt; font-family: "Calibri", sans-serif; font-weight: bold;" lang="EN-US">From:</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" lang="EN-US"> fpc-devel <fpc-devel-bounces@lists.freepascal.org> <span style="font-weight: bold;">On Behalf Of </span>Dmitry Boyarintsev<br>
<span style="font-weight: bold;">Sent:</span> Monday, 9 July 2018 09:00<br>
<span style="font-weight: bold;">To:</span> FPC developers' list <fpc-devel@lists.freepascal.org><br>
<span style="font-weight: bold;">Subject:</span> Re: [fpc-devel] Pure function Wiki page<o:p></o:p></fpc-devel@lists.freepascal.org></fpc-devel-bounces@lists.freepascal.org></span></p></div></div><p class="MsoNormal"><o:p> </o:p></p><div><div><div><p class="MsoNormal">On Sun, Jul 8, 2018 at 6:47 PM, Thorsten Engler <<a href="mailto:thorsten.engler@gmx.net">thorsten.engler@gmx.net</a>> wrote:<o:p></o:p></p><blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div><div><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">You are thinking about something like:</span><o:p></o:p></p><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span><o:p></o:p></p><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">
const</span><o:p></o:p></p><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> x = FunctionCall(42);</span><o:p></o:p></p><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span><o:p></o:p></p><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">
In which case, yes, the compiler could possibly see that as in implicit “check if that function is pure”.</span><o:p></o:p></p><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span><o:p></o:p></p><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">But “constant expressions” can also be something like:</span>
<o:p></o:p></p><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> </span><o:p></o:p></p><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">If FunctionCall(42) > 0 then </span><o:p></o:p></p><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">
</span><o:p></o:p></p><p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">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.</span><o:p></o:p></p></div></div></blockquote><div><p class="MsoNormal"><o:p> </o:p></p></div><div><p class="MsoNormal">Maybe a different approach should be taken?<o:p>
</o:p></p></div><div><p class="MsoNormal">Determine how much performance impact is made to determine the purity of a function. and then consider adding a new directive and a keyword.<o:p></o:p></p></div><div><p class="MsoNormal"><o:p> </o:p></p></div><div><p class="MsoNormal">thanks,<o:p></o:p></p></div><div><p class="MsoNormal">Dmitry<o:p></o:p></p></div></div></div></div></div></div>
_______________________________________________<br>
fpc-devel maillist - <a href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a><br>
<a target="_blank" href="<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>"><span style="color: red;">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</span></a><br>
<br>
</defanged_body></defanged_meta></defanged_meta></blockquote></HTML>