@@ -11,25 +11,35 @@
11-- * Call runGhc, use runGhcFast instead. It's faster and doesn't require config we don't have.
11-- * Call runGhc, use runGhcFast instead. It's faster and doesn't require config we don't have.
13-- * Call setSessionDynFlags, use modifyDynFlags instead. It's faster and avoids loading packages.
13-- * Call setSessionDynFlags, use modifyDynFlags instead. It's faster and avoids loading packages.
14−module Development.IDE.UtilGHC(module Development.IDE.UtilGHC) where
14+module Development.IDE.UtilGHC(
27+ Development.IDE.UtilGHC.RealLocated,
16import Config
31import Config
17−import qualified CmdLineParser as Cmd (warnMsg)
18−import DynFlags (parseDynamicFilePragma)
19import Fingerprint
32import Fingerprint
20import GHC hiding (convertLit)
33import GHC hiding (convertLit)
21−import GHC.LanguageExtensions.Type
22import GhcMonad
34import GhcMonad
23import GhcPlugins as GHC hiding (PackageState, fst3, (<>))
35import GhcPlugins as GHC hiding (PackageState, fst3, (<>))
24import HscMain
36import HscMain
25import qualified Packages
37import qualified Packages
26−import Panic (throwGhcExceptionIO)
27import Platform
38import Platform
28import qualified StringBuffer as SB
39import qualified StringBuffer as SB
29import qualified EnumSet
40import qualified EnumSet
31import Control.DeepSeq
42import Control.DeepSeq
33import Data.IORef
43import Data.IORef
34import Data.List
44import Data.List
35import qualified Data.Text as T
45import qualified Data.Text as T
@@ -38,111 +48,6 @@ import GHC.Generics (Generic)
38----------------------------------------------------------------------
48----------------------------------------------------------------------
39-- GHC setup
49-- GHC setup
41−-- | Language options enabled in the DAML-1.2 compilation
42−xExtensionsSet :: [Extension]
44− [ -- syntactic convenience
45− RecordPuns, RecordWildCards, LambdaCase, TupleSections, BlockArguments, ViewPatterns,
48− , DuplicateRecordFields, DisambiguateRecordFields
50− , ScopedTypeVariables, ExplicitForAll
51− , DataKinds, KindSignatures, RankNTypes, TypeApplications
54− , MultiParamTypeClasses, FlexibleInstances, GeneralizedNewtypeDeriving, TypeSynonymInstances
55− , DefaultSignatures, StandaloneDeriving, FunctionalDependencies, DeriveFunctor
56− -- replacing primitives
57− , RebindableSyntax, OverloadedStrings
60− -- avoiding letrec in list comp (see DEL-3841)
61− , MonadComprehensions
66− , DamlVersionRequired
72−-- | Language settings _disabled_ ($-XNo...$) in the DAML-1.2 compilation
73−xExtensionsUnset :: [Extension]
74−xExtensionsUnset = [ ]
76−-- | Flags set for DAML-1.2 compilation
77−xFlagsSet :: [ GeneralFlag ]
83−-- | Warning options set for DAML compilation. Note that these can be modified
84−-- (per file) by the user via file headers '{-# OPTIONS -fwarn-... #-} and
85−-- '{-# OPTIONS -no-warn-... #-}'.
86−wOptsSet :: [ WarningFlag ]
88− [ Opt_WarnUnusedImports
89− , Opt_WarnPrepositiveQualifiedModule
90− , Opt_WarnOverlappingPatterns
91− , Opt_WarnIncompletePatterns
94−-- | Warning options set for DAML compilation, which become errors.
95−wOptsSetFatal :: [ WarningFlag ]
97− [ Opt_WarnMissingFields
100−-- | Warning options unset for DAML compilation. Note that these can be modified
101−-- (per file) by the user via file headers '{-# OPTIONS -fwarn-... #-} and
102−-- '{-# OPTIONS -no-warn-... #-}'.
103−wOptsUnset :: [ WarningFlag ]
105− [ Opt_WarnMissingMonadFailInstances -- failable pattern plus RebindableSyntax raises this error
106− , Opt_WarnOverflowedLiterals -- this does not play well with -ticky and the error message is misleading
110−adjustDynFlags :: [FilePath] -> PackageState -> Maybe String -> DynFlags -> DynFlags
111−adjustDynFlags paths packageState mbPackageName dflags
113− $ setPackageState packageState
114− $ setThisInstalledUnitId (maybe mainUnitId stringToUnitId mbPackageName)
115− -- once we have package imports working, we want to import the base package and set this to
116− -- the default instead of always compiling in the context of ghc-prim.
117− $ apply wopt_set wOptsSet
118− $ apply wopt_unset wOptsUnset
119− $ apply wopt_set_fatal wOptsSetFatal
120− $ apply xopt_set xExtensionsSet
121− $ apply xopt_unset xExtensionsUnset
122− $ apply gopt_set xFlagsSet
124− mainModIs = mkModule primUnitId (mkModuleName "NotAnExistingName"), -- avoid DEL-6770
126− ghcLink = NoLink, hscTarget = HscNothing -- avoid generating .o or .hi files
127− {-, dumpFlags = Opt_D_ppr_debug `EnumSet.insert` dumpFlags dflags -- turn on debug output from GHC-}
129− where apply f xs d = foldl' f d xs
131−setThisInstalledUnitId :: UnitId -> DynFlags -> DynFlags
132−setThisInstalledUnitId unitId dflags =
133− dflags {thisInstalledUnitId = toInstalledUnitId unitId}
135−setImports :: [FilePath] -> DynFlags -> DynFlags
136−setImports paths dflags = dflags { importPaths = paths }
138−setPackageState :: PackageState -> DynFlags -> DynFlags
139−setPackageState state dflags =
141− { pkgDatabase = pkgStateDb state
142− , pkgState = pkgStateState state
143− , thisUnitIdInsts_ = pkgThisUnitIdInsts state
146setPackageDbs :: [FilePath] -> DynFlags -> DynFlags
51setPackageDbs :: [FilePath] -> DynFlags -> DynFlags
147setPackageDbs paths dflags =
52setPackageDbs paths dflags =
@@ -185,31 +90,6 @@ data PackageState = PackageState
185instance NFData PackageState where
90instance NFData PackageState where
186 rnf (PackageState db state insts) = db `seq` state `seq` rnf insts
91 rnf (PackageState db state insts) = db `seq` state `seq` rnf insts
188−-- | Configures the @DynFlags@ for this session to DAML-1.2
190−-- * Installs a custom log action;
191−-- * Sets up the package databases;
192−-- * Sets the import paths to the given list of 'FilePath'.
193−-- * if present, parses and applies custom options for GHC
194−-- (may fail if the custom options are inconsistent with std DAML ones)
195−setupDamlGHC :: GhcMonad m => [FilePath] -> Maybe String -> PackageState -> [String] -> m ()
196−setupDamlGHC importPaths mbPackageName packageState [] =
197− modifyDynFlags $ adjustDynFlags importPaths packageState mbPackageName
198−-- if custom options are given, add them after the standard DAML flag setup
199−setupDamlGHC importPaths mbPackageName packageState customOpts = do
200− setupDamlGHC importPaths mbPackageName packageState []
201− damlDFlags <- getSessionDynFlags
202− (dflags', leftover, warns) <- parseDynamicFilePragma damlDFlags $ map noLoc customOpts
204− let leftoverError = CmdLineError $
205− (unlines . ("Unable to parse custom flags:":) . map unLoc) leftover
206− unless (null leftover) $ liftIO $ throwGhcExceptionIO leftoverError
208− unless (null warns) $
209− liftIO $ putStrLn $ unlines $ "Warnings:" : map (unLoc . Cmd.warnMsg) warns
211− modifySession $ \h ->
212− h { hsc_dflags = dflags', hsc_IC = (hsc_IC h) {ic_dflags = dflags' } }
214-- | A version of `showSDoc` that uses default flags (to avoid uses of
94-- | A version of `showSDoc` that uses default flags (to avoid uses of
215-- `showSDocUnsafe`).
95-- `showSDocUnsafe`).