<html>#2512: Enable detection of `attribute(pure)`
<table style='border-spacing: 1ex 0pt; '>
<tr><td style='text-align:right'> Reporter:</td><td>Erik Schnetter</td></tr>
<tr><td style='text-align:right'>   Status:</td><td>new</td></tr>
<tr><td style='text-align:right'>Milestone:</td><td></td></tr>
<tr><td style='text-align:right'>  Version:</td><td>development version</td></tr>
<tr><td style='text-align:right'>     Type:</td><td>proposal</td></tr>
<tr><td style='text-align:right'> Priority:</td><td>minor</td></tr>
<tr><td style='text-align:right'>Component:</td><td>Cactus</td></tr>
</table>

<p>Cactus has the ability (currently disabled) to detect whether the compiler supports <code>attribute(pure)</code>. Pure functions do not have side effects and are only called for their result. This allows the compiler to avoid calling a function if the result is not used.</p>
<p>In the flesh, notably <code>CCTK_VarIndex</code> and <code>CCTKi_VarDataPtrI</code> are declared <code>pure</code>. These functions are called via the macro <code>DECLARE_CCTK_ARGUMENTS</code>. I observe cases (e.g. when using CarpetX thorns) where enabling this attribute reduces the size of function significantly.</p>
<p>Note that <code>CCTKi_VarDataPtrI</code> is somewhat expensive. (I traced its call chain, and the way it checks whether the scheduled function has access to a given variable and time level is surprisingly duplicitous.) Independent of that, not calling this function if the grid variable isn’t actually used would be good, and <code>attribute(pure)</code> is exactly the annotation that allows the compiler to do that.</p>
<p>In the past, I suspected this attribute to cause miscompiled code, at least on some systems with some compilers. We’ll have to test carefully when and where to enable it.</p>
<p>--<br/>
Ticket URL: <a href='https://bitbucket.org/einsteintoolkit/tickets/issues/2512/enable-detection-of-attribute-pure'>https://bitbucket.org/einsteintoolkit/tickets/issues/2512/enable-detection-of-attribute-pure</a></p>
</html>