Extending C++ Reflection for Compile-Time Automatic Differentiation

Speaker: Thomas Prideaux-Ghee, Polina Vyshnevska, Lucas Rey, Bloomberg

Abstract

In this talk, we will demonstrate a fresh compile-time approach for automatic differentiation (AD) for C++ using an extended reflection system that can inspect and transform function bodies, using working prototypes on both GCC and Clang. Unlike existing AD methods that rely on operator overloading, expression templates, runtime tapes, or compiler IR transformations (such as Enzyme), we utilize reflection (C++26) to analyse computational structure directly and transform reflected program representations to produce compilable derivative implementations via program transformation. Our proof of concept implements both forward-mode and reverse-mode differentiation, including higher-order derivatives, of a simple Black-Scholes function. A key objective of this work is to identify the minimal set of reflection features required to support a robust, language-integrated AD tool. These features are intended to inform a future ISO C++ standardisation proposal, while our current work extends the transformation pipeline to cover more complex C++ language features.