Ensure modules are loaded independently

Fixes #1021
This also exposed a couple of bugs in the library, in which things were
being used but not imported, but we were getting away with it because of
the previous problem.

This relies on a bit of a hack to preserve missing cases, type inference
information and interactive editing data, which is not saved in ibcs,
but should be.