@@ -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).