on master help sign in
Clean up the IDE (#961)

* Split the Options into a separate module * Make the Logger handle live in IO * Reduce the amount of IDE logging to just two * Rename CompileOpts to IdeOptions * Rename PackageState to PackageDynFlags * Clean up setting the PackageDynFlags * Stop hiding PackageState, we no longer clash on it * Introduce a helper for collecting the package flags * Move the StringBuffer conversion to its only use

commit1c27ffe760e989a2fd2f90155e4c4f9ef0267c25 authorNeil Mitchell <35463327+neil-da@users.noreply.github.com> dateTue 7 May 2019, 10:19 (7 years ago) parentc0e9c90
9 files changed+116−109
src/Development/IDE/Functions/Compile.hs+23−42 src/Development/IDE/Logger.hs+5−7 src/Development/IDE/State/FileStore.hs+9−2 src/Development/IDE/State/RuleTypes.hs+2−1 src/Development/IDE/State/Rules.hs+2−1 src/Development/IDE/State/Service.hs+7−14 src/Development/IDE/State/Shake.hs+12−16 src/Development/IDE/Types/Options.hs+31 src/Development/IDE/UtilGHC.hs+25−26
src/Development/IDE/Functions/Compile.hs+23−42
@@ -8,9 +8,7 @@
88-- | Based on https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/API.
99-- Given a list of paths to find libraries, and a file to compile, produce a list of 'CoreModule' values.
1010module Development.IDE.Functions.Compile
11− ( CompileOpts(..)
12− , PackageState(..)
13− , GhcModule(..)
11+ ( GhcModule(..)
1412 , TcModuleResult(..)
1513 , LoadPackageResult(..)
1614 , getGhcDynFlags
@@ -29,6 +27,7 @@ import qualified Development.IDE.Functions.FindImports as FindImports
2927import Development.IDE.Functions.GHCError
3028import Development.IDE.Functions.SpanInfo
3129import Development.IDE.UtilGHC
30+import Development.IDE.Types.Options
3231
3332import GHC hiding (parseModule, typecheckModule)
3433import qualified Parser
@@ -38,7 +37,7 @@ import Bag
3837import qualified GHC
3938import Panic
4039import GhcMonad
41−import GhcPlugins as GHC hiding (PackageState, fst3, (<>))
40+import GhcPlugins as GHC hiding (fst3, (<>))
4241import qualified HeaderInfo as Hdr
4342import MkIface
4443import NameCache
@@ -61,24 +60,6 @@ import Development.IDE.Types.SpanInfo
6160import GHC.Generics (Generic)
6261import System.FilePath
6362
64−-- TODO (MK) Move to a separate Options module
65−data CompileOpts = CompileOpts
66− { optPreprocessor :: GHC.ParsedSource -> ([(GHC.SrcSpan, String)], GHC.ParsedSource)
67− , optRunGhcSession :: forall a. Maybe ParsedModule -> PackageState -> Ghc a -> IO a
68− -- ^ Setup a GHC session using a given package state. If a `ParsedModule` is supplied,
69− -- the import path should be setup for that module.
70− , optWriteIface :: Bool
71−
72− , optMbPackageName :: Maybe String
73−
74− , optPackageDbs :: [FilePath]
75− , optHideAllPkgs :: Bool
76− , optPackageImports :: [(String, ModRenaming)]
77−
78− , optThreads :: Int
79− , optShakeProfiling :: Maybe FilePath
80− }
81−
8263-- | 'CoreModule' together with some additional information required for the
8364-- conversion to DAML-LF.
8465data GhcModule = GhcModule
@@ -106,9 +87,9 @@ data LoadPackageResult = LoadPackageResult
10687
10788-- | Get source span info, used for e.g. AtPoint and Goto Definition.
10889getSrcSpanInfos
109− :: CompileOpts
90+ :: IdeOptions
11091 -> ParsedModule
111− -> PackageState
92+ -> PackageDynFlags
11293 -> [(Located ModuleName, Maybe FilePath)]
11394 -> TcModuleResult
11495 -> IO [SpanInfo]
@@ -120,18 +101,18 @@ getSrcSpanInfos opt mod packageState imports tc =
120101
121102-- | Given a string buffer, return a pre-processed @ParsedModule@.
122103parseModule
123− :: CompileOpts
124− -> PackageState
104+ :: IdeOptions
105+ -> PackageDynFlags
125106 -> FilePath
126107 -> (UTCTime, SB.StringBuffer)
127108 -> IO ([FileDiagnostic], Maybe ParsedModule)
128−parseModule opt@CompileOpts{..} packageState file =
109+parseModule opt@IdeOptions{..} packageState file =
129110 fmap (either (, Nothing) (second Just)) . Ex.runExceptT .
130111 -- We need packages since imports fail to resolve otherwise.
131112 runGhcSessionExcept opt Nothing packageState . parseFileContents optPreprocessor file
132113
133114computePackageDeps ::
134− CompileOpts -> PackageState -> InstalledUnitId -> IO (Either [FileDiagnostic] [InstalledUnitId])
115+ IdeOptions -> PackageDynFlags -> InstalledUnitId -> IO (Either [FileDiagnostic] [InstalledUnitId])
135116computePackageDeps opts packageState iuid =
136117 Ex.runExceptT $
137118 runGhcSessionExcept opts Nothing packageState $
@@ -149,9 +130,9 @@ getPackage dflags p =
149130
150131-- | Typecheck a single module using the supplied dependencies and packages.
151132typecheckModule
152− :: CompileOpts
133+ :: IdeOptions
153134 -> ParsedModule
154− -> PackageState
135+ -> PackageDynFlags
155136 -> UniqSupply
156137 -> [TcModuleResult]
157138 -> [LoadPackageResult]
@@ -169,8 +150,8 @@ typecheckModule opt mod packageState uniqSupply deps pkgs pm =
169150
170151-- | Load a pkg and populate the name cache and external package state.
171152loadPackage ::
172− CompileOpts
173− -> PackageState
153+ IdeOptions
154+ -> PackageDynFlags
174155 -> UniqSupply
175156 -> [LoadPackageResult]
176157 -> InstalledUnitId
@@ -196,9 +177,9 @@ loadPackage opt packageState us lps p =
196177-- | Compile a single type-checked module to a 'CoreModule' value, or
197178-- provide errors.
198179compileModule
199− :: CompileOpts
180+ :: IdeOptions
200181 -> ParsedModule
201− -> PackageState
182+ -> PackageDynFlags
202183 -> UniqSupply
203184 -> [TcModuleResult]
204185 -> [LoadPackageResult]
@@ -233,27 +214,27 @@ compileModule opt mod packageState uniqSupply deps pkgs tmr =
233214-- | Evaluate a GHC session using a new environment constructed with
234215-- the supplied options.
235216runGhcSessionExcept
236− :: CompileOpts
217+ :: IdeOptions
237218 -> Maybe ParsedModule
238− -> PackageState
219+ -> PackageDynFlags
239220 -> Ex.ExceptT e Ghc a
240221 -> Ex.ExceptT e IO a
241222runGhcSessionExcept opts mbMod pkg m =
242223 Ex.ExceptT $ runGhcSession opts mbMod pkg $ Ex.runExceptT m
243224
244225
245−getGhcDynFlags :: CompileOpts -> ParsedModule -> PackageState -> IO DynFlags
226+getGhcDynFlags :: IdeOptions -> ParsedModule -> PackageDynFlags -> IO DynFlags
246227getGhcDynFlags opts mod pkg = runGhcSession opts (Just mod) pkg getSessionDynFlags
247228
248229-- | Evaluate a GHC session using a new environment constructed with
249230-- the supplied options.
250231runGhcSession
251− :: CompileOpts
232+ :: IdeOptions
252233 -> Maybe ParsedModule
253− -> PackageState
234+ -> PackageDynFlags
254235 -> Ghc a
255236 -> IO a
256−runGhcSession CompileOpts{..} = optRunGhcSession
237+runGhcSession IdeOptions{..} = optRunGhcSession
257238
258239-- When we make a fresh GHC environment, the OrigNameCache comes already partially
259240-- populated. So to be safe, we simply extend this one.
@@ -496,11 +477,11 @@ parsePragmasIntoDynFlags fp contents = catchSrcErrors $ do
496477 (dflags, _, _) <- parseDynamicFilePragma dflags0 opts
497478 return dflags
498479
499−generatePackageState :: [FilePath] -> Bool -> [(String, ModRenaming)] -> IO PackageState
480+generatePackageState :: [FilePath] -> Bool -> [(String, ModRenaming)] -> IO PackageDynFlags
500481generatePackageState paths hideAllPkgs pkgImports = do
501482 let dflags = setPackageImports hideAllPkgs pkgImports $ setPackageDbs paths (defaultDynFlags fakeSettings fakeLlvmConfig)
502483 (newDynFlags, _) <- initPackages dflags
503− pure $ PackageState (pkgDatabase newDynFlags) (pkgState newDynFlags) (thisUnitIdInsts_ newDynFlags)
484+ pure $ getPackageDynFlags newDynFlags
504485
505486-- | Run something in a Ghc monad and catch the errors (SourceErrors and
506487-- compiler-internal exceptions like Panic or InstallationError).
src/Development/IDE/Logger.hs+5−7
@@ -13,13 +13,11 @@ module Development.IDE.Logger
1313import qualified Data.Text as T
1414import GHC.Stack
1515
16−data Handle m = Handle {
17− logError :: HasCallStack => T.Text -> m ()
18− , logWarning :: HasCallStack => T.Text -> m ()
19− , logInfo :: HasCallStack => T.Text -> m ()
20− , logDebug :: HasCallStack => T.Text -> m ()
16+data Handle = Handle {
17+ logSeriousError :: HasCallStack => T.Text -> IO ()
18+ , logDebug :: HasCallStack => T.Text -> IO ()
2119 }
2220
23−makeNopHandle :: Monad m => Handle m
24−makeNopHandle = Handle e e e e where
21+makeNopHandle :: Handle
22+makeNopHandle = Handle e e where
2523 e _ = pure ()
src/Development/IDE/State/FileStore.hs+9−2
@@ -12,6 +12,7 @@ module Development.IDE.State.FileStore(
1212
1313
1414import StringBuffer
15+import Development.IDE.UtilGHC()
1516
1617import qualified Data.Map.Strict as Map
1718import qualified Data.Text as T
@@ -21,12 +22,12 @@ import qualified System.Directory as Dir
2122import Development.Shake
2223import Development.Shake.Classes
2324import Development.IDE.State.Shake
24−import Development.IDE.UtilGHC
2525import Control.Concurrent.Extra
2626import Control.Exception
2727import GHC.Generics
2828import System.IO.Error
2929import qualified Data.ByteString.Char8 as BS
30+import qualified StringBuffer as SB
3031import Development.IDE.Types.Diagnostics
3132import Data.Time
3233
@@ -141,7 +142,13 @@ setBufferModified state absFile (mcontents, !time) = do
141142 -- update vars synchronously
142143 modifyVar_ envDirtyFiles $ evaluate . case mcontents of
143144 Nothing -> Map.delete absFile
144− Just contents -> Map.insert absFile $ strictPair time (textToStringBuffer contents)
145+ Just contents -> Map.insert absFile $ strictPair time $ textToStringBuffer contents
145146
146147 -- run shake to update results regarding the files of interest
147148 void $ shakeRun state []
149+
150+
151+-- would be nice to do this more efficiently...
152+textToStringBuffer :: T.Text -> SB.StringBuffer
153+-- would be nice to do this more efficiently...
154+textToStringBuffer = SB.stringToStringBuffer . T.unpack
src/Development/IDE/State/RuleTypes.hs+2−1
@@ -15,6 +15,7 @@ module Development.IDE.State.RuleTypes(
1515import Control.DeepSeq
1616import Development.IDE.Functions.Compile (TcModuleResult, GhcModule, LoadPackageResult(..))
1717import qualified Development.IDE.Functions.Compile as Compile
18+import qualified Development.IDE.UtilGHC as Compile
1819import Development.IDE.Functions.FindImports (Import(..))
1920import Development.IDE.Functions.DependencyInformation
2021import Data.Hashable
@@ -61,7 +62,7 @@ type instance RuleResult GenerateCore = GhcModule
6162
6263-- | We capture the subset of `DynFlags` that is computed by package initialization in a rule to
6364-- make session initialization cheaper by reusing it.
64−type instance RuleResult LoadPackageState = Compile.PackageState
65+type instance RuleResult LoadPackageState = Compile.PackageDynFlags
6566
6667-- | Resolve the imports in a module to the list of either external packages or absolute file paths
6768-- for modules in the same package.
src/Development/IDE/State/Rules.hs+2−1
@@ -28,6 +28,7 @@ import Control.Exception (evaluate)
2828import Control.Monad.Except
2929import Control.Monad.Extra (whenJust)
3030import qualified Development.IDE.Functions.Compile as Compile
31+import qualified Development.IDE.Types.Options as Compile
3132import Development.IDE.Functions.DependencyInformation
3233import Development.IDE.Functions.FindImports
3334import Development.IDE.State.FileStore
@@ -152,7 +153,7 @@ getDefinitionForFile file pos = do
152153 spans <- useE GetSpanInfo file
153154 return $ AtPoint.gotoDefinition spans pos
154155
155−getOpts :: Action Compile.CompileOpts
156+getOpts :: Action Compile.IdeOptions
156157getOpts = envOptions <$> getServiceEnv
157158
158159------------------------------------------------------------
src/Development/IDE/State/Service.hs+7−14
@@ -16,18 +16,17 @@ module Development.IDE.State.Service(
1616 setFilesOfInterest,
1717 writeProfile,
1818 getDiagnostics, unsafeClearDiagnostics,
19− logDebug, logInfo, logWarning, logError
19+ logDebug, logSeriousError
2020 ) where
2121
2222import Control.Concurrent.Extra
2323import Control.Monad.Except
24−import Development.IDE.Functions.Compile (CompileOpts(..))
24+import Development.IDE.Types.Options (IdeOptions(..))
2525import Development.IDE.State.FileStore
2626import qualified Development.IDE.Logger as Logger
2727import Data.Maybe
2828import Data.Set (Set)
2929import qualified Data.Set as Set
30−import qualified Data.Text as T
3130import Development.IDE.Functions.GHCError
3231import Development.Shake hiding (Diagnostic, Env, newCache)
3332import Development.IDE.Types.LSP as Compiler
@@ -39,7 +38,7 @@ import Development.IDE.State.Shake
3938
4039-- | Environment threaded through the Shake actions.
4140data Env = Env
42− { envOptions :: CompileOpts
41+ { envOptions :: IdeOptions
4342 -- ^ Compiler options.
4443 , envOfInterestVar :: Var (Set FilePath)
4544 -- ^ The files of interest.
@@ -49,7 +48,7 @@ data Env = Env
4948instance IsIdeGlobal Env
5049
5150
52−mkEnv :: CompileOpts -> IO Env
51+mkEnv :: IdeOptions -> IO Env
5352mkEnv options = do
5453 ofInterestVar <- newVar Set.empty
5554 uniqSupplyVar <- mkSplitUniqSupply 'a' >>= newVar
@@ -72,8 +71,8 @@ unsafeClearDiagnostics = unsafeClearAllDiagnostics
7271-- | Initialise the Compiler Service.
7372initialise :: Rules ()
7473 -> Maybe (Event -> IO ())
75− -> Logger.Handle IO
76− -> CompileOpts
74+ -> Logger.Handle
75+ -> IdeOptions
7776 -> IO IdeState
7877initialise mainRule toDiags logger options =
7978 shakeOpen
@@ -90,7 +89,7 @@ initialise mainRule toDiags logger options =
9089writeProfile :: IdeState -> FilePath -> IO ()
9190writeProfile = shakeProfile
9291
93−setProfiling :: CompileOpts -> ShakeOptions -> ShakeOptions
92+setProfiling :: IdeOptions -> ShakeOptions -> ShakeOptions
9493setProfiling opts shakeOpts =
9594 maybe shakeOpts (\p -> shakeOpts { shakeReport = [p], shakeTimings = True }) (optShakeProfiling opts)
9695
@@ -119,9 +118,3 @@ setFilesOfInterest state files = do
119118
120119getServiceEnv :: Action Env
121120getServiceEnv = getIdeGlobalAction
122−
123−logDebug, logInfo, logWarning, logError :: IdeState -> T.Text -> IO ()
124−logDebug = shakeLogDebug
125−logInfo = shakeLogInfo
126−logWarning = shakeLogWarning
127−logError = shakeLogError
src/Development/IDE/State/Shake.hs+12−16
@@ -38,10 +38,8 @@ module Development.IDE.State.Shake(
3838 garbageCollect,
3939 setPriority,
4040 sendEvent,
41− shakeLogDebug,
42− shakeLogInfo,
43− shakeLogWarning,
44− shakeLogError,
41+ Development.IDE.State.Shake.logDebug,
42+ Development.IDE.State.Shake.logSeriousError,
4543 ) where
4644
4745import Development.Shake
@@ -78,7 +76,7 @@ import Numeric.Extra
7876-- information we stash inside the shakeExtra field
7977data ShakeExtras = ShakeExtras
8078 {eventer :: Event -> IO ()
81− ,logger :: Logger.Handle IO
79+ ,logger :: Logger.Handle
8280 ,globals :: Var (Map.HashMap TypeRep Dynamic)
8381 ,state :: Var Values
8482 }
@@ -221,7 +219,7 @@ getValues state key file = do
221219
222220-- | Open a 'IdeState', should be shut using 'shakeShut'.
223221shakeOpen :: (Event -> IO ()) -- ^ diagnostic handler
224− -> Logger.Handle IO
222+ -> Logger.Handle
225223 -> ShakeOptions
226224 -> Rules ()
227225 -> IO IdeState
@@ -245,13 +243,13 @@ shakeRun :: IdeState -> [Action a] -> IO (IO [a])
245243-- not even start, which would make issues with async exceptions less problematic.
246244shakeRun IdeState{shakeExtras=ShakeExtras{..}, ..} acts = modifyVar shakeAbort $ \stop -> do
247245 (stopTime,_) <- duration stop
248− Logger.logInfo logger $ T.pack $ "Starting shakeRun (aborting the previous one took " ++ showDuration stopTime ++ ")"
246+ Logger.logDebug logger $ T.pack $ "Starting shakeRun (aborting the previous one took " ++ showDuration stopTime ++ ")"
249247 bar <- newBarrier
250248 start <- offsetTime
251249 thread <- forkFinally (shakeRunDatabaseProfile shakeDb acts) $ \res -> do
252250 signalBarrier bar res
253251 runTime <- start
254− Logger.logInfo logger $ T.pack $
252+ Logger.logDebug logger $ T.pack $
255253 "Finishing shakeRun (took " ++ showDuration runTime ++ ", " ++ (if isLeft res then "exception" else "completed") ++ ")"
256254 -- important: we send an async exception to the thread, then wait for it to die, before continuing
257255 return (do killThread thread; void $ waitBarrier bar, either throwIO return =<< waitBarrier bar)
@@ -302,12 +300,12 @@ uses_ key files = do
302300reportSeriousError :: String -> Action ()
303301reportSeriousError t = do
304302 ShakeExtras{logger} <- getShakeExtras
305− liftIO $ Logger.logError logger $ T.pack t
303+ liftIO $ Logger.logSeriousError logger $ T.pack t
306304
307305reportSeriousErrorDie :: String -> Action a
308306reportSeriousErrorDie t = do
309307 ShakeExtras{logger} <- getShakeExtras
310− liftIO $ Logger.logError logger $ T.pack t
308+ liftIO $ Logger.logSeriousError logger $ T.pack t
311309 fail t
312310
313311
@@ -419,12 +417,10 @@ sendEvent e = do
419417 liftIO $ eventer e
420418
421419-- | bit of an odd signature because we're trying to remove priority
422−sl :: (Handle IO -> T.Text -> IO ()) -> IdeState -> T.Text -> IO ()
420+sl :: (Handle -> T.Text -> IO ()) -> IdeState -> T.Text -> IO ()
423421sl f IdeState{shakeExtras=ShakeExtras{logger}} p = f logger p
424422
425−shakeLogDebug, shakeLogInfo, shakeLogWarning, shakeLogError
423+logDebug, logSeriousError
426424 :: IdeState -> T.Text -> IO ()
427−shakeLogDebug = sl logDebug
428−shakeLogInfo = sl logInfo
429−shakeLogWarning = sl logWarning
430−shakeLogError = sl logError
425+logDebug = sl Logger.logDebug
426+logSeriousError = sl Logger.logSeriousError
src/Development/IDE/Types/Options.hsnew file+31
@@ -0,0 +1,31 @@
1+-- Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2+-- SPDX-License-Identifier: Apache-2.0
3+
4+{-# LANGUAGE RankNTypes #-}
5+
6+-- | Options
7+module Development.IDE.Types.Options
8+ ( IdeOptions(..)
9+ ) where
10+
11+import Development.IDE.UtilGHC
12+import GHC hiding (parseModule, typecheckModule)
13+import GhcPlugins as GHC hiding (fst3, (<>))
14+
15+
16+data IdeOptions = IdeOptions
17+ { optPreprocessor :: GHC.ParsedSource -> ([(GHC.SrcSpan, String)], GHC.ParsedSource)
18+ , optRunGhcSession :: forall a. Maybe ParsedModule -> PackageDynFlags -> Ghc a -> IO a
19+ -- ^ Setup a GHC session using a given package state. If a `ParsedModule` is supplied,
20+ -- the import path should be setup for that module.
21+ , optWriteIface :: Bool
22+
23+ , optMbPackageName :: Maybe String
24+
25+ , optPackageDbs :: [FilePath]
26+ , optHideAllPkgs :: Bool
27+ , optPackageImports :: [(String, ModRenaming)]
28+
29+ , optThreads :: Int
30+ , optShakeProfiling :: Maybe FilePath
31+ }
src/Development/IDE/UtilGHC.hs+25−26
@@ -12,9 +12,8 @@
1212--
1313-- * Call setSessionDynFlags, use modifyDynFlags instead. It's faster and avoids loading packages.
1414module Development.IDE.UtilGHC(
15− PackageState(..),
15+ PackageDynFlags(..), setPackageDynFlags, getPackageDynFlags,
1616 modifyDynFlags,
17− textToStringBuffer,
1817 removeTypeableInfo,
1918 setPackageImports,
2019 setPackageDbs,
@@ -25,7 +24,6 @@ module Development.IDE.UtilGHC(
2524 mkImport,
2625 runGhcFast,
2726 setImports,
28− setPackageState,
2927 setThisInstalledUnitId,
3028 modIsInternal
3129 ) where
@@ -34,18 +32,17 @@ import Config
3432import Fingerprint
3533import GHC hiding (convertLit)
3634import GhcMonad
37−import GhcPlugins as GHC hiding (PackageState, fst3, (<>))
35+import GhcPlugins as GHC hiding (fst3, (<>))
3836import HscMain
3937import qualified Packages
4038import Platform
41−import qualified StringBuffer as SB
4239import qualified EnumSet
4340
4441import Control.DeepSeq
4542import Data.IORef
4643import Data.List
47−import qualified Data.Text as T
4844import GHC.Generics (Generic)
45+import qualified StringBuffer as SB
4946
5047----------------------------------------------------------------------
5148-- GHC setup
@@ -82,15 +79,29 @@ modifyDynFlags f = do
8279 modifySession $ \h ->
8380 h { hsc_dflags = newFlags, hsc_IC = (hsc_IC h) {ic_dflags = newFlags} }
8481
85−-- | This is the subset of `DynFlags` that is computed by package initialization.
86−data PackageState = PackageState
87− { pkgStateDb :: !(Maybe [(FilePath, [Packages.PackageConfig])])
88− , pkgStateState :: !Packages.PackageState
89− , pkgThisUnitIdInsts :: !(Maybe [(ModuleName, Module)])
90− } deriving (Generic, Show)
82+-- | The subset of @DynFlags@ computed by package initialization.
83+data PackageDynFlags = PackageDynFlags
84+ { pdfPkgDatabase :: !(Maybe [(FilePath, [Packages.PackageConfig])])
85+ , pdfPkgState :: !Packages.PackageState
86+ , pdfThisUnitIdInsts :: !(Maybe [(ModuleName, Module)])
87+ } deriving (Generic, Show)
88+
89+instance NFData PackageDynFlags where
90+ rnf (PackageDynFlags db state insts) = db `seq` state `seq` rnf insts
91+
92+setPackageDynFlags :: PackageDynFlags -> DynFlags -> DynFlags
93+setPackageDynFlags PackageDynFlags{..} dflags = dflags
94+ { pkgDatabase = pdfPkgDatabase
95+ , pkgState = pdfPkgState
96+ , thisUnitIdInsts_ = pdfThisUnitIdInsts
97+ }
9198
92−instance NFData PackageState where
93− rnf (PackageState db state insts) = db `seq` state `seq` rnf insts
99+getPackageDynFlags :: DynFlags -> PackageDynFlags
100+getPackageDynFlags DynFlags{..} = PackageDynFlags
101+ { pdfPkgDatabase = pkgDatabase
102+ , pdfPkgState = pkgState
103+ , pdfThisUnitIdInsts = thisUnitIdInsts_
104+ }
94105
95106
96107-- | A version of `showSDoc` that uses default flags (to avoid uses of
@@ -102,10 +113,6 @@ showSDocDefault = showSDoc dynFlags
102113prettyPrint :: Outputable a => a -> String
103114prettyPrint = showSDocDefault . ppr
104115
105−textToStringBuffer :: T.Text -> SB.StringBuffer
106−-- would be nice to do this more efficiently...
107−textToStringBuffer = SB.stringToStringBuffer . T.unpack
108−
109116-- FIXME(#1203): This must move out of `haskell-ide-core` and into `damlc`.
110117internalModules :: [String]
111118internalModules =
@@ -177,14 +184,6 @@ setThisInstalledUnitId unitId dflags =
177184setImports :: [FilePath] -> DynFlags -> DynFlags
178185setImports paths dflags = dflags { importPaths = paths }
179186
180−setPackageState :: PackageState -> DynFlags -> DynFlags
181−setPackageState state dflags =
182− dflags
183− { pkgDatabase = pkgStateDb state
184− , pkgState = pkgStateState state
185− , thisUnitIdInsts_ = pkgThisUnitIdInsts state
186− }
187−
188187
189188
190189-- Orphan instances for types from the GHC API.