No KnotVars should be live at the end of upsweep
There is a simple invariant which should hold for the KnotVars constructor:
- At the end of upsweep, there should be no live KnotVars
This invariant is difficult to test but easy to check using ghc-debug. The usage of NoKnotVars is intended to make this invariant easier to check.
The most common situation where a KnotVars is retained accidentally is if a HscEnv which contains reference to a KnotVars is used during interface file loading. The thunks created during this process will retain a reference to the KnotVars. In theory, all these references should be removed by 'typecheckLoop' as that retypechecks all interface files in the loop without using KnotVars.
At the time of writing (MP: Oct 21) the invariant doesn't actually hold but also doesn't seem to have too much of a negative consequence on compiler residency. In theory it could be quite bad as each KnotVars may retain a stale reference to an entire TypeEnv.