@@ -17,7 +17,6 @@ module Development.IDE.Core.Rules(
17
17
runAction , useE , useNoFileE , usesE ,
18
18
toIdeResult , defineNoFile ,
19
19
mainRule ,
20
- getGhcCore ,
21
20
getAtPoint ,
22
21
getDefinition ,
23
22
getDependencies ,
@@ -55,10 +54,12 @@ import Development.Shake hiding (Diagnostic)
55
54
import Development.IDE.Core.RuleTypes
56
55
57
56
import GHC hiding (parseModule , typecheckModule )
57
+ import qualified GHC.LanguageExtensions as LangExt
58
58
import Development.IDE.GHC.Compat
59
59
import UniqSupply
60
60
import NameCache
61
61
import HscTypes
62
+ import DynFlags (xopt )
62
63
import GHC.Generics (Generic )
63
64
64
65
import qualified Development.IDE.Spans.AtPoint as AtPoint
@@ -92,16 +93,6 @@ defineNoFile f = define $ \k file -> do
92
93
------------------------------------------------------------
93
94
-- Exposed API
94
95
95
-
96
- -- | Generate the GHC Core for the supplied file and its dependencies.
97
- getGhcCore :: NormalizedFilePath -> Action (Maybe [CoreModule ])
98
- getGhcCore file = runMaybeT $ do
99
- files <- transitiveModuleDeps <$> useE GetDependencies file
100
- pms <- usesE GetParsedModule $ files ++ [file]
101
- usesE GenerateCore $ map fileFromParsedModule pms
102
-
103
-
104
-
105
96
-- | Get all transitive file dependencies of a given module.
106
97
-- Does not include the file itself.
107
98
getDependencies :: NormalizedFilePath -> Action (Maybe [NormalizedFilePath ])
@@ -281,13 +272,27 @@ typeCheckRule =
281
272
define $ \ TypeCheck file -> do
282
273
pm <- use_ GetParsedModule file
283
274
deps <- use_ GetDependencies file
284
- tms <- uses_ TypeCheck (transitiveModuleDeps deps)
285
- setPriority priorityTypeCheck
286
275
packageState <- hscEnv <$> use_ GhcSession file
276
+ -- Figure out whether we need TemplateHaskell or QuasiQuotes support
277
+ let graph_needs_th_qq = needsTemplateHaskellOrQQ $ hsc_mod_graph packageState
278
+ file_uses_th_qq = uses_th_qq $ ms_hspp_opts (pm_mod_summary pm)
279
+ any_uses_th_qq = graph_needs_th_qq || file_uses_th_qq
280
+ tms <- if any_uses_th_qq
281
+ -- If we use TH or QQ, we must obtain the bytecode
282
+ then do
283
+ bytecodes <- uses_ GenerateByteCode (transitiveModuleDeps deps)
284
+ tmrs <- uses_ TypeCheck (transitiveModuleDeps deps)
285
+ pure (zipWith addByteCode bytecodes tmrs)
286
+ else uses_ TypeCheck (transitiveModuleDeps deps)
287
+ setPriority priorityTypeCheck
287
288
IdeOptions { optDefer = defer} <- getIdeOptions
288
289
liftIO $ typecheckModule defer packageState tms pm
290
+ where
291
+ uses_th_qq dflags = xopt LangExt. TemplateHaskell dflags || xopt LangExt. QuasiQuotes dflags
292
+ addByteCode :: Linkable -> TcModuleResult -> TcModuleResult
293
+ addByteCode lm tmr = tmr { tmrModInfo = (tmrModInfo tmr) { hm_linkable = Just lm } }
289
294
290
- generateCore :: NormalizedFilePath -> Action (IdeResult CoreModule )
295
+ generateCore :: NormalizedFilePath -> Action (IdeResult ( SafeHaskellMode , CgGuts , ModDetails ) )
291
296
generateCore file = do
292
297
deps <- use_ GetDependencies file
293
298
(tm: tms) <- uses_ TypeCheck (file: transitiveModuleDeps deps)
@@ -299,6 +304,14 @@ generateCoreRule :: Rules ()
299
304
generateCoreRule =
300
305
define $ \ GenerateCore -> generateCore
301
306
307
+ generateByteCodeRule :: Rules ()
308
+ generateByteCodeRule =
309
+ define $ \ GenerateByteCode file -> do
310
+ deps <- use_ GetDependencies file
311
+ (tm : tms) <- uses_ TypeCheck (file: transitiveModuleDeps deps)
312
+ session <- hscEnv <$> use_ GhcSession file
313
+ (_, guts, _) <- use_ GenerateCore file
314
+ liftIO $ generateByteCode session tms tm guts
302
315
303
316
-- A local rule type to get caching. We want to use newCache, but it has
304
317
-- thread killed exception issues, so we lift it to a full rule.
@@ -345,6 +358,7 @@ mainRule = do
345
358
typeCheckRule
346
359
getSpanInfoRule
347
360
generateCoreRule
361
+ generateByteCodeRule
348
362
loadGhcSession
349
363
getHieFileRule
350
364
0 commit comments