Backpack puts information in the EPS that depends on the HPT, causing issues with recompilation
I've noticed a strange interaction of Backpack with GHCi
. For readability I'm giving the test case as a .bkp
, but note that as --backpack
isn't supported by GHCi
, the actual test case uses cabal.
unit p where
signature H where
data S1
data S2
module A where
import H
data T = T S1 S2
unit q where
dependency p[H=<H2>] (A as A2)
module L where
data S1 = MkS1
signature H2(S1(MkS1), S2) where
import L
data S2
module B where
import A2
import H2
t = T :: S1 -> S2 -> T
When processing q
, we instantiate p
with H = H2
and add it to the EPS, even though it refers to L
and H2
which are in the HPT. This is a problem, as the EPS is supposed to only contain stable information, whereas the HPT can be updated; any change to the HPT will not be reflected in the EPS and thus will refer to out of date information.
To demonstrate this, we can load everything in GHCi, change H2
and reload. (Recall: using cabal, not --backpack
mode which doesn't work with GHCi
.)
[1 of 2] Compiling H[sig] ( p\H.hsig, nothing )
[2 of 2] Compiling A ( p\A.hs, nothing )
[1 of 1] Instantiating bkp10-0-inplace-p
[1 of 4] Compiling H2[sig] ( q\H2.hsig, nothing )
[2 of 4] Instantiating bkp10-0-inplace-p
[3 of 4] Compiling B ( q\B.hs, nothing )
[4 of 4] Compiling L ( q\L.hs, nothing )
Ok, three modules loaded.
now I change H2 so that S1 is defined in H2 instead of imported from L
ghci> :r
[2 of 4] Compiling H2[sig] ( q\H2.hsig, nothing ) [Source file changed]
[3 of 4] Instantiating bkp10-0-inplace-p
[4 of 4] Compiling B ( q\B.hs, nothing ) [H2 changed]
q\B.hs:4:9: error:
* Couldn't match type `{H2.S1}' with `S1'
Expected: S1 -> S2 -> T
Actual: {H2.S1} -> S2 -> T
NB: `S1' is defined at q\L.hs:3:3-16
`{H2.S1}' is defined at q\H2.hsig:3:5-11
if I quit and restart, it works:
[1 of 1] Instantiating bkp10-0-inplace-p
[3 of 4] Instantiating bkp10-0-inplace-p
[4 of 4] Compiling B ( q\B.hs, nothing ) [H2 changed]
Ok, three modules loaded.