on master help sign in
IDE cleanups and progress towards external usability (#930)

* Remove the requirement for Binary on Shake rules (was not used) * Add a deriving Show on Event, easier for external integrations * Rename GeneratePackageState to LoadPackageState and move its fields to the rule, rather than the key * Inline getPackageState away * Change to passing a ModRenaming to the package loader. Two reasons: 1) When loading non-DAML things we might want to omit the renaming 2) The type ModRenaming has documentation of semantics, unlike [(String, String)]

commit9600e400ea2ff2543397e89d1f05ed4382e28eed authorNeil Mitchell <35463327+neil-da@users.noreply.github.com> dateMon 6 May 2019, 10:57 (7 years ago) parent7376825
7 files changed+35−49
src/Development/IDE/Functions/Compile.hs+2−2 src/Development/IDE/State/FileStore.hs−3 src/Development/IDE/State/RuleTypes.hs+4−21 src/Development/IDE/State/Rules.hs+14−17 src/Development/IDE/State/Shake.hs+11−2 src/Development/IDE/Types/LSP.hs+1 src/Development/IDE/UtilGHC.hs+3−4
src/Development/IDE/Functions/Compile.hs+2−2
@@ -72,7 +72,7 @@ data CompileOpts = CompileOpts
7272
7373 , optPackageDbs :: [FilePath]
7474 , optHideAllPkgs :: Bool
75− , optPackageImports :: [(String, [(String, String)])]
75+ , optPackageImports :: [(String, ModRenaming)]
7676
7777 , optThreads :: Int
7878 , optShakeProfiling :: Maybe FilePath
@@ -486,7 +486,7 @@ parsePragmasIntoDynFlags fp contents = catchSrcErrors $ do
486486 (dflags, _, _) <- parseDynamicFilePragma dflags0 opts
487487 return dflags
488488
489−generatePackageState :: [FilePath] -> Bool -> [(String, [(String, String)])] -> IO PackageState
489+generatePackageState :: [FilePath] -> Bool -> [(String, ModRenaming)] -> IO PackageState
490490generatePackageState paths hideAllPkgs pkgImports = do
491491 let dflags = setPackageImports hideAllPkgs pkgImports $ setPackageDbs paths (defaultDynFlags fakeSettings fakeLlvmConfig)
492492 (newDynFlags, _) <- initPackages dflags
src/Development/IDE/State/FileStore.hs−3
@@ -54,19 +54,16 @@ type instance RuleResult GetFileExists = Bool
5454
5555data GetFileExists = GetFileExists
5656 deriving (Eq, Show, Generic)
57−instance Binary GetFileExists
5857instance Hashable GetFileExists
5958instance NFData GetFileExists
6059
6160data GetModificationTime = GetModificationTime
6261 deriving (Eq, Show, Generic)
63−instance Binary GetModificationTime
6462instance Hashable GetModificationTime
6563instance NFData GetModificationTime
6664
6765data GetFileContents = GetFileContents
6866 deriving (Eq, Show, Generic)
69−instance Binary GetFileContents
7067instance Hashable GetFileContents
7168instance NFData GetFileContents
7269
src/Development/IDE/State/RuleTypes.hs+4−21
@@ -17,8 +17,6 @@ import Development.IDE.Functions.Compile (TcModuleResult,
1717import qualified Development.IDE.Functions.Compile as Compile
1818import Development.IDE.Functions.FindImports (Import(..))
1919import Development.IDE.Functions.DependencyInformation
20−import Data.Binary (Binary)
21−import qualified Data.Binary as Binary
2220import Data.Hashable
2321import Data.Typeable
2422import Development.Shake hiding (Env, newCache)
@@ -63,7 +61,7 @@ type instance RuleResult GenerateCore = GhcModule
6361
6462-- | We capture the subset of `DynFlags` that is computed by package initialization in a rule to
6563-- make session initialization cheaper by reusing it.
66−type instance RuleResult GeneratePackageState = Compile.PackageState
64+type instance RuleResult LoadPackageState = Compile.PackageState
6765
6866-- | Resolve the imports in a module to the list of either external packages or absolute file paths
6967-- for modules in the same package.
@@ -77,69 +75,58 @@ type instance RuleResult ReportImportCycles = ()
7775
7876data OfInterest = OfInterest
7977 deriving (Eq, Show, Typeable, Generic)
80−instance Binary OfInterest
8178instance Hashable OfInterest
8279instance NFData OfInterest
8380
8481data GetParsedModule = GetParsedModule
8582 deriving (Eq, Show, Typeable, Generic)
86−instance Binary GetParsedModule
8783instance Hashable GetParsedModule
8884instance NFData GetParsedModule
8985
9086data GetLocatedImports = GetLocatedImports
9187 deriving (Eq, Show, Typeable, Generic)
92−instance Binary GetLocatedImports
9388instance Hashable GetLocatedImports
9489instance NFData GetLocatedImports
9590
9691data GetDependencyInformation = GetDependencyInformation
9792 deriving (Eq, Show, Typeable, Generic)
98−instance Binary GetDependencyInformation
9993instance Hashable GetDependencyInformation
10094instance NFData GetDependencyInformation
10195
10296data ReportImportCycles = ReportImportCycles
10397 deriving (Eq, Show, Typeable, Generic)
104−instance Binary ReportImportCycles
10598instance Hashable ReportImportCycles
10699instance NFData ReportImportCycles
107100
108101data GetDependencies = GetDependencies
109102 deriving (Eq, Show, Typeable, Generic)
110−instance Binary GetDependencies
111103instance Hashable GetDependencies
112104instance NFData GetDependencies
113105
114106data TypeCheck = TypeCheck
115107 deriving (Eq, Show, Typeable, Generic)
116−instance Binary TypeCheck
117108instance Hashable TypeCheck
118109instance NFData TypeCheck
119110
120111data LoadPackage = LoadPackage InstalledUnitId
121112 deriving (Eq, Show, Typeable, Generic)
122−instance Binary LoadPackage
123113instance Hashable LoadPackage
124114instance NFData LoadPackage
125115
126116data GetSpanInfo = GetSpanInfo
127117 deriving (Eq, Show, Typeable, Generic)
128−instance Binary GetSpanInfo
129118instance Hashable GetSpanInfo
130119instance NFData GetSpanInfo
131120
132121data GenerateCore = GenerateCore
133122 deriving (Eq, Show, Typeable, Generic)
134−instance Binary GenerateCore
135123instance Hashable GenerateCore
136124instance NFData GenerateCore
137125
138−data GeneratePackageState = GeneratePackageState [FilePath] Bool [(String, [(String, String)])]
126+data LoadPackageState = LoadPackageState
139127 deriving (Eq, Show, Typeable, Generic)
140−instance Binary GeneratePackageState
141−instance Hashable GeneratePackageState
142−instance NFData GeneratePackageState
128+instance Hashable LoadPackageState
129+instance NFData LoadPackageState
143130
144131------------------------------------------------------------
145132-- Orphan Instances
@@ -171,10 +158,6 @@ instance NFData SpanInfo where
171158instance NFData Import where
172159 rnf = rwhnf
173160
174−instance Binary InstalledUnitId where
175− get = fmap stringToInstalledUnitId Binary.get
176− put = Binary.put . installedUnitIdString
177−
178161instance Hashable InstalledUnitId where
179162 hashWithSalt salt = hashWithSalt salt . installedUnitIdString
180163
src/Development/IDE/State/Rules.hs+14−17
@@ -172,7 +172,7 @@ getParsedModuleRule :: Rules ()
172172getParsedModuleRule =
173173 define $ \GetParsedModule file -> do
174174 contents <- getFileContents file
175− packageState <- getPackageState
175+ packageState <- use_ LoadPackageState ""
176176 opt <- getOpts
177177 liftIO $ Compile.parseModule opt packageState file contents
178178
@@ -182,7 +182,7 @@ getLocatedImportsRule =
182182 pm <- use_ GetParsedModule file
183183 let ms = pm_mod_summary pm
184184 let imports = ms_textual_imps ms
185− packageState <- getPackageState
185+ packageState <- use_ LoadPackageState ""
186186 opt <- getOpts
187187 dflags <- liftIO $ Compile.getGhcDynFlags opt pm packageState
188188 xs <- forM imports $ \(mbPkgName, modName) ->
@@ -204,7 +204,7 @@ rawDependencyInformation f = go (Set.singleton f) Map.empty Map.empty
204204 let modGraph' = Map.insert f (Left ModuleParseError) modGraph
205205 in go fs modGraph' pkgs
206206 Just imports -> do
207− packageState <- lift getPackageState
207+ packageState <- lift $ use_ LoadPackageState ""
208208 opt <- lift getOpts
209209 modOrPkgImports <- forM imports $ \imp -> do
210210 case imp of
@@ -272,7 +272,7 @@ getSpanInfoRule =
272272 pm <- use_ GetParsedModule file
273273 tc <- use_ TypeCheck file
274274 imports <- use_ GetLocatedImports file
275− packageState <- getPackageState
275+ packageState <- use_ LoadPackageState ""
276276 opt <- getOpts
277277 x <- liftIO $ Compile.getSrcSpanInfos opt pm packageState (fileImports imports) tc
278278 return ([], Just x)
@@ -287,7 +287,7 @@ typeCheckRule =
287287 tms <- uses_ TypeCheck (transitiveModuleDeps deps)
288288 setPriority PriorityTypeCheck
289289 us <- getUniqSupply
290− packageState <- getPackageState
290+ packageState <- use_ LoadPackageState ""
291291 opt <- getOpts
292292 liftIO $ Compile.typecheckModule opt pm packageState us tms lps pm
293293
@@ -295,7 +295,7 @@ typeCheckRule =
295295loadPackageRule :: Rules ()
296296loadPackageRule =
297297 defineNoFile $ \(LoadPackage pkg) -> do
298− packageState <- getPackageState
298+ packageState <- use_ LoadPackageState ""
299299 opt <- getOpts
300300 pkgs <- liftIO $ Compile.computePackageDeps opt packageState pkg
301301 case pkgs of
@@ -319,14 +319,16 @@ generateCoreRule =
319319 let pm = tm_parsed_module . Compile.tmrModule $ tm
320320 setPriority PriorityGenerateDalf
321321 us <- getUniqSupply
322− packageState <- getPackageState
322+ packageState <- use_ LoadPackageState ""
323323 opt <- getOpts
324324 liftIO $ Compile.compileModule opt pm packageState us tms lps tm
325325
326−generatePackageStateRule :: Rules ()
327−generatePackageStateRule =
328− defineNoFile $ \(GeneratePackageState paths hideAllPkgs pkgImports) -> do
329− liftIO $ Compile.generatePackageState paths hideAllPkgs pkgImports
326+loadPackageStateRule :: Rules ()
327+loadPackageStateRule =
328+ defineNoFile $ \LoadPackageState -> do
329+ opts <- envOptions <$> getServiceEnv
330+ liftIO $ Compile.generatePackageState
331+ (Compile.optPackageDbs opts) (Compile.optHideAllPkgs opts) (Compile.optPackageImports opts)
330332
331333-- | A rule that wires per-file rules together
332334mainRule :: Rules ()
@@ -339,7 +341,7 @@ mainRule = do
339341 typeCheckRule
340342 getSpanInfoRule
341343 generateCoreRule
342− generatePackageStateRule
344+ loadPackageStateRule
343345 loadPackageRule
344346
345347------------------------------------------------------------
@@ -347,11 +349,6 @@ mainRule = do
347349fileFromParsedModule :: ParsedModule -> IO FilePath
348350fileFromParsedModule = pure . ms_hspp_file . pm_mod_summary
349351
350−getPackageState :: Action PackageState
351−getPackageState = do
352− opts <- envOptions <$> getServiceEnv
353− use_ (GeneratePackageState (Compile.optPackageDbs opts) (Compile.optHideAllPkgs opts) (Compile.optPackageImports opts)) ""
354−
355352fileImports ::
356353 [(Located ModuleName, Maybe Import)]
357354 -> [(Located ModuleName, Maybe FilePath)]
src/Development/IDE/State/Shake.hs+11−2
@@ -152,7 +152,11 @@ type IdeResult v = ([FileDiagnostic], Maybe v)
152152
153153type IdeRule k v =
154154 ( Shake.RuleResult k ~ v
155− , Shake.ShakeValue k
155+ , Show k
156+ , Typeable k
157+ , NFData k
158+ , Hashable k
159+ , Eq k
156160 , Show v
157161 , Typeable v
158162 , NFData v
@@ -320,7 +324,12 @@ isBadDependency x
320324
321325
322326newtype 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"
324333
325334instance Show k => Show (Q k) where
326335 show (Q (k, file)) = show k ++ "; " ++ file
src/Development/IDE/Types/LSP.hs+1
@@ -58,3 +58,4 @@ data Event
5858 | EventFatalError !T.Text
5959 -- ^ @EventFatalError reason@: A fatal error occurred in the compiler and
6060 -- the compiler cannot continue.
61+ deriving Show
src/Development/IDE/UtilGHC.hs+3−4
@@ -156,12 +156,11 @@ setPackageDbs paths dflags =
156156 }
157157 }
158158
159−setPackageImports :: Bool -> [(String, [(String, String)])] -> DynFlags -> DynFlags
159+setPackageImports :: Bool -> [(String, ModRenaming)] -> DynFlags -> DynFlags
160160setPackageImports hideAllPkgs pkgImports dflags = dflags {
161161 packageFlags = packageFlags dflags ++
162− [ExposePackage pkgName (UnitIdArg $ stringToUnitId pkgName)
163− (ModRenaming False [(mkModuleName mod, mkModuleName alias) | (mod, alias) <- aliases])
164− | (pkgName, aliases) <- pkgImports
162+ [ExposePackage pkgName (UnitIdArg $ stringToUnitId pkgName) renaming
163+ | (pkgName, renaming) <- pkgImports
165164 ]
166165 , generalFlags = if hideAllPkgs
167166 then Opt_HideAllPackages `EnumSet.insert` generalFlags dflags