Description
The blog post [The Interface for Multiple Home Units](https://well-typed.com/blog/2022/01/multiple-home-units/#closure-property-for-home-units) explains the closure property needed for setting up a multiple component session.
HLS does not ensure this holds which leads to broken sessions when loading multiple components. For example.. random overlapping instance errors, panics in checkFamConst etc etc. It is critical that any session which HLS constructs obeys the closure property.
Stated simply the closure property is:
Any dependency which is not a home unit must not (transitively) depend on a home unit.
And in terms of implementation there is a function in GHC called checkHomeUnitsClosed
which implements this check and reports the reason why it's not closed.
My proposal is
- If a new unit is added and the closure property doesn't hold, then the error is reported prominently to the user and the new component is ignored completely by the IDE.
- If a user then subsequently adds the units needed for closure then the session can resume in a multi-component manner.
My experience is that multi-component works without problem as long as the closure property. I spent the last week using the support whilst developing cabal-install, which has 5 components.
In the future:
There should be a better interface for initialising a session which contains multiple components rather than having to create the session incrementally one component at a time.