My idea is to create something between current implementation and iterative compilation, similar to DLL system:
- When module is compiled, if something is declared as 'shared', store any additional data required for subsequent compilation
- Introduce new keyword 'using', in global statement like: using MyModule;
- If module is using another one, it gains access to any shared information stored on that module (and any information from modules it is using)
- If module we depend on is not found/compiled, emit compile error (and stop)
- Every time module is used by another one, increase some usage counter (Modules have to keep track on what they depend on, to decrease this usage counter when discarded)
- If module has usage counter > 0, then it cannot be discarded or recompiled (so it cannot be discarded until all depended modules are)
Such method would reduce number of compiled files (no redundancy) and also guarantee that shared global variables are always valid.
It would require new 'using' (or similar) keyword, and some structures (and possibly interface methods) to keep track of dependencies.
So, what do you think?