Skip to content

Commit 1accbca

Browse files
committed
Add data ProjectImport replacing tuples
1 parent b61e031 commit 1accbca

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

cabal-install-solver/src/Distribution/Solver/Types/ProjectConfigPath.hs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
{-# LANGUAGE DeriveGeneric #-}
2+
{-# LANGUAGE NamedFieldPuns #-}
23
{-# LANGUAGE ViewPatterns #-}
34

45
module Distribution.Solver.Types.ProjectConfigPath
56
(
67
-- * Project Config Path Manipulation
7-
ProjectConfigPath(..)
8+
ProjectImport(..)
9+
, ProjectConfigPath(..)
810
, projectConfigPathRoot
911
, nullProjectConfigPath
1012
, consProjectConfigPath
@@ -45,6 +47,13 @@ import Text.PrettyPrint
4547
import Distribution.Simple.Utils (ordNub)
4648
import Distribution.System (OS(Windows), buildOS)
4749

50+
data ProjectImport =
51+
ProjectImport
52+
{ importOf :: FilePath
53+
, importBy :: ProjectConfigPath
54+
}
55+
deriving (Eq, Ord)
56+
4857
-- | Path to a configuration file, either a singleton project root, or a longer
4958
-- list representing a path to an import. The path is a non-empty list that we
5059
-- build up by prepending relative imports with @consProjectConfigPath@.
@@ -180,18 +189,18 @@ cyclicalImportMsg path@(ProjectConfigPath (duplicate :| _)) =
180189
-- | A message for a duplicate import, a "duplicate import of". If a check for
181190
-- cyclical imports has already been made then this would report a duplicate
182191
-- import by two different paths.
183-
duplicateImportMsg :: Doc -> FilePath -> ProjectConfigPath -> [(FilePath, ProjectConfigPath)] -> Doc
192+
duplicateImportMsg :: Doc -> FilePath -> ProjectConfigPath -> [ProjectImport] -> Doc
184193
duplicateImportMsg intro = seenImportMsg intro
185194

186-
seenImportMsg :: Doc -> FilePath -> ProjectConfigPath -> [(FilePath, ProjectConfigPath)] -> Doc
187-
seenImportMsg intro duplicate path seenImportsBy =
195+
seenImportMsg :: Doc -> FilePath -> ProjectConfigPath -> [ProjectImport] -> Doc
196+
seenImportMsg intro duplicate path seenImports =
188197
vcat
189198
[ intro
190199
, nest 2 (docProjectConfigPath path)
191200
, nest 2 $
192201
vcat
193-
[ docProjectConfigPath dib
194-
| (_, dib) <- filter ((duplicate ==) . fst) seenImportsBy
202+
[ docProjectConfigPath importBy
203+
| ProjectImport{importBy} <- filter ((duplicate ==) . importOf) seenImports
195204
]
196205
]
197206

cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ parseProject rootPath cacheDir httpTransport verbosity configToParse = do
257257
let (dir, projectFileName) = splitFileName rootPath
258258
projectDir <- makeAbsolute dir
259259
projectPath@(ProjectConfigPath (canonicalRoot :| _)) <- canonicalizeConfigPath projectDir (ProjectConfigPath $ projectFileName :| [])
260-
importsBy <- newIORef $ toNubList [(canonicalRoot, projectPath)]
260+
importsBy <- newIORef $ toNubList [ProjectImport canonicalRoot projectPath]
261261
dupesMap <- newIORef mempty
262262
result <- parseProjectSkeleton cacheDir httpTransport verbosity importsBy dupesMap projectDir projectPath configToParse
263263
dupes <- Map.filter ((> 1) . length) <$> readIORef dupesMap
@@ -267,7 +267,7 @@ parseProject rootPath cacheDir httpTransport verbosity configToParse = do
267267
data Dupes = Dupes
268268
{ dupesUniqueImport :: FilePath
269269
, dupesNormLocPath :: ProjectConfigPath
270-
, dupesSeenImportsBy :: [(FilePath, ProjectConfigPath)]
270+
, dupesSeenImportsBy :: [ProjectImport]
271271
}
272272
deriving (Eq)
273273

@@ -286,7 +286,7 @@ parseProjectSkeleton
286286
:: FilePath
287287
-> HttpTransport
288288
-> Verbosity
289-
-> IORef (NubList (FilePath, ProjectConfigPath))
289+
-> IORef (NubList ProjectImport)
290290
-- ^ The imports seen so far, used to report on cycles and duplicates and to detect duplicates that are not cycles
291291
-> IORef DupesMap
292292
-- ^ The duplicates seen so far, used to defer reporting on duplicates
@@ -308,7 +308,7 @@ parseProjectSkeleton cacheDir httpTransport verbosity importsBy dupesMap project
308308
-- Once we canonicalize the import path, we can check for cyclical and duplicate imports
309309
normSource <- canonicalizeConfigPath projectDir source
310310
normLocPath@(ProjectConfigPath (uniqueImport :| _)) <- canonicalizeConfigPath projectDir importLocPath
311-
seenImportsBy@(fmap fst -> seenImports) <- fromNubList <$> atomicModifyIORef' importsBy (\ibs -> (toNubList [(uniqueImport, normLocPath)] <> ibs, ibs))
311+
seenImportsBy@(fmap importOf -> seenImports) <- fromNubList <$> atomicModifyIORef' importsBy (\ibs -> (toNubList [ProjectImport uniqueImport normLocPath] <> ibs, ibs))
312312
debug verbosity $ "\nimport path, normalized\n=======================\n" ++ render (docProjectConfigPath normLocPath)
313313
debug verbosity "\nseen unique paths\n================="
314314
mapM_ (debug verbosity) seenImports

0 commit comments

Comments
 (0)