@@ -10,10 +10,10 @@ where
10import Control.Exception
10import Control.Exception
11import Control.Monad
11import Control.Monad
12import Control.Monad.IO.Class
12import Control.Monad.IO.Class
13−import Data.List (isPrefixOf)
13+import Data.List (isPrefixOf, foldl')
14import Data.Maybe (catMaybes)
14import Data.Maybe (catMaybes)
15import GHC hiding (IE, parseModule, parser)
15import GHC hiding (IE, parseModule, parser)
16−import GHC.LanguageExtensions.Type (Extension (Cpp))
16+import GHC.LanguageExtensions.Type (Extension (..))
17import GHC.Paths (libdir)
17import GHC.Paths (libdir)
18import Ormolu.Config
18import Ormolu.Config
19import Ormolu.Exception
19import Ormolu.Exception
@@ -87,7 +87,7 @@ initDynFlagsPure fp input = do
87 -- I was told we could get away with using the 'unsafeGlobalDynFlags'. as
87 -- I was told we could get away with using the 'unsafeGlobalDynFlags'. as
88 -- long as 'parseDynamicFilePragma' is impure there seems to be no reason
88 -- long as 'parseDynamicFilePragma' is impure there seems to be no reason
89 -- to use it.
89 -- to use it.
90− dflags0 <- GHC.getSessionDynFlags
90+ dflags0 <- setDefaultExts <$> GHC.getSessionDynFlags
91 let tokens = GHC.getOptions dflags0 (GHC.stringToStringBuffer input) fp
91 let tokens = GHC.getOptions dflags0 (GHC.stringToStringBuffer input) fp
92 (dflags1, _, _) <- GHC.parseDynamicFilePragma dflags0 tokens
92 (dflags1, _, _) <- GHC.parseDynamicFilePragma dflags0 tokens
93 -- Turn this on last to avoid T10942
93 -- Turn this on last to avoid T10942
@@ -154,3 +154,70 @@ getPragma s@(x:xs)
154 | otherwise =
154 | otherwise =
155 let (prag, remline) = getPragma xs
155 let (prag, remline) = getPragma xs
156 in (x:prag, ' ':remline)
156 in (x:prag, ' ':remline)
158+-- | Enable all language extensions that we think should be enabled by
159+-- default for ease of use.
161+setDefaultExts :: DynFlags -> DynFlags
162+setDefaultExts flags = foldl' GHC.xopt_set flags
163+ [ OverlappingInstances
164+ , UndecidableInstances
165+ , IncoherentInstances
166+ , UndecidableSuperClasses
167+ , ExtendedDefaultRules
168+ , ForeignFunctionInterface
172+ , ScopedTypeVariables
175+ , TypeFamilyDependencies
188+ , StandaloneDeriving
191+ , DerivingStrategies
195+ , MultiParamTypeClasses
196+ , FunctionalDependencies
197+ , ExistentialQuantification
201+ , GeneralizedNewtypeDeriving
207+ , ExplicitNamespaces
220+ , NumericUnderscores
221+ , QuantifiedConstraints