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