on master help sign in
Move the DAML config stuff out of haskell-ide-core (#940)
af56be6Neil Mitchell
src/Development/IDE/UtilGHC.hs+16−136
@@ -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.
12--
12--
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(
15+ PackageState(..),
16+ modifyDynFlags,
17+ textToStringBuffer,
18+ removeTypeableInfo,
19+ setPackageImports,
20+ setPackageDbs,
21+ fakeSettings,
22+ fakeLlvmConfig,
23+ prettyPrint,
24+ importGenerated,
25+ mkImport,
26+ runGhcFast,
27+ Development.IDE.UtilGHC.RealLocated,
28+ modIsInternal
29+ ) where
15
30
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
30
41
31import Control.DeepSeq
42import Control.DeepSeq
32−import Control.Monad
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
40
50
41−-- | Language options enabled in the DAML-1.2 compilation
42−xExtensionsSet :: [Extension]
43−xExtensionsSet =
44− [ -- syntactic convenience
45− RecordPuns, RecordWildCards, LambdaCase, TupleSections, BlockArguments, ViewPatterns,
46− NumericUnderscores
47− -- records
48− , DuplicateRecordFields, DisambiguateRecordFields
49− -- types and kinds
50− , ScopedTypeVariables, ExplicitForAll
51− , DataKinds, KindSignatures, RankNTypes, TypeApplications
52− , ConstraintKinds
53− -- type classes
54− , MultiParamTypeClasses, FlexibleInstances, GeneralizedNewtypeDeriving, TypeSynonymInstances
55− , DefaultSignatures, StandaloneDeriving, FunctionalDependencies, DeriveFunctor
56− -- replacing primitives
57− , RebindableSyntax, OverloadedStrings
58− -- strictness
59− , Strict, StrictData
60− -- avoiding letrec in list comp (see DEL-3841)
61− , MonadComprehensions
62− -- package imports
63− , PackageImports
64− -- our changes
65− , NewColonConvention
66− , DamlVersionRequired
67− , WithRecordSyntax
68− , DamlTemplate
69− ]
70−
71−
72−-- | Language settings _disabled_ ($-XNo...$) in the DAML-1.2 compilation
73−xExtensionsUnset :: [Extension]
74−xExtensionsUnset = [ ]
75−
76−-- | Flags set for DAML-1.2 compilation
77−xFlagsSet :: [ GeneralFlag ]
78−xFlagsSet = [
79− Opt_Haddock
80− , Opt_Ticky
81− ]
82−
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 ]
87−wOptsSet =
88− [ Opt_WarnUnusedImports
89− , Opt_WarnPrepositiveQualifiedModule
90− , Opt_WarnOverlappingPatterns
91− , Opt_WarnIncompletePatterns
92− ]
93−
94−-- | Warning options set for DAML compilation, which become errors.
95−wOptsSetFatal :: [ WarningFlag ]
96−wOptsSetFatal =
97− [ Opt_WarnMissingFields
98− ]
99−
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 ]
104−wOptsUnset =
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
107− ]
108−
109−
110−adjustDynFlags :: [FilePath] -> PackageState -> Maybe String -> DynFlags -> DynFlags
111−adjustDynFlags paths packageState mbPackageName dflags
112− = setImports paths
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
123− dflags{
124− mainModIs = mkModule primUnitId (mkModuleName "NotAnExistingName"), -- avoid DEL-6770
125− debugLevel = 1,
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-}
128− }
129− where apply f xs d = foldl' f d xs
130−
131−setThisInstalledUnitId :: UnitId -> DynFlags -> DynFlags
132−setThisInstalledUnitId unitId dflags =
133− dflags {thisInstalledUnitId = toInstalledUnitId unitId}
134−
135−setImports :: [FilePath] -> DynFlags -> DynFlags
136−setImports paths dflags = dflags { importPaths = paths }
137−
138−setPackageState :: PackageState -> DynFlags -> DynFlags
139−setPackageState state dflags =
140− dflags
141− { pkgDatabase = pkgStateDb state
142− , pkgState = pkgStateState state
143− , thisUnitIdInsts_ = pkgThisUnitIdInsts state
144− }
145−
146setPackageDbs :: [FilePath] -> DynFlags -> DynFlags
51setPackageDbs :: [FilePath] -> DynFlags -> DynFlags
147setPackageDbs paths dflags =
52setPackageDbs paths dflags =
148 dflags
53 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
187
92
188−-- | Configures the @DynFlags@ for this session to DAML-1.2
189−-- compilation:
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
203−
204− let leftoverError = CmdLineError $
205− (unlines . ("Unable to parse custom flags:":) . map unLoc) leftover
206− unless (null leftover) $ liftIO $ throwGhcExceptionIO leftoverError
207−
208− unless (null warns) $
209− liftIO $ putStrLn $ unlines $ "Warnings:" : map (unLoc . Cmd.warnMsg) warns
210−
211− modifySession $ \h ->
212− h { hsc_dflags = dflags', hsc_IC = (hsc_IC h) {ic_dflags = dflags' } }
213
93
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`).