A C++ Migration Story adopting Modules

This resource first appeared in issue #22 on 01 May 2020 and has tags Technical Leadership: Software Development, Technical Leadership: Migration, Technical Leadership: Case study

Migrating large codebases to C++ Modules - Takahashi, Shadura, & Vassilev
C++ Modules in ROOT and Beyond - Vassilev, Lange, Muzzafar, Rodozov, Shadura, & Penev

C++20 is finally coming. There are five major new features - Contracts (preconditions/postconditions/assertions - which I think are potentially extremely interesting for research computing), Co-routines, Concepts, Ranges, and Modules.

Modules are probably the biggest change to the language. Ever since C, the approach that’s been taken for modularization of C/C++ code is C-preprocessor style include statements. These are hard to reason about and slow/difficult/repetitive to compile, because macros, etc defined earlier in your file - er, ‘translation unit’ - can modify the interpretation of what you’re including. You can also easily find yourself in a twisted mess of circular imports.

With modules (a good quick introduction is here), there are import and export statements setting explicit boundaries around modules and, frankly, improving clarity - it’s now much easier to understand what the interface is to a collection of code.

In the first paper, Takahashi et al. describe the partial rewrite of CERN’s ROOT to modules. For ROOT, which is (a) a huge codebase and (b) is often used in the context of a C++ interpreter/JIT system, Cling, the problem modules solve is particularly urgent. This work is completed by the second paper by Vassilev et al. They discuss both the logistics of moving a large code base to modules, and the substantial compilation/JIT performance improvements they see.

(PS, congratulations to GSOC student Arpitha Raghunandan who apparently helped with the module indexing work of the second paper).

<<<<<<< HEAD
======= >>>>>>> c1d069a... First pass at category pages