16.4 Stable Translations

While a translator provides the ability to convert information into a stable data structure, it does not necessarily resolve all stability issues that can arise in translating data. For example, if the input expression for an xlate operation itself references Unstable data, the resulting D program is also Unstable because program stability is always computed as the minimum stability of the accumulated D program statements and expressions. Therefore, it is sometimes necessary to define a specific stable input expression for a translator in order to permit stable programs to be constructed. The D inline mechanism can be used to facilitate such stable translations.

The DTrace procfs.d library provides the curlwpsinfo and curpsinfo variables described earlier as stable translations. For example, the curpsinfo and curlwpsinfo variables are actually inline declared as follows:

inline psinfo_t *curpsinfo = xlate <psinfo_t *> (curthread);
#pragma D attributes Stable/Stable/Common curpsinfo

inline lwpsinfo_t *curlwpsinfo = xlate <lwpsinfo_t *> (curthread);
#pragma D attributes Stable/Stable/Common curlwpsinfo

Both curpsinfo and curlwpsinfo are defined as inline translations from the curthread variable, a pointer to the kernel's Private data structure representing a process descriptor, to the Stable lwpsinfo_t type. The D compiler processes this library file and caches the inline declarations, making curpsinfo and curlwpsinfo appear as any other D variable. The #pragma statement following the declaration is used to explicitly reset the attributes of the curpsinfo and curlwpsinfo identifiers to Stable/Stable/Common, masking the reference to curthread in the inline expressions.