TLDR:We have lived with .mod files for 35 years at least. That’s enough. It is time to give them up. Efficient recompilation requires fine-grained analysis. What can replace them? And what other wins can an alternative enable?
To kick off the discussion, I want to present a half-baked idea: the lazy compiler leveraging a database.
The lazy compiler, given a filename that is recognised as Source (a “load”) proceeds to complete the stages up to semantic analysis. If valid, it stores information about the canonicalised lexed source, the program units, the scopes and symbol tables, the module USE dependencies, etc in the database. Once it reads the source, what happens to the file containing the source is immaterial (e.g. it can be piped in). The context is a user-selected Fortran identifier (e.g. MAIN_WEATHER or LIB_MPI). A duplicated global identifier is identified as an error by consulting the current database (with current compilers you might get a linker error, or nonsensical/unintended results).
A special option on the compiler enables the next stage, code generation from the digested source in the database. First, the database context is consulted for existing compilations of the global identifiers. The first time, the database has none. The compiler walks the dependency chain already in the context and determines an order of compilation (including parallel jobs) and executes them. A subsequent time, after a “load” of new versions of some global identifier, a program unit (or possibly a more fine-grained entity) can be determined to not be affected by the change, and the last recorded object code is marked as valid without new code generation needed.
The essence is that the compiler is in charge of what needs to be recompiled and when, not the build system.
Shall we build it?
The evil that men do lives after them