ndmitchell / ghcid

Very low feature GHCi based IDE
Other
1.13k stars 114 forks source link

Template Haskell creates different splices with ghcid vs ghci #339

Closed davidsd closed 3 years ago

davidsd commented 3 years ago

I have some Template Haskell that finds all Show instances in scope (using reify ''Show) and creates corresponding instances of a custom typeclass Static (Show ...). It runs fine with stack build and stack ghci. However, when I use ghcid, I get a bunch of errors:

The constraint ‘Static (sop-core-0.5.0.1:Data.SOP.Constraint.All ...
is no smaller than the instance head (...) ...

Strangely, I don't use Data.SOP in my project at all! And indeed no such instances appear when I do -ddump-splices with stack build. It seems that reify ''Show is finding different Show instances when I use ghcid than when I use stack ghci or stack build.

Do you have any suggestions for what is going on and how I could mitigate the problem? I thought maybe I should change my code to only use instances from specific modules, but I can't figure out how to do that in Template Haskell.

davidsd commented 3 years ago

The problem appears to go away if I use ghcid --command "stack ghci --ghci-options=-fobject-code" (so that is what I will do for now). So I guess it's another strange thing about Template Haskell and -fno-code. Still, I'd like to understand what's going on.

davidsd commented 3 years ago

Sorry for spamming this page, but it appears that -fobject-code is not a great solution, as I'm seeing strange behavior like errors not appearing immediately on saving, errors appearing and disappearing when I add comments, etc.

ndmitchell commented 3 years ago

These all seem like underlying issues with the ghci that ghcid is being invoked with - TemplateHaskell has always been a bit odd, and buggy. If you can figure out the ideal command line, and it doesn't have a performance implication (which -fobject-code probably would), we can switch to it by default. Unfortunately, unless someone fixes ghci itself, the bugs are likely to remain :(

davidsd commented 3 years ago

That's good to know -- do you think I should file a GHC bug report about this? The problem is that I don't know precisely how to get the weird behavior with just ghci.

ndmitchell commented 3 years ago

A ghci only bug report would be great - but my experience is they rarely get fixed. I raised a bunch 6 years ago and they remain, unloved, and figuring out good but reports is a pain. It's a valuable thing to do though. I leave it to your choice.

davidsd commented 3 years ago

Sounds good. In any case, I will close this issue since it seems there isn't anything more to do here.