I'm not familiar with Nim's compiler internals, so someone correct me if I'm wrong (and I'm sorry if so), but:
Nim's `import` isn't like C, which has loads every file you `#include`. When Nim `import`'s a module, it reads a symbol file. This is relatively quick. Nim can also `include` a file, much like C, but this is rarer. So, your suggested optimization might well give the Nim compiler a marginal improvement with `import`, but it would also add a fair amount of complexity, and the improvement would be marginal. There's a paper somewhere about something like this in the Oberon compiler, decades ago. PS If I'm wrong I'll be happy to know.