Skip to content

Commit 03f6b3c

Browse files
committed
some more update
1 parent e7160a9 commit 03f6b3c

File tree

5 files changed

+64
-18
lines changed

5 files changed

+64
-18
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ captureSplicesAndDeps TypecheckHelpers{..} env k = do
294294
mods_transitive_list =
295295
mapMaybe nodeKeyToInstalledModule $ Set.toList mods_transitive
296296

297+
-- todo: 9.12
297298
; moduleLocs <- readIORef (fcModuleCache $ hsc_FC hsc_env)
298299
; lbs <- getLinkables [toNormalizedFilePath' file
299300
| installedMod <- mods_transitive_list
@@ -430,7 +431,14 @@ mkHiFileResultNoCompile session tcm = do
430431
details <- makeSimpleDetails hsc_env_tmp tcGblEnv
431432
sf <- finalSafeMode (ms_hspp_opts ms) tcGblEnv
432433
iface' <- mkIfaceTc hsc_env_tmp sf details ms Nothing tcGblEnv
433-
let iface = iface' { mi_globals = Nothing, mi_usages = filterUsages (mi_usages iface') } -- See Note [Clearing mi_globals after generating an iface]
434+
#if MIN_VERSION_ghc(9,11,0)
435+
let iface = set_mi_top_env Nothing iface'
436+
-- todo: 9.12, since usages are not expose anymore, we can't update mi_usages.
437+
#else
438+
let iface = iface' {
439+
mi_globals = Nothing
440+
, mi_usages = filterUsages (mi_usages iface') } -- See Note [Clearing mi_globals after generating an iface]
441+
#endif
434442
pure $! mkHiFileResult ms iface details (tmrRuntimeModules tcm) Nothing
435443

436444
mkHiFileResultCompile
@@ -462,7 +470,13 @@ mkHiFileResultCompile se session' tcm simplified_guts = catchErrs $ do
462470
#if MIN_VERSION_ghc(9,4,2)
463471
Nothing
464472
#endif
465-
let final_iface = final_iface' {mi_globals = Nothing, mi_usages = filterUsages (mi_usages final_iface')} -- See Note [Clearing mi_globals after generating an iface]
473+
let final_iface = final_iface' {
474+
#if MIN_VERSION_ghc(9,11,0)
475+
mi_top_env = Nothing
476+
#else
477+
mi_globals = Nothing
478+
#endif
479+
, mi_usages = filterUsages (mi_usages final_iface')} -- See Note [Clearing mi_globals after generating an iface]
466480

467481
-- Write the core file now
468482
core_file <- do

ghcide/src/Development/IDE/GHC/Compat/Core.hs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ module Development.IDE.GHC.Compat.Core (
6868
IfaceExport,
6969
IfaceTyCon(..),
7070
ModIface,
71+
pattern GHC.ModIface,
7172
ModIface_(..),
7273
HscSource(..),
7374
WhereFrom(..),
@@ -365,6 +366,10 @@ module Development.IDE.GHC.Compat.Core (
365366
getKey,
366367
module GHC.Driver.Env.KnotVars,
367368
module GHC.Linker.Types,
369+
#if MIN_VERSION_ghc(9,11,0)
370+
pattern LM,
371+
#endif
372+
368373
module GHC.Types.Unique.Map,
369374
module GHC.Utils.TmpFs,
370375
module GHC.Unit.Finder.Types,
@@ -544,6 +549,7 @@ import GHC.Utils.TmpFs
544549
import Language.Haskell.Syntax hiding (FunDep)
545550
#if MIN_VERSION_ghc(9,11,0)
546551
import System.OsPath.Types (OsPath)
552+
import System.OsPath (unsafeEncodeUtf)
547553
#endif
548554

549555
-- See Note [Guidelines For Using CPP In GHCIDE Import Statements]
@@ -557,12 +563,13 @@ import GHC.Types.Avail (greNamePrintableName)
557563
import GHC.Hs (SrcSpanAnn')
558564
#endif
559565

560-
#if !MIN_VERSION_ghc(9,11,0)
561566
mkHomeModLocation :: DynFlags -> ModuleName -> FilePath -> IO Module.ModLocation
562-
#else
563-
mkHomeModLocation :: DynFlags -> ModuleName -> OsPath -> IO Module.ModLocation
567+
mkHomeModLocation df mn f = do
568+
#if MIN_VERSION_ghc(9,11,0)
569+
f <- return $ unsafeEncodeUtf f
564570
#endif
565-
mkHomeModLocation df mn f = pure $ GHC.mkHomeModLocation (GHC.initFinderOpts df) mn f
571+
pure $ GHC.mkHomeModLocation (GHC.initFinderOpts df) mn f
572+
566573

567574
pattern RealSrcSpan :: SrcLoc.RealSrcSpan -> Maybe BufSpan -> SrcLoc.SrcSpan
568575

@@ -806,4 +813,7 @@ lookupGlobalRdrEnv gre_env occ = lookupGRE gre_env (LookupOccName occ AllRelevan
806813

807814
#if MIN_VERSION_ghc(9,11,0)
808815
type Unlinked = LinkablePart
816+
pattern LM a b c = Linkable a b c
809817
#endif
818+
-- pattern LM :: Linkable -> [Linkable] -> [Linkable] -> Linkable
819+

ghcide/src/Development/IDE/GHC/CoreFile.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import GHC.Core
2525
import GHC.CoreToIface
2626
import GHC.Fingerprint
2727
#if MIN_VERSION_ghc(9,11,0)
28-
import qualified GHC.Iface.Load as Iface
28+
import qualified GHC.Iface.Load as Iface
2929
#endif
3030
import GHC.Iface.Binary
3131
import GHC.Iface.Env
@@ -91,7 +91,7 @@ readBinCoreFile name_cache fat_hi_path = do
9191

9292
-- | Write a core file
9393
writeBinCoreFile :: DynFlags -> FilePath -> CoreFile -> IO Fingerprint
94-
writeBinCoreFile dflag core_path fat_iface = do
94+
writeBinCoreFile _dflag core_path fat_iface = do
9595
bh <- openBinMem initBinMemSize
9696

9797
let quietTrace =
@@ -100,7 +100,7 @@ writeBinCoreFile dflag core_path fat_iface = do
100100
#if !MIN_VERSION_ghc(9,11,0)
101101
putWithUserData quietTrace bh fat_iface
102102
#else
103-
putWithUserData quietTrace (Iface.flagsToIfCompression dflag) bh fat_iface
103+
putWithUserData quietTrace (Iface.flagsToIfCompression _dflag) bh fat_iface
104104
#endif
105105

106106
-- And send the result to the file

ghcide/src/Development/IDE/GHC/Orphans.hs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,35 @@ instance Show ModDetails where show = const "<moddetails>"
5151
instance NFData ModDetails where rnf = rwhnf
5252
instance NFData SafeHaskellMode where rnf = rwhnf
5353
instance Show Linkable where show = unpack . printOutputable
54+
#if MIN_VERSION_ghc(9,11,0)
55+
instance NFData LinkableObjectSort where rnf = rwhnf
56+
#else
5457
instance NFData Linkable where rnf (LM a b c) = rnf a `seq` rnf b `seq` rnf c
58+
#endif
5559
instance NFData Unlinked where
60+
#if MIN_VERSION_ghc(9,11,0)
61+
rnf (DotO f l) = rnf f `seq` rnf l
62+
rnf (LazyBCOs a b) = seqCompiledByteCode a `seq` liftRnf rwhnf b
63+
rnf (BCOs a) = seqCompiledByteCode a
64+
#else
5665
rnf (DotO f) = rnf f
66+
rnf (BCOs a b) = seqCompiledByteCode a `seq` liftRnf rwhnf b
67+
rnf (LoadedBCOs us) = rnf us
68+
#endif
5769
rnf (DotA f) = rnf f
5870
rnf (DotDLL f) = rnf f
59-
rnf (BCOs a b) = seqCompiledByteCode a `seq` liftRnf rwhnf b
6071
#if MIN_VERSION_ghc(9,5,0)
6172
rnf (CoreBindings wcb) = rnf wcb
62-
rnf (LoadedBCOs us) = rnf us
63-
64-
instance NFData WholeCoreBindings where
65-
rnf (WholeCoreBindings bs m ml) = rnf bs `seq` rnf m `seq` rnf ml
66-
6773
instance NFData ModLocation where
6874
rnf (ModLocation mf f1 f2 f3 f4 f5) = rnf mf `seq` rnf f1 `seq` rnf f2 `seq` rnf f3 `seq` rnf f4 `seq` rnf f5
75+
#endif
6976

77+
#if MIN_VERSION_ghc(9,5,0) && !MIN_VERSION_ghc(9,11,0)
78+
instance NFData WholeCoreBindings where
79+
rnf (WholeCoreBindings bs m ml) = rnf bs `seq` rnf m `seq` rnf ml
80+
#else
81+
instance NFData WholeCoreBindings where
82+
rnf (WholeCoreBindings bs m ml wf) = rnf bs `seq` rnf m `seq` rnf ml `seq` rnf wf
7083
#endif
7184

7285
instance Show PackageFlag where show = unpack . printOutputable

ghcide/src/Development/IDE/Import/FindImports.hs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import Development.IDE.Types.Diagnostics
2626
import Development.IDE.Types.Location
2727
import GHC.Types.PkgQual
2828
import GHC.Unit.State
29+
#if MIN_VERSION_ghc(9,11,0)
30+
import GHC.Driver.DynFlags
31+
#endif
2932
import System.FilePath
3033

3134

@@ -91,13 +94,19 @@ locateModuleFile import_dirss exts targetFor isSource modName = do
9194
| isSource = ext ++ "-boot"
9295
| otherwise = ext
9396

97+
reexportedModulesFrom :: DynFlags -> S.Set ModuleName
98+
reexportedModulesFrom flag =
99+
#if MIN_VERSION_ghc(9,11,0)
100+
S.fromList $ reexportFrom <$>
101+
#endif
102+
reexportedModules flag
103+
94104
-- | This function is used to map a package name to a set of import paths.
95105
-- It only returns Just for unit-ids which are possible to import into the
96106
-- current module. In particular, it will return Nothing for 'main' components
97107
-- as they can never be imported into another package.
98108
mkImportDirs :: HscEnv -> (UnitId, DynFlags) -> Maybe (UnitId, ([FilePath], S.Set ModuleName))
99-
mkImportDirs _env (i, flags) = Just (i, (importPaths flags, reexportedModules flags))
100-
109+
mkImportDirs _env (i, flags) = Just (i, (importPaths flags, reexportedModulesFrom flags))
101110
-- | locate a module in either the file system or the package database. Where we go from *daml to
102111
-- Haskell
103112
locateModule
@@ -146,7 +155,7 @@ locateModule env comp_info exts targetFor modName mbPkgName isSource = do
146155
-- about which module unit a imports.
147156
-- Without multi-component support it is hard to recontruct the dependency environment so
148157
-- unit a will have both unit b and unit c in scope.
149-
map (\uid -> let this_df = homeUnitEnv_dflags (ue_findHomeUnitEnv uid ue) in (uid, importPaths this_df, reexportedModules this_df)) hpt_deps
158+
map (\uid -> let this_df = homeUnitEnv_dflags (ue_findHomeUnitEnv uid ue) in (uid, importPaths this_df, reexportedModulesFrom this_df)) hpt_deps
150159
ue = hsc_unit_env env
151160
units = homeUnitEnv_units $ ue_findHomeUnitEnv (homeUnitId_ dflags) ue
152161
hpt_deps :: [UnitId]

0 commit comments

Comments
 (0)