@@ -36,6 +36,7 @@ module Development.IDE.Core.Compile
36
36
, TypecheckHelpers (.. )
37
37
) where
38
38
39
+ import Control.Monad.IO.Class
39
40
import Control.Concurrent.Extra
40
41
import Control.Concurrent.STM.Stats hiding (orElse )
41
42
import Control.DeepSeq (NFData (.. ), force , liftRnf ,
@@ -133,6 +134,13 @@ import GHC.Hs (LEpaComment)
133
134
import qualified GHC.Types.Error as Error
134
135
#endif
135
136
137
+ #if MIN_VERSION_ghc(9,5,0)
138
+ import GHC.Driver.Config.CoreToStg.Prep
139
+ import GHC.Core.Lint.Interactive
140
+ import GHC.Driver.Main (mkCgInteractiveGuts )
141
+ import GHC.Unit.Home.ModInfo
142
+ #endif
143
+
136
144
-- | Given a string buffer, return the string (after preprocessing) and the 'ParsedModule'.
137
145
parseModule
138
146
:: IdeOptions
@@ -467,7 +475,11 @@ mkHiFileResultNoCompile session tcm = do
467
475
tcGblEnv = tmrTypechecked tcm
468
476
details <- makeSimpleDetails hsc_env_tmp tcGblEnv
469
477
sf <- finalSafeMode (ms_hspp_opts ms) tcGblEnv
470
- iface' <- mkIfaceTc hsc_env_tmp sf details ms tcGblEnv
478
+ iface' <- mkIfaceTc hsc_env_tmp sf details ms
479
+ #if MIN_VERSION_ghc(9,5,0)
480
+ Nothing
481
+ #endif
482
+ tcGblEnv
471
483
let iface = iface' { mi_globals = Nothing , mi_usages = filterUsages (mi_usages iface') } -- See Note [Clearing mi_globals after generating an iface]
472
484
pure $! mkHiFileResult ms iface details (tmrRuntimeModules tcm) Nothing
473
485
@@ -482,20 +494,19 @@ mkHiFileResultCompile se session' tcm simplified_guts = catchErrs $ do
482
494
ms = pm_mod_summary $ tmrParsed tcm
483
495
tcGblEnv = tmrTypechecked tcm
484
496
485
- (details, mguts) <-
486
- if mg_hsc_src simplified_guts == HsBootFile
487
- then do
488
- details <- mkBootModDetailsTc session tcGblEnv
489
- pure (details, Nothing )
490
- else do
497
+ (details, guts) <- do
491
498
-- write core file
492
499
-- give variables unique OccNames
493
500
tidy_opts <- initTidyOpts session
494
501
(guts, details) <- tidyProgram tidy_opts simplified_guts
495
- pure (details, Just guts)
502
+ pure (details, guts)
496
503
497
504
#if MIN_VERSION_ghc(9,0,1)
498
- let ! partial_iface = force $ mkPartialIface session details
505
+ let ! partial_iface = force $ mkPartialIface session
506
+ #if MIN_VERSION_ghc(9,5,0)
507
+ (cg_binds guts)
508
+ #endif
509
+ details
499
510
#if MIN_VERSION_ghc(9,3,0)
500
511
ms
501
512
#endif
@@ -513,9 +524,7 @@ mkHiFileResultCompile se session' tcm simplified_guts = catchErrs $ do
513
524
let final_iface = final_iface' {mi_globals = Nothing , mi_usages = filterUsages (mi_usages final_iface')} -- See Note [Clearing mi_globals after generating an iface]
514
525
515
526
-- Write the core file now
516
- core_file <- case mguts of
517
- Nothing -> pure Nothing -- no guts, likely boot file
518
- Just guts -> do
527
+ core_file <- do
519
528
let core_fp = ml_core_file $ ms_location ms
520
529
core_file = codeGutsToCoreFile iface_hash guts
521
530
iface_hash = getModuleHash final_iface
@@ -538,27 +547,37 @@ mkHiFileResultCompile se session' tcm simplified_guts = catchErrs $ do
538
547
Just (core, _) | optVerifyCoreFile -> do
539
548
let core_fp = ml_core_file $ ms_location ms
540
549
traceIO $ " Verifying " ++ core_fp
541
- let CgGuts {cg_binds = unprep_binds, cg_tycons = tycons } = case mguts of
542
- Nothing -> error " invariant optVerifyCoreFile: guts must exist if linkable exists"
543
- Just g -> g
550
+ let CgGuts {cg_binds = unprep_binds, cg_tycons = tycons } = guts
544
551
mod = ms_mod ms
545
552
data_tycons = filter isDataTyCon tycons
546
553
CgGuts {cg_binds = unprep_binds'} <- coreFileToCgGuts session final_iface details core
547
554
555
+ #if MIN_VERSION_ghc(9,5,0)
556
+ cp_cfg <- initCorePrepConfig session
557
+ #endif
558
+
559
+ let corePrep = corePrepPgm
560
+ #if MIN_VERSION_ghc(9,5,0)
561
+ (hsc_logger session) cp_cfg (initCorePrepPgmConfig (hsc_dflags session) (interactiveInScope $ hsc_IC session))
562
+ #else
563
+ session
564
+ #endif
565
+ mod (ms_location ms)
566
+
548
567
-- Run corePrep first as we want to test the final version of the program that will
549
568
-- get translated to STG/Bytecode
550
569
#if MIN_VERSION_ghc(9,3,0)
551
570
prepd_binds
552
571
#else
553
572
(prepd_binds , _)
554
573
#endif
555
- <- corePrepPgm session mod (ms_location ms) unprep_binds data_tycons
574
+ <- corePrep unprep_binds data_tycons
556
575
#if MIN_VERSION_ghc(9,3,0)
557
576
prepd_binds'
558
577
#else
559
578
(prepd_binds', _)
560
579
#endif
561
- <- corePrepPgm session mod (ms_location ms) unprep_binds' data_tycons
580
+ <- corePrep unprep_binds' data_tycons
562
581
let binds = noUnfoldings $ (map flattenBinds . (: [] )) $ prepd_binds
563
582
binds' = noUnfoldings $ (map flattenBinds . (: [] )) $ prepd_binds'
564
583
@@ -683,7 +702,7 @@ generateByteCode (CoreFileTime time) hscEnv summary guts = do
683
702
let session = _tweak (hscSetFlags (ms_hspp_opts summary) hscEnv)
684
703
-- TODO: maybe settings ms_hspp_opts is unnecessary?
685
704
summary' = summary { ms_hspp_opts = hsc_dflags session }
686
- hscInteractive session guts
705
+ hscInteractive session (mkCgInteractiveGuts guts)
687
706
(ms_location summary')
688
707
let unlinked = BCOs bytecode sptEntries
689
708
let linkable = LM time (ms_mod summary) [unlinked]
@@ -1242,7 +1261,9 @@ parseHeader
1242
1261
=> DynFlags -- ^ flags to use
1243
1262
-> FilePath -- ^ the filename (for source locations)
1244
1263
-> Util. StringBuffer -- ^ Haskell module source text (full Unicode is supported)
1245
- #if MIN_VERSION_ghc(9,0,1)
1264
+ #if MIN_VERSION_ghc(9,5,0)
1265
+ -> ExceptT [FileDiagnostic ] m ([FileDiagnostic ], Located (HsModule GhcPs ))
1266
+ #elif MIN_VERSION_ghc(9,0,1)
1246
1267
-> ExceptT [FileDiagnostic ] m ([FileDiagnostic ], Located (HsModule ))
1247
1268
#else
1248
1269
-> ExceptT [FileDiagnostic ] m ([FileDiagnostic ], Located (HsModule GhcPs ))
@@ -1574,13 +1595,13 @@ showReason (RecompBecause s) = s
1574
1595
mkDetailsFromIface :: HscEnv -> ModIface -> IO ModDetails
1575
1596
mkDetailsFromIface session iface = do
1576
1597
fixIO $ \ details -> do
1577
- let ! hsc' = hscUpdateHPT (\ hpt -> addToHpt hpt (moduleName $ mi_module iface) (HomeModInfo iface details Nothing )) session
1598
+ let ! hsc' = hscUpdateHPT (\ hpt -> addToHpt hpt (moduleName $ mi_module iface) (HomeModInfo iface details emptyHomeModInfoLinkable )) session
1578
1599
initIfaceLoad hsc' (typecheckIface iface)
1579
1600
1580
1601
coreFileToCgGuts :: HscEnv -> ModIface -> ModDetails -> CoreFile -> IO CgGuts
1581
1602
coreFileToCgGuts session iface details core_file = do
1582
1603
let act hpt = addToHpt hpt (moduleName this_mod)
1583
- (HomeModInfo iface details Nothing )
1604
+ (HomeModInfo iface details emptyHomeModInfoLinkable )
1584
1605
this_mod = mi_module iface
1585
1606
types_var <- newIORef (md_types details)
1586
1607
let hsc_env' = hscUpdateHPT act (session {
@@ -1604,9 +1625,9 @@ coreFileToLinkable :: LinkableType -> HscEnv -> ModSummary -> ModIface -> ModDet
1604
1625
coreFileToLinkable linkableType session ms iface details core_file t = do
1605
1626
cgi_guts <- coreFileToCgGuts session iface details core_file
1606
1627
(warns, lb) <- case linkableType of
1607
- BCOLinkable -> generateByteCode (CoreFileTime t) session ms cgi_guts
1608
- ObjectLinkable -> generateObjectCode session ms cgi_guts
1609
- pure (warns, HomeModInfo iface details . Just <$> lb)
1628
+ BCOLinkable -> fmap ( maybe emptyHomeModInfoLinkable justBytecode) <$> generateByteCode (CoreFileTime t) session ms cgi_guts
1629
+ ObjectLinkable -> fmap ( maybe emptyHomeModInfoLinkable justObjects) <$> generateObjectCode session ms cgi_guts
1630
+ pure (warns, Just $ HomeModInfo iface details lb) -- TODO wz1000 handle emptyHomeModInfoLinkable
1610
1631
1611
1632
-- | Non-interactive, batch version of 'InteractiveEval.getDocs'.
1612
1633
-- The interactive paths create problems in ghc-lib builds
0 commit comments