Skip to content

Commit c7112e5

Browse files
committed
Revert "Warn if TH and Mac and static binary (haskell#2470)"
This reverts commit 807cb8f.
1 parent 451a9e6 commit c7112e5

File tree

2 files changed

+13
-42
lines changed

2 files changed

+13
-42
lines changed

docs/troubleshooting.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ Often this means that the client is configured to run the wrong binary, or the c
6363

6464
The easiest way to check whether the server is running is to use an OS process monitor to see if there is a `haskell-language-server` process running.
6565

66-
### Checking whether the client is connecting to the server
66+
### Problems with Template Haskell
6767

68-
If the server is running, you should see some kind of indicator in your client.
69-
In some clients (e.g. `coc`) you may need to run a command to query the client's beliefs about the server state.
70-
If the client doesn't seem to be connected despite the server running, this may indicate a bug in the client or HLS.
68+
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.
7169

72-
### Checking whether the project is being built correctly by HLS
70+
The errors thrown are usually related to linking and usually make HLS crash: `Segmentation fault`, `GHC runtime linker: fatal error`, etc
71+
72+
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.
73+
74+
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.
7375

7476
HLS needs to build the project correctly, with the correct flags, and if it does not do so then very little is likely to work.
7577
A typical symptom of this going wrong is "incorrect" compilation errors being sent to the client.

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

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ module Development.IDE.Core.Rules(
5757
getParsedModuleDefinition,
5858
typeCheckRuleDefinition,
5959
GhcSessionDepsConfig(..),
60-
Log(..),
61-
DisplayTHWarning(..),
60+
Log(..)
6261
) where
6362

6463
#if !MIN_VERSION_ghc(8,8,0)
@@ -136,7 +135,7 @@ import qualified GHC.LanguageExtensions as LangExt
136135
import qualified HieDb
137136
import Ide.Plugin.Config
138137
import qualified Language.LSP.Server as LSP
139-
import Language.LSP.Types (SMethod (SCustomMethod, SWindowShowMessage), ShowMessageParams (ShowMessageParams), MessageType (MtInfo))
138+
import Language.LSP.Types (SMethod (SCustomMethod))
140139
import Language.LSP.VFS
141140
import System.Directory (makeAbsolute)
142141
import Data.Default (def, Default)
@@ -149,15 +148,12 @@ import Ide.PluginUtils (configForPlugin)
149148
import Ide.Types (DynFlagsModifications (dynFlagsModifyGlobal, dynFlagsModifyParser),
150149
PluginId)
151150
import Control.Concurrent.STM.Stats (atomically)
152-
import Language.LSP.Server (LspT)
153-
import System.Info.Extra (isWindows)
154-
import HIE.Bios.Ghc.Gap (hostIsDynamic)
155151
import Development.IDE.Types.Logger (Recorder, logWith, cmapWithPrio, WithPriority, Pretty (pretty), (<+>), nest, vcat)
156152
import qualified Development.IDE.Core.Shake as Shake
157153
import qualified Development.IDE.GHC.ExactPrint as ExactPrint hiding (LogShake)
158154
import qualified Development.IDE.Types.Logger as Logger
159155

160-
data Log
156+
data Log
161157
= LogShake Shake.Log
162158
| LogReindexingHieFile !NormalizedFilePath
163159
| LogLoadingHieFile !NormalizedFilePath
@@ -182,9 +178,6 @@ instance Pretty Log where
182178
"SUCCEEDED LOADING HIE FILE FOR" <+> pretty path
183179
LogExactPrint log -> pretty log
184180

185-
templateHaskellInstructions :: T.Text
186-
templateHaskellInstructions = "https://haskell-language-server.readthedocs.io/en/latest/troubleshooting.html#static-binaries"
187-
188181
-- | This is useful for rules to convert rules that can only produce errors or
189182
-- a result into the more general IdeResult type that supports producing
190183
-- warnings while also producing a result.
@@ -852,27 +845,8 @@ isHiFileStableRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder)
852845
summarize SourceUnmodified = BS.singleton 2
853846
summarize SourceUnmodifiedAndStable = BS.singleton 3
854847

855-
displayTHWarning :: LspT c IO ()
856-
displayTHWarning
857-
| not isWindows && not hostIsDynamic = do
858-
LSP.sendNotification SWindowShowMessage $
859-
ShowMessageParams MtInfo $ T.unwords
860-
[ "This HLS binary does not support Template Haskell."
861-
, "Follow the [instructions](" <> templateHaskellInstructions <> ")"
862-
, "to build an HLS binary with support for Template Haskell."
863-
]
864-
| otherwise = return ()
865-
866-
newtype DisplayTHWarning = DisplayTHWarning (IO ())
867-
instance IsIdeGlobal DisplayTHWarning
868-
869848
getModSummaryRule :: Recorder (WithPriority Log) -> Rules ()
870849
getModSummaryRule recorder = do
871-
menv <- lspEnv <$> getShakeExtrasRules
872-
forM_ menv $ \env -> do
873-
displayItOnce <- liftIO $ once $ LSP.runLspT env displayTHWarning
874-
addIdeGlobal (DisplayTHWarning displayItOnce)
875-
876850
defineEarlyCutoff (cmapWithPrio LogShake recorder) $ Rule $ \GetModSummary f -> do
877851
session' <- hscEnv <$> use_ GhcSession f
878852
modify_dflags <- getModifyDynFlags dynFlagsModifyGlobal
@@ -883,10 +857,6 @@ getModSummaryRule recorder = do
883857
getModSummaryFromImports session fp modTime (textToStringBuffer <$> mFileContent)
884858
case modS of
885859
Right res -> do
886-
-- Check for Template Haskell
887-
when (uses_th_qq $ msrModSummary res) $ do
888-
DisplayTHWarning act <- getIdeGlobalAction
889-
liftIO act
890860
bufFingerPrint <- liftIO $
891861
fingerprintFromStringBuffer $ fromJust $ ms_hspp_buf $ msrModSummary res
892862
let fingerPrint = Util.fingerprintFingerprints
@@ -1082,6 +1052,9 @@ needsCompilationRule file = do
10821052

10831053
pure (Just $ encodeLinkableType res, Just res)
10841054
where
1055+
uses_th_qq (ms_hspp_opts -> dflags) =
1056+
xopt LangExt.TemplateHaskell dflags || xopt LangExt.QuasiQuotes dflags
1057+
10851058
computeLinkableType :: ModSummary -> [Maybe ModSummary] -> [Maybe LinkableType] -> Maybe LinkableType
10861059
computeLinkableType this deps xs
10871060
| Just ObjectLinkable `elem` xs = Just ObjectLinkable -- If any dependent needs object code, so do we
@@ -1091,10 +1064,6 @@ needsCompilationRule file = do
10911064
where
10921065
this_type = computeLinkableTypeForDynFlags (ms_hspp_opts this)
10931066

1094-
uses_th_qq :: ModSummary -> Bool
1095-
uses_th_qq (ms_hspp_opts -> dflags) =
1096-
xopt LangExt.TemplateHaskell dflags || xopt LangExt.QuasiQuotes dflags
1097-
10981067
-- | How should we compile this module?
10991068
-- (assuming we do in fact need to compile it).
11001069
-- Depends on whether it uses unboxed tuples or sums

0 commit comments

Comments
 (0)