on master help sign in
IDE cleanups and progress towards external usability (#930)
9600e40Neil Mitchell
src/Development/IDE/Functions/Compile.hs+2−2
@@ -72,7 +72,7 @@ data CompileOpts = CompileOpts
72
72
73 , optPackageDbs :: [FilePath]
73 , optPackageDbs :: [FilePath]
74 , optHideAllPkgs :: Bool
74 , optHideAllPkgs :: Bool
75− , optPackageImports :: [(String, [(String, String)])]
75+ , optPackageImports :: [(String, ModRenaming)]
76
76
77 , optThreads :: Int
77 , optThreads :: Int
78 , optShakeProfiling :: Maybe FilePath
78 , optShakeProfiling :: Maybe FilePath
@@ -486,7 +486,7 @@ parsePragmasIntoDynFlags fp contents = catchSrcErrors $ do
486 (dflags, _, _) <- parseDynamicFilePragma dflags0 opts
486 (dflags, _, _) <- parseDynamicFilePragma dflags0 opts
487 return dflags
487 return dflags
488
488
489−generatePackageState :: [FilePath] -> Bool -> [(String, [(String, String)])] -> IO PackageState
489+generatePackageState :: [FilePath] -> Bool -> [(String, ModRenaming)] -> IO PackageState
490generatePackageState paths hideAllPkgs pkgImports = do
490generatePackageState paths hideAllPkgs pkgImports = do
491 let dflags = setPackageImports hideAllPkgs pkgImports $ setPackageDbs paths (defaultDynFlags fakeSettings fakeLlvmConfig)
491 let dflags = setPackageImports hideAllPkgs pkgImports $ setPackageDbs paths (defaultDynFlags fakeSettings fakeLlvmConfig)
492 (newDynFlags, _) <- initPackages dflags
492 (newDynFlags, _) <- initPackages dflags
src/Development/IDE/State/FileStore.hs−3
@@ -54,19 +54,16 @@ type instance RuleResult GetFileExists = Bool
54
54
55data GetFileExists = GetFileExists
55data GetFileExists = GetFileExists
56 deriving (Eq, Show, Generic)
56 deriving (Eq, Show, Generic)
57−instance Binary GetFileExists
58instance Hashable GetFileExists
57instance Hashable GetFileExists
59instance NFData GetFileExists
58instance NFData GetFileExists
60
59
61data GetModificationTime = GetModificationTime
60data GetModificationTime = GetModificationTime
62 deriving (Eq, Show, Generic)
61 deriving (Eq, Show, Generic)
63−instance Binary GetModificationTime
64instance Hashable GetModificationTime
62instance Hashable GetModificationTime
65instance NFData GetModificationTime
63instance NFData GetModificationTime
66
64
67data GetFileContents = GetFileContents
65data GetFileContents = GetFileContents
68 deriving (Eq, Show, Generic)
66 deriving (Eq, Show, Generic)
69−instance Binary GetFileContents
70instance Hashable GetFileContents
67instance Hashable GetFileContents
71instance NFData GetFileContents
68instance NFData GetFileContents
72
69
src/Development/IDE/State/RuleTypes.hs+4−21
@@ -17,8 +17,6 @@ import Development.IDE.Functions.Compile (TcModuleResult,
17import qualified Development.IDE.Functions.Compile as Compile
17import qualified Development.IDE.Functions.Compile as Compile
18import Development.IDE.Functions.FindImports (Import(..))
18import Development.IDE.Functions.FindImports (Import(..))
19import Development.IDE.Functions.DependencyInformation
19import Development.IDE.Functions.DependencyInformation
20−import Data.Binary (Binary)
21−import qualified Data.Binary as Binary
22import Data.Hashable
20import Data.Hashable
23import Data.Typeable
21import Data.Typeable
24import Development.Shake hiding (Env, newCache)
22import Development.Shake hiding (Env, newCache)
@@ -63,7 +61,7 @@ type instance RuleResult GenerateCore = GhcModule
63
61
64-- | We capture the subset of `DynFlags` that is computed by package initialization in a rule to
62-- | We capture the subset of `DynFlags` that is computed by package initialization in a rule to
65-- make session initialization cheaper by reusing it.
63-- make session initialization cheaper by reusing it.
66−type instance RuleResult GeneratePackageState = Compile.PackageState
64+type instance RuleResult LoadPackageState = Compile.PackageState
67
65
68-- | Resolve the imports in a module to the list of either external packages or absolute file paths
66-- | Resolve the imports in a module to the list of either external packages or absolute file paths
69-- for modules in the same package.
67-- for modules in the same package.
@@ -77,69 +75,58 @@ type instance RuleResult ReportImportCycles = ()
77
75
78data OfInterest = OfInterest
76data OfInterest = OfInterest
79 deriving (Eq, Show, Typeable, Generic)
77 deriving (Eq, Show, Typeable, Generic)
80−instance Binary OfInterest
81instance Hashable OfInterest
78instance Hashable OfInterest
82instance NFData OfInterest
79instance NFData OfInterest
83
80
84data GetParsedModule = GetParsedModule
81data GetParsedModule = GetParsedModule
85 deriving (Eq, Show, Typeable, Generic)
82 deriving (Eq, Show, Typeable, Generic)
86−instance Binary GetParsedModule
87instance Hashable GetParsedModule
83instance Hashable GetParsedModule
88instance NFData GetParsedModule
84instance NFData GetParsedModule
89
85
90data GetLocatedImports = GetLocatedImports
86data GetLocatedImports = GetLocatedImports
91 deriving (Eq, Show, Typeable, Generic)
87 deriving (Eq, Show, Typeable, Generic)
92−instance Binary GetLocatedImports
93instance Hashable GetLocatedImports
88instance Hashable GetLocatedImports
94instance NFData GetLocatedImports
89instance NFData GetLocatedImports
95
90
96data GetDependencyInformation = GetDependencyInformation
91data GetDependencyInformation = GetDependencyInformation
97 deriving (Eq, Show, Typeable, Generic)
92 deriving (Eq, Show, Typeable, Generic)
98−instance Binary GetDependencyInformation
99instance Hashable GetDependencyInformation
93instance Hashable GetDependencyInformation
100instance NFData GetDependencyInformation
94instance NFData GetDependencyInformation
101
95
102data ReportImportCycles = ReportImportCycles
96data ReportImportCycles = ReportImportCycles
103 deriving (Eq, Show, Typeable, Generic)
97 deriving (Eq, Show, Typeable, Generic)
104−instance Binary ReportImportCycles
105instance Hashable ReportImportCycles
98instance Hashable ReportImportCycles
106instance NFData ReportImportCycles
99instance NFData ReportImportCycles
107
100
108data GetDependencies = GetDependencies
101data GetDependencies = GetDependencies
109 deriving (Eq, Show, Typeable, Generic)
102 deriving (Eq, Show, Typeable, Generic)
110−instance Binary GetDependencies
111instance Hashable GetDependencies
103instance Hashable GetDependencies
112instance NFData GetDependencies
104instance NFData GetDependencies
113
105
114data TypeCheck = TypeCheck
106data TypeCheck = TypeCheck
115 deriving (Eq, Show, Typeable, Generic)
107 deriving (Eq, Show, Typeable, Generic)
116−instance Binary TypeCheck
117instance Hashable TypeCheck
108instance Hashable TypeCheck
118instance NFData TypeCheck
109instance NFData TypeCheck
119
110
120data LoadPackage = LoadPackage InstalledUnitId
111data LoadPackage = LoadPackage InstalledUnitId
121 deriving (Eq, Show, Typeable, Generic)
112 deriving (Eq, Show, Typeable, Generic)
122−instance Binary LoadPackage
123instance Hashable LoadPackage
113instance Hashable LoadPackage
124instance NFData LoadPackage
114instance NFData LoadPackage
125
115
126data GetSpanInfo = GetSpanInfo
116data GetSpanInfo = GetSpanInfo
127 deriving (Eq, Show, Typeable, Generic)
117 deriving (Eq, Show, Typeable, Generic)
128−instance Binary GetSpanInfo
129instance Hashable GetSpanInfo
118instance Hashable GetSpanInfo
130instance NFData GetSpanInfo
119instance NFData GetSpanInfo
131
120
132data GenerateCore = GenerateCore
121data GenerateCore = GenerateCore
133 deriving (Eq, Show, Typeable, Generic)
122 deriving (Eq, Show, Typeable, Generic)
134−instance Binary GenerateCore
135instance Hashable GenerateCore
123instance Hashable GenerateCore
136instance NFData GenerateCore
124instance NFData GenerateCore
137
125
138−data GeneratePackageState = GeneratePackageState [FilePath] Bool [(String, [(String, String)])]
126+data LoadPackageState = LoadPackageState
139 deriving (Eq, Show, Typeable, Generic)
127 deriving (Eq, Show, Typeable, Generic)
140−instance Binary GeneratePackageState
128+instance Hashable LoadPackageState
141−instance Hashable GeneratePackageState
142−instance NFData GeneratePackageState
129+instance NFData LoadPackageState
143
130
144------------------------------------------------------------
131------------------------------------------------------------
145-- Orphan Instances
132-- Orphan Instances
@@ -171,10 +158,6 @@ instance NFData SpanInfo where
171instance NFData Import where
158instance NFData Import where
172 rnf = rwhnf
159 rnf = rwhnf
173
160
174−instance Binary InstalledUnitId where
175− get = fmap stringToInstalledUnitId Binary.get
176− put = Binary.put . installedUnitIdString
177−
178instance Hashable InstalledUnitId where
161instance Hashable InstalledUnitId where
179 hashWithSalt salt = hashWithSalt salt . installedUnitIdString
162 hashWithSalt salt = hashWithSalt salt . installedUnitIdString
180
163
src/Development/IDE/State/Rules.hs+14−17
@@ -172,7 +172,7 @@ getParsedModuleRule :: Rules ()
172getParsedModuleRule =
172getParsedModuleRule =
173 define $ \GetParsedModule file -> do
173 define $ \GetParsedModule file -> do
174 contents <- getFileContents file
174 contents <- getFileContents file
175− packageState <- getPackageState
175+ packageState <- use_ LoadPackageState ""
176 opt <- getOpts
176 opt <- getOpts
177 liftIO $ Compile.parseModule opt packageState file contents
177 liftIO $ Compile.parseModule opt packageState file contents
178
178
@@ -182,7 +182,7 @@ getLocatedImportsRule =
182 pm <- use_ GetParsedModule file
182 pm <- use_ GetParsedModule file
183 let ms = pm_mod_summary pm
183 let ms = pm_mod_summary pm
184 let imports = ms_textual_imps ms
184 let imports = ms_textual_imps ms
185− packageState <- getPackageState
185+ packageState <- use_ LoadPackageState ""
186 opt <- getOpts
186 opt <- getOpts
187 dflags <- liftIO $ Compile.getGhcDynFlags opt pm packageState
187 dflags <- liftIO $ Compile.getGhcDynFlags opt pm packageState
188 xs <- forM imports $ \(mbPkgName, modName) ->
188 xs <- forM imports $ \(mbPkgName, modName) ->
@@ -204,7 +204,7 @@ rawDependencyInformation f = go (Set.singleton f) Map.empty Map.empty
204 let modGraph' = Map.insert f (Left ModuleParseError) modGraph
204 let modGraph' = Map.insert f (Left ModuleParseError) modGraph
205 in go fs modGraph' pkgs
205 in go fs modGraph' pkgs
206 Just imports -> do
206 Just imports -> do
207− packageState <- lift getPackageState
207+ packageState <- lift $ use_ LoadPackageState ""
208 opt <- lift getOpts
208 opt <- lift getOpts
209 modOrPkgImports <- forM imports $ \imp -> do
209 modOrPkgImports <- forM imports $ \imp -> do
210 case imp of
210 case imp of
@@ -272,7 +272,7 @@ getSpanInfoRule =
272 pm <- use_ GetParsedModule file
272 pm <- use_ GetParsedModule file
273 tc <- use_ TypeCheck file
273 tc <- use_ TypeCheck file
274 imports <- use_ GetLocatedImports file
274 imports <- use_ GetLocatedImports file
275− packageState <- getPackageState
275+ packageState <- use_ LoadPackageState ""
276 opt <- getOpts
276 opt <- getOpts
277 x <- liftIO $ Compile.getSrcSpanInfos opt pm packageState (fileImports imports) tc
277 x <- liftIO $ Compile.getSrcSpanInfos opt pm packageState (fileImports imports) tc
278 return ([], Just x)
278 return ([], Just x)
@@ -287,7 +287,7 @@ typeCheckRule =
287 tms <- uses_ TypeCheck (transitiveModuleDeps deps)
287 tms <- uses_ TypeCheck (transitiveModuleDeps deps)
288 setPriority PriorityTypeCheck
288 setPriority PriorityTypeCheck
289 us <- getUniqSupply
289 us <- getUniqSupply
290− packageState <- getPackageState
290+ packageState <- use_ LoadPackageState ""
291 opt <- getOpts
291 opt <- getOpts
292 liftIO $ Compile.typecheckModule opt pm packageState us tms lps pm
292 liftIO $ Compile.typecheckModule opt pm packageState us tms lps pm
293
293
@@ -295,7 +295,7 @@ typeCheckRule =
295loadPackageRule :: Rules ()
295loadPackageRule :: Rules ()
296loadPackageRule =
296loadPackageRule =
297 defineNoFile $ \(LoadPackage pkg) -> do
297 defineNoFile $ \(LoadPackage pkg) -> do
298− packageState <- getPackageState
298+ packageState <- use_ LoadPackageState ""
299 opt <- getOpts
299 opt <- getOpts
300 pkgs <- liftIO $ Compile.computePackageDeps opt packageState pkg
300 pkgs <- liftIO $ Compile.computePackageDeps opt packageState pkg
301 case pkgs of
301 case pkgs of
@@ -319,14 +319,16 @@ generateCoreRule =
319 let pm = tm_parsed_module . Compile.tmrModule $ tm
319 let pm = tm_parsed_module . Compile.tmrModule $ tm
320 setPriority PriorityGenerateDalf
320 setPriority PriorityGenerateDalf
321 us <- getUniqSupply
321 us <- getUniqSupply
322− packageState <- getPackageState
322+ packageState <- use_ LoadPackageState ""
323 opt <- getOpts
323 opt <- getOpts
324 liftIO $ Compile.compileModule opt pm packageState us tms lps tm
324 liftIO $ Compile.compileModule opt pm packageState us tms lps tm
325
325
326−generatePackageStateRule :: Rules ()
326+loadPackageStateRule :: Rules ()
327−generatePackageStateRule =
327+loadPackageStateRule =
328− defineNoFile $ \(GeneratePackageState paths hideAllPkgs pkgImports) -> do
328+ defineNoFile $ \LoadPackageState -> do
329+ opts <- envOptions <$> getServiceEnv
329− liftIO $ Compile.generatePackageState paths hideAllPkgs pkgImports
330+ liftIO $ Compile.generatePackageState
331+ (Compile.optPackageDbs opts) (Compile.optHideAllPkgs opts) (Compile.optPackageImports opts)
330
332
331-- | A rule that wires per-file rules together
333-- | A rule that wires per-file rules together
332mainRule :: Rules ()
334mainRule :: Rules ()
@@ -339,7 +341,7 @@ mainRule = do
339 typeCheckRule
341 typeCheckRule
340 getSpanInfoRule
342 getSpanInfoRule
341 generateCoreRule
343 generateCoreRule
342− generatePackageStateRule
344+ loadPackageStateRule
343 loadPackageRule
345 loadPackageRule
344
346
345------------------------------------------------------------
347------------------------------------------------------------
@@ -347,11 +349,6 @@ mainRule = do
347fileFromParsedModule :: ParsedModule -> IO FilePath
349fileFromParsedModule :: ParsedModule -> IO FilePath
348fileFromParsedModule = pure . ms_hspp_file . pm_mod_summary
350fileFromParsedModule = pure . ms_hspp_file . pm_mod_summary
349
351
350−getPackageState :: Action PackageState
351−getPackageState = do
352− opts <- envOptions <$> getServiceEnv
353− use_ (GeneratePackageState (Compile.optPackageDbs opts) (Compile.optHideAllPkgs opts) (Compile.optPackageImports opts)) ""
354−
355fileImports ::
352fileImports ::
356 [(Located ModuleName, Maybe Import)]
353 [(Located ModuleName, Maybe Import)]
357 -> [(Located ModuleName, Maybe FilePath)]
354 -> [(Located ModuleName, Maybe FilePath)]
src/Development/IDE/State/Shake.hs+11−2
@@ -152,7 +152,11 @@ type IdeResult v = ([FileDiagnostic], Maybe v)
152
152
153type IdeRule k v =
153type IdeRule k v =
154 ( Shake.RuleResult k ~ v
154 ( Shake.RuleResult k ~ v
155− , Shake.ShakeValue k
155+ , Show k
156+ , Typeable k
157+ , NFData k
158+ , Hashable k
159+ , Eq k
156 , Show v
160 , Show v
157 , Typeable v
161 , Typeable v
158 , NFData v
162 , NFData v
@@ -320,7 +324,12 @@ isBadDependency x
320
324
321
325
322newtype Q k = Q (k, FilePath)
326newtype Q k = Q (k, FilePath)
323− deriving (Eq,Hashable,Binary,NFData)
327+ deriving (Eq,Hashable,NFData)
328+
329+-- Using Database we don't need Binary instances for keys
330+instance Binary (Q k) where
331+ put _ = return ()
332+ get = fail "Binary.get not defined for type Development.IDE.State.Shake.Q"
324
333
325instance Show k => Show (Q k) where
334instance Show k => Show (Q k) where
326 show (Q (k, file)) = show k ++ "; " ++ file
335 show (Q (k, file)) = show k ++ "; " ++ file
src/Development/IDE/Types/LSP.hs+1
@@ -58,3 +58,4 @@ data Event
58 | EventFatalError !T.Text
58 | EventFatalError !T.Text
59 -- ^ @EventFatalError reason@: A fatal error occurred in the compiler and
59 -- ^ @EventFatalError reason@: A fatal error occurred in the compiler and
60 -- the compiler cannot continue.
60 -- the compiler cannot continue.
61+ deriving Show
src/Development/IDE/UtilGHC.hs+3−4
@@ -156,12 +156,11 @@ setPackageDbs paths dflags =
156 }
156 }
157 }
157 }
158
158
159−setPackageImports :: Bool -> [(String, [(String, String)])] -> DynFlags -> DynFlags
159+setPackageImports :: Bool -> [(String, ModRenaming)] -> DynFlags -> DynFlags
160setPackageImports hideAllPkgs pkgImports dflags = dflags {
160setPackageImports hideAllPkgs pkgImports dflags = dflags {
161 packageFlags = packageFlags dflags ++
161 packageFlags = packageFlags dflags ++
162− [ExposePackage pkgName (UnitIdArg $ stringToUnitId pkgName)
162+ [ExposePackage pkgName (UnitIdArg $ stringToUnitId pkgName) renaming
163− (ModRenaming False [(mkModuleName mod, mkModuleName alias) | (mod, alias) <- aliases])
164− | (pkgName, aliases) <- pkgImports
163+ | (pkgName, renaming) <- pkgImports
165 ]
164 ]
166 , generalFlags = if hideAllPkgs
165 , generalFlags = if hideAllPkgs
167 then Opt_HideAllPackages `EnumSet.insert` generalFlags dflags
166 then Opt_HideAllPackages `EnumSet.insert` generalFlags dflags