@@ -64,15 +64,20 @@ data ModuleImports = ModuleImports
64 -- ^ Transitive package dependencies unioned for all imports.
64 -- ^ Transitive package dependencies unioned for all imports.
67−-- | For processing dependency information, we need lots of maps and sets
67+-- | For processing dependency information, we need lots of maps and sets of
68−-- of filepaths. Comparing Strings is really slow, so we work with IntMap/IntSet
68+-- filepaths. Comparing Strings is really slow, so we work with IntMap/IntSet
69−-- instead and only convert at the edges
69+-- instead and only convert at the edges.
71newtype FilePathId = FilePathId { getFilePathId :: Int }
70newtype FilePathId = FilePathId { getFilePathId :: Int }
72 deriving (Show, NFData, Eq, Ord)
71 deriving (Show, NFData, Eq, Ord)
73+-- | Map from 'FilePathId'
74+type FilePathIdMap = IntMap
76+-- | Set of 'FilePathId's
77+type FilePathIdSet = IntSet
74data PathIdMap = PathIdMap
79data PathIdMap = PathIdMap
75− { idToPathMap :: !(IntMap ArtifactsLocation)
80+ { idToPathMap :: !(FilePathIdMap ArtifactsLocation)
76 , pathToIdMap :: !(HashMap NormalizedFilePath FilePathId)
81 , pathToIdMap :: !(HashMap NormalizedFilePath FilePathId)
78 deriving (Show, Generic)
83 deriving (Show, Generic)
@@ -109,16 +114,14 @@ idToPath pathIdMap filePathId = artifactFilePath $ idToModLocation pathIdMap fil
109idToModLocation :: PathIdMap -> FilePathId -> ArtifactsLocation
114idToModLocation :: PathIdMap -> FilePathId -> ArtifactsLocation
110idToModLocation PathIdMap{idToPathMap} (FilePathId id) = idToPathMap IntMap.! id
115idToModLocation PathIdMap{idToPathMap} (FilePathId id) = idToPathMap IntMap.! id
113−type BootIdMap = IntMap FilePathId
117+type BootIdMap = FilePathIdMap FilePathId
115insertBootId :: FilePathId -> FilePathId -> BootIdMap -> BootIdMap
119insertBootId :: FilePathId -> FilePathId -> BootIdMap -> BootIdMap
116insertBootId k = IntMap.insert (getFilePathId k)
120insertBootId k = IntMap.insert (getFilePathId k)
119-- | Unprocessed results that we find by following imports recursively.
122-- | Unprocessed results that we find by following imports recursively.
120data RawDependencyInformation = RawDependencyInformation
123data RawDependencyInformation = RawDependencyInformation
121− { rawImports :: !(IntMap (Either ModuleParseError ModuleImports))
124+ { rawImports :: !(FilePathIdMap (Either ModuleParseError ModuleImports))
122 , rawPathIdMap :: !PathIdMap
125 , rawPathIdMap :: !PathIdMap
123 -- The rawBootMap maps the FilePathId of a hs-boot file to its
126 -- The rawBootMap maps the FilePathId of a hs-boot file to its
124 -- corresponding hs file. It is used when topologically sorting as we
127 -- corresponding hs file. It is used when topologically sorting as we
@@ -127,23 +130,24 @@ data RawDependencyInformation = RawDependencyInformation
127 , rawBootMap :: !BootIdMap
130 , rawBootMap :: !BootIdMap
130−pkgDependencies :: RawDependencyInformation -> IntMap (Set InstalledUnitId)
133+pkgDependencies :: RawDependencyInformation -> FilePathIdMap (Set InstalledUnitId)
131pkgDependencies RawDependencyInformation{..} =
134pkgDependencies RawDependencyInformation{..} =
132 IntMap.map (either (const Set.empty) packageImports) rawImports
135 IntMap.map (either (const Set.empty) packageImports) rawImports
134data DependencyInformation =
137data DependencyInformation =
135 DependencyInformation
138 DependencyInformation
136− { depErrorNodes :: !(IntMap (NonEmpty NodeError))
139+ { depErrorNodes :: !(FilePathIdMap (NonEmpty NodeError))
137 -- ^ Nodes that cannot be processed correctly.
140 -- ^ Nodes that cannot be processed correctly.
138− , depModuleNames :: !(IntMap ShowableModuleName)
141+ , depModuleNames :: !(FilePathIdMap ShowableModuleName)
139− , depModuleDeps :: !(IntMap IntSet)
142+ , depModuleDeps :: !(FilePathIdMap FilePathIdSet)
140 -- ^ For a non-error node, this contains the set of module immediate dependencies
143 -- ^ For a non-error node, this contains the set of module immediate dependencies
141 -- in the same package.
144 -- in the same package.
142− , depPkgDeps :: !(IntMap (Set InstalledUnitId))
145+ , depPkgDeps :: !(FilePathIdMap (Set InstalledUnitId))
143 -- ^ For a non-error node, this contains the set of immediate pkg deps.
146 -- ^ For a non-error node, this contains the set of immediate pkg deps.
144 , depPathIdMap :: !PathIdMap
147 , depPathIdMap :: !PathIdMap
145− -- ^ Map from hs-boot file to the corresponding hs file
148+ -- ^ Map from FilePath to FilePathId
146 , depBootMap :: !BootIdMap
149 , depBootMap :: !BootIdMap
150+ -- ^ Map from hs-boot file to the corresponding hs file
147 } deriving (Show, Generic)
151 } deriving (Show, Generic)
149newtype ShowableModuleName =
153newtype ShowableModuleName =
@@ -243,7 +247,7 @@ processDependencyInformation rawDepInfo@RawDependencyInformation{..} =
243-- 2. Mark each node that has a parse error as an error node.
247-- 2. Mark each node that has a parse error as an error node.
244-- 3. Mark each node whose immediate children could not be located as an error.
248-- 3. Mark each node whose immediate children could not be located as an error.
245-- 4. Recursively propagate errors to parents if they are not already error nodes.
249-- 4. Recursively propagate errors to parents if they are not already error nodes.
246−buildResultGraph :: IntMap (Either ModuleParseError ModuleImports) -> IntMap NodeResult
250+buildResultGraph :: FilePathIdMap (Either ModuleParseError ModuleImports) -> FilePathIdMap NodeResult
247buildResultGraph g = propagatedErrors
251buildResultGraph g = propagatedErrors
249 sccs = stronglyConnComp (graphEdges g)
253 sccs = stronglyConnComp (graphEdges g)
@@ -290,7 +294,7 @@ buildResultGraph g = propagatedErrors
290 Right ModuleImports{moduleImports} ->
294 Right ModuleImports{moduleImports} ->
291 fmap fst $ find (\(_, resolvedImp) -> resolvedImp == Just importedFile) moduleImports
295 fmap fst $ find (\(_, resolvedImp) -> resolvedImp == Just importedFile) moduleImports
293−graphEdges :: IntMap (Either ModuleParseError ModuleImports) -> [(FilePathId, FilePathId, [FilePathId])]
297+graphEdges :: FilePathIdMap (Either ModuleParseError ModuleImports) -> [(FilePathId, FilePathId, [FilePathId])]
294graphEdges g =
298graphEdges g =
295 map (\(k, v) -> (FilePathId k, FilePathId k, deps v)) $ IntMap.toList g
299 map (\(k, v) -> (FilePathId k, FilePathId k, deps v)) $ IntMap.toList g
296 where deps :: Either e ModuleImports -> [FilePathId]
300 where deps :: Either e ModuleImports -> [FilePathId]