#2512: Enable detection of `attribute(pure)`
Reporter:Erik Schnetter
Status:new
Milestone:
Version:development version
Type:proposal
Priority:minor
Component:Cactus

Cactus has the ability (currently disabled) to detect whether the compiler supports attribute(pure). 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.

In the flesh, notably CCTK_VarIndex and CCTKi_VarDataPtrI are declared pure. These functions are called via the macro DECLARE_CCTK_ARGUMENTS. I observe cases (e.g. when using CarpetX thorns) where enabling this attribute reduces the size of function significantly.

Note that CCTKi_VarDataPtrI 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 attribute(pure) is exactly the annotation that allows the compiler to do that.

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.

--
Ticket URL: https://bitbucket.org/einsteintoolkit/tickets/issues/2512/enable-detection-of-attribute-pure