Skip to content

Commit 807cb8f

Browse files
Warn if TH and Mac and static binary (#2470)
* Warn if TH and Mac and static binary * fix up the instructions * use hostIsDynamic * Upgrade hie-bios version * bump cabal index * fix more Stack descriptors Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 3b581a1 commit 807cb8f

11 files changed

+48
-17
lines changed

cabal-ghc901.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ package *
3737

3838
write-ghc-environment-files: never
3939

40-
index-state: 2021-11-29T08:11:07Z
40+
index-state: 2021-11-29T12:30:07Z
4141

4242
constraints:
4343
-- These plugins don't work on GHC9 yet

cabal-ghc921.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ package *
3636

3737
write-ghc-environment-files: never
3838

39-
index-state: 2021-11-29T08:11:07Z
39+
index-state: 2021-11-29T12:30:07Z
4040

4141
constraints:
4242
-- These plugins doesn't work on GHC92 yet

cabal.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ package *
4040

4141
write-ghc-environment-files: never
4242

43-
index-state: 2021-11-29T08:11:07Z
43+
index-state: 2021-11-29T12:30:07Z
4444

4545
constraints:
4646
hyphenation +embed

docs/troubleshooting.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,11 @@ An usual symptom is the presence of errors containing `unknown symbol` and it is
3636

3737
The workaround is to use a version of haskell-language-server compiled from source with the ghc option `-dynamic` enabled. See more details [here](https://github.com/haskell/haskell-language-server/issues/1160#issuecomment-756566273).
3838

39-
### Problems with Template Haskell
39+
### Support for Template Haskell
4040

41-
Due to how Template Haskell code is evaluated at compile time and some limitations in the interaction between HLS and GHC, the loading of modules using TH can be problematic.
41+
Template Haskell should work fine in Linux and Windows with the distributed binaries. In Mac Os a dynamically linked binary of HLS is required to avoid segmentation faults. The easiest way to obtain a dynamically linked HLS binary is to build it locally. With cabal install this can be done as follows:
4242

43-
The errors thrown are usually related to linking and usually make HLS crash: `Segmentation fault`, `GHC runtime linker: fatal error`, etc
44-
45-
A workaround which has helped in some cases is to compile HLS from source with the ghc option `-dynamic` enabled, as in the previous issue.
46-
47-
We have a [dedicated label](https://github.com/haskell/haskell-language-server/issues?q=is%3Aissue+is%3Aopen+label%3A%22type%3A+template+haskell+related%22) in the issue tracker and an [general issue](https://github.com/haskell/haskell-language-server/issues/1431) tracking support for TH.
43+
cabal update && cabal install haskell-language-server --enable-executable-dynamic
4844

4945
## Troubleshooting the server
5046

ghcide/ghcide.cabal

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ library
106106
ghc-check >=0.5.0.4,
107107
ghc-paths,
108108
cryptohash-sha1 >=0.11.100 && <0.12,
109-
hie-bios >= 0.7.1 && < 0.9.0,
109+
hie-bios >= 0.8 && < 0.9.0,
110110
implicit-hie-cradle >= 0.3.0.5 && < 0.4,
111111
base16-bytestring >=0.1.1 && <1.1
112112
if os(windows)

ghcide/src/Development/IDE/Core/Rules.hs

+36-4
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ import qualified GHC.LanguageExtensions as LangExt
136136
import qualified HieDb
137137
import Ide.Plugin.Config
138138
import qualified Language.LSP.Server as LSP
139-
import Language.LSP.Types (SMethod (SCustomMethod))
139+
import Language.LSP.Types (SMethod (SCustomMethod, SWindowShowMessage), ShowMessageParams (ShowMessageParams), MessageType (MtInfo))
140140
import Language.LSP.VFS
141141
import System.Directory (makeAbsolute)
142142
import Data.Default (def, Default)
@@ -149,6 +149,15 @@ import Ide.PluginUtils (configForPlugin)
149149
import Ide.Types (DynFlagsModifications (dynFlagsModifyGlobal, dynFlagsModifyParser),
150150
PluginId)
151151
import Control.Concurrent.STM.Stats (atomically)
152+
import Language.LSP.Server (LspT)
153+
import System.Environment (getExecutablePath)
154+
import System.Process.Extra (readProcessWithExitCode)
155+
import Text.Read (readMaybe)
156+
import System.Info.Extra (isMac)
157+
import HIE.Bios.Ghc.Gap (hostIsDynamic)
158+
159+
templateHaskellInstructions :: T.Text
160+
templateHaskellInstructions = "https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html#support-for-template-haskell"
152161

153162
-- | This is useful for rules to convert rules that can only produce errors or
154163
-- a result into the more general IdeResult type that supports producing
@@ -820,8 +829,26 @@ isHiFileStableRule = defineEarlyCutoff $ RuleNoDiagnostics $ \IsHiFileStable f -
820829
summarize SourceUnmodified = BS.singleton 2
821830
summarize SourceUnmodifiedAndStable = BS.singleton 3
822831

832+
displayTHWarning :: LspT c IO ()
833+
displayTHWarning
834+
| isMac && not hostIsDynamic = do
835+
LSP.sendNotification SWindowShowMessage $
836+
ShowMessageParams MtInfo $ T.unwords
837+
[ "This HLS binary does not support Template Haskell."
838+
, "Follow the [instructions](" <> templateHaskellInstructions <> ")"
839+
, "to build an HLS binary with support for Template Haskell."
840+
]
841+
| otherwise = return ()
842+
843+
newtype DisplayTHWarning = DisplayTHWarning (IO ())
844+
instance IsIdeGlobal DisplayTHWarning
845+
823846
getModSummaryRule :: Rules ()
824847
getModSummaryRule = do
848+
env <- lspEnv <$> getShakeExtrasRules
849+
displayItOnce <- liftIO $ once $ LSP.runLspT (fromJust env) displayTHWarning
850+
addIdeGlobal (DisplayTHWarning displayItOnce)
851+
825852
defineEarlyCutoff $ Rule $ \GetModSummary f -> do
826853
session' <- hscEnv <$> use_ GhcSession f
827854
modify_dflags <- getModifyDynFlags dynFlagsModifyGlobal
@@ -832,6 +859,10 @@ getModSummaryRule = do
832859
getModSummaryFromImports session fp modTime (textToStringBuffer <$> mFileContent)
833860
case modS of
834861
Right res -> do
862+
-- Check for Template Haskell
863+
when (uses_th_qq $ msrModSummary res) $ do
864+
DisplayTHWarning act <- getIdeGlobalAction
865+
liftIO act
835866
bufFingerPrint <- liftIO $
836867
fingerprintFromStringBuffer $ fromJust $ ms_hspp_buf $ msrModSummary res
837868
let fingerPrint = Util.fingerprintFingerprints
@@ -1027,9 +1058,6 @@ needsCompilationRule file = do
10271058

10281059
pure (Just $ encodeLinkableType res, Just res)
10291060
where
1030-
uses_th_qq (ms_hspp_opts -> dflags) =
1031-
xopt LangExt.TemplateHaskell dflags || xopt LangExt.QuasiQuotes dflags
1032-
10331061
computeLinkableType :: ModSummary -> [Maybe ModSummary] -> [Maybe LinkableType] -> Maybe LinkableType
10341062
computeLinkableType this deps xs
10351063
| Just ObjectLinkable `elem` xs = Just ObjectLinkable -- If any dependent needs object code, so do we
@@ -1039,6 +1067,10 @@ needsCompilationRule file = do
10391067
where
10401068
this_type = computeLinkableTypeForDynFlags (ms_hspp_opts this)
10411069

1070+
uses_th_qq :: ModSummary -> Bool
1071+
uses_th_qq (ms_hspp_opts -> dflags) =
1072+
xopt LangExt.TemplateHaskell dflags || xopt LangExt.QuasiQuotes dflags
1073+
10421074
-- | How should we compile this module?
10431075
-- (assuming we do in fact need to compile it).
10441076
-- Depends on whether it uses unboxed tuples or sums

stack-8.10.6.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extra-deps:
3737
- data-tree-print-0.1.0.2@sha256:d845e99f322df70e0c06d6743bf80336f5918d5423498528beb0593a2afc1703,1620
3838
- floskell-0.10.5@sha256:77f0bc1569573d9666b10975a5357fef631d32266c071733739393ccae521dab,3803
3939
- heapsize-0.3.0.1@sha256:0b69aa97a46d819b700ac7b145f3b5493c3565cf2c5b8298682238d405d0326e,1417
40+
- hie-bios-0.8.0
4041
- hiedb-0.4.1.0
4142
- implicit-hie-0.1.2.6@sha256:f50a908979a574a881f753c0f9a5224f023f438b30fdefc5b7fa01803b07a280,2998
4243
- implicit-hie-cradle-0.3.0.5@sha256:5f5e575f549b2a9db664be7650b5c3c9226e313bddc46c79e2e83eb349f8e692,2610

stack-8.10.7.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extra-deps:
3737
- data-tree-print-0.1.0.2@sha256:d845e99f322df70e0c06d6743bf80336f5918d5423498528beb0593a2afc1703,1620
3838
- floskell-0.10.5@sha256:77f0bc1569573d9666b10975a5357fef631d32266c071733739393ccae521dab,3803
3939
- heapsize-0.3.0.1@sha256:0b69aa97a46d819b700ac7b145f3b5493c3565cf2c5b8298682238d405d0326e,1417
40+
- hie-bios-0.8.0
4041
- hiedb-0.4.1.0
4142
- implicit-hie-0.1.2.6@sha256:f50a908979a574a881f753c0f9a5224f023f438b30fdefc5b7fa01803b07a280,2998
4243
- implicit-hie-cradle-0.3.0.5@sha256:5f5e575f549b2a9db664be7650b5c3c9226e313bddc46c79e2e83eb349f8e692,2610

stack-8.6.5.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extra-deps:
6060
- haddock-library-1.10.0
6161
- hashable-1.3.0.0
6262
- heapsize-0.3.0
63-
- hie-bios-0.7.5
63+
- hie-bios-0.8.0
6464
- hlint-3.2.3
6565
- HsYAML-0.2.1.0@rev:1
6666
- HsYAML-aeson-0.2.0.0@rev:2

stack-8.8.4.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extra-deps:
5050
- ghc-trace-events-0.1.2.1
5151
- haskell-src-exts-1.21.1
5252
- heapsize-0.3.0
53-
- hie-bios-0.7.5
53+
- hie-bios-0.8.0
5454
- hlint-3.2.3
5555
- HsYAML-aeson-0.2.0.0@rev:2
5656
- hoogle-5.0.17.11

stack.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extra-deps:
3737
- data-tree-print-0.1.0.2@sha256:d845e99f322df70e0c06d6743bf80336f5918d5423498528beb0593a2afc1703,1620
3838
- floskell-0.10.5@sha256:77f0bc1569573d9666b10975a5357fef631d32266c071733739393ccae521dab,3803
3939
- heapsize-0.3.0.1@sha256:0b69aa97a46d819b700ac7b145f3b5493c3565cf2c5b8298682238d405d0326e,1417
40+
- hie-bios-0.8.0
4041
- hiedb-0.4.1.0
4142
- implicit-hie-0.1.2.6@sha256:f50a908979a574a881f753c0f9a5224f023f438b30fdefc5b7fa01803b07a280,2998
4243
- implicit-hie-cradle-0.3.0.5@sha256:5f5e575f549b2a9db664be7650b5c3c9226e313bddc46c79e2e83eb349f8e692,2610

0 commit comments

Comments
 (0)