compiler/ic/design.rst
We split the Nim compiler into a frontend and a backend.
The frontend produces a set of .rod files. Every .nim module
produces its own .rod file.
Advantage of the "set of files" vs the previous global database:
.rod file or from the
.nim file, there can be no inconsistency. There can also be no
partial updates.References to external modules must be (moduleId, symId) pairs. The symbol IDs are module specific. This way no global ID increment mechanism needs to be implemented that we could get wrong. ModuleIds are rod-file specific too.
There is no global state.
It's a simple binary file format. rodfiles.nim contains some details.
Nim programmers have to come to enjoy whole-program dead code elimination, by default. Since this is a "whole program" optimization, it does break modularity. However, thanks to the packed AST representation we can perform this global analysis without having to unpack anything. This is basically a mark&sweep GC algorithm:
Caching logic: Only if the set of alive symbols is different from the last run, the module has to be regenerated.