haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.62k stars 697 forks source link

Document the interaction between Backpack and Template Haskell #7353

Open danidiaz opened 3 years ago

danidiaz commented 3 years ago

Perhaps the Backpack section of the user guide could devote a paragraph or subsection to explaining the interaction between indefinite libraries and TH code.

I've found that splicing TH code from libraries that are still indefinite (that is: libraries that have module signatures still unfilled) causes errors like

ghc: ^^ Could not load 'lesson9zmtemplatezmhaskellzm1zi0zi0zi0zminplacezmcorezmAfo5JIVDJVcCScFF1FkCSzz_CoreziTH_makeIdFunc_closure', dependency unresolved. See top entry above.
GHC.ByteCode.Linker.lookupCE
During interactive linking, GHCi couldn't find the following symbol:
  lesson9zmtemplatezmhaskellzm1zi0zi0zi0zminplacezmcorezmAfo5JIVDJVcCScFF1FkCSzz_CoreziTH_makeIdFunc_closure

I wrote a longer description of the problem here.

I'm not 100% sure, but the problem might be that indefinite libraries get typecheked, but not compiled down to object code (they can't be, because they have "holes" in the form of module signatures).

Therefore, when splicing the code, there's no actual TH code to run! So this is not a bug, but an insurmountable limitation of Backpack (although the errors could be better).

fgaz commented 3 years ago

/cc @ezyang

ezyang commented 3 years ago

Yes, this diagnosis is absolutely correct. (And the error message could definitely be better, though I'm not sure exactly where to put it.)