[commit: ghc] wip/nfs-locking: Drop non-derived Show instance for PackageName (dc0bae1)
git at git.haskell.org
git at git.haskell.org
Fri Oct 27 01:00:45 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : wip/nfs-locking
Link : http://ghc.haskell.org/trac/ghc/changeset/dc0bae1e5aeb05e5704e38a8aa5c64887165fcc6/ghc
>---------------------------------------------------------------
commit dc0bae1e5aeb05e5704e38a8aa5c64887165fcc6
Author: Andrey Mokhov <andrey.mokhov at gmail.com>
Date: Sun May 15 00:47:13 2016 +0100
Drop non-derived Show instance for PackageName
>---------------------------------------------------------------
dc0bae1e5aeb05e5704e38a8aa5c64887165fcc6
src/Oracles/PackageDeps.hs | 8 ++++----
src/Package.hs | 21 +++++++++------------
2 files changed, 13 insertions(+), 16 deletions(-)
diff --git a/src/Oracles/PackageDeps.hs b/src/Oracles/PackageDeps.hs
index a2a9234..7983c7f 100644
--- a/src/Oracles/PackageDeps.hs
+++ b/src/Oracles/PackageDeps.hs
@@ -7,7 +7,7 @@ import Base
import Package
import Settings.Paths
-newtype PackageDepsKey = PackageDepsKey PackageName
+newtype PackageDepsKey = PackageDepsKey String
deriving (Show, Typeable, Eq, Hashable, Binary, NFData)
-- @packageDeps name@ is an action that given a 'Package' looks up its
@@ -15,8 +15,8 @@ newtype PackageDepsKey = PackageDepsKey PackageName
-- computed by scanning package cabal files (see Rules.Cabal).
packageDeps :: Package -> Action [PackageName]
packageDeps pkg = do
- res <- askOracle . PackageDepsKey . pkgName $ pkg
- return . fromMaybe [] $ res
+ res <- askOracle . PackageDepsKey $ pkgNameString pkg
+ return . map PackageName $ fromMaybe [] res
-- Oracle for the package dependencies file
packageDepsOracle :: Rules ()
@@ -25,6 +25,6 @@ packageDepsOracle = do
putOracle $ "Reading package dependencies..."
contents <- readFileLines packageDependencies
return . Map.fromList $
- [ (p, ps) | line <- contents, let p:ps = map PackageName $ words line ]
+ [ (p, ps) | line <- contents, let p:ps = words line ]
_ <- addOracle $ \(PackageDepsKey pkg) -> Map.lookup pkg <$> deps ()
return ()
diff --git a/src/Package.hs b/src/Package.hs
index 4b6fbc6..1fc1ac9 100644
--- a/src/Package.hs
+++ b/src/Package.hs
@@ -15,12 +15,9 @@ import GHC.Generics (Generic)
import Data.String
-- | The name of a Cabal package
-newtype PackageName = PackageName { getPackageName :: String }
+newtype PackageName = PackageName { fromPackageName :: String }
deriving (Eq, Ord, IsString, Generic, Binary, Hashable, Typeable, NFData)
-instance Show PackageName where
- show (PackageName name) = name
-
-- TODO: Make PackageType more precise, #12
-- TODO: Turn Program to Program FilePath thereby getting rid of programPath
-- | We regard packages as either being libraries or programs. This is
@@ -37,23 +34,23 @@ data Package = Package
-- | Prettyprint Package name.
pkgNameString :: Package -> String
-pkgNameString = getPackageName . pkgName
+pkgNameString = fromPackageName . pkgName
-- | Relative path to cabal file, e.g.: "libraries/Cabal/Cabal/Cabal.cabal"
pkgCabalFile :: Package -> FilePath
-pkgCabalFile pkg = pkgPath pkg -/- getPackageName (pkgName pkg) <.> "cabal"
+pkgCabalFile pkg = pkgPath pkg -/- pkgNameString pkg <.> "cabal"
-- | Smart constructor for a top-level package, e.g. 'compiler'.
topLevel :: PackageName -> Package
-topLevel name = Package name (getPackageName name) Library
+topLevel name = Package name (fromPackageName name) Library
-- | Smart constructor for a library package, e.g. 'array'.
library :: PackageName -> Package
-library name = Package name ("libraries" -/- getPackageName name) Library
+library name = Package name ("libraries" -/- fromPackageName name) Library
-- | Smart constructor for a utility package, e.g. 'haddock'.
utility :: PackageName -> Package
-utility name = Package name ("utils" -/- getPackageName name) Program
+utility name = Package name ("utils" -/- fromPackageName name) Program
-- | Amend package path. Useful when a package name doesn't match its path.
setPath :: Package -> FilePath -> Package
@@ -65,17 +62,17 @@ setType pkg ty = pkg { pkgType = ty }
-- | Check whether a package is a library.
isLibrary :: Package -> Bool
-isLibrary (Package {pkgType=Library}) = True
+isLibrary (Package _ _ Library) = True
isLibrary _ = False
-- | Check whether a package is a program.
isProgram :: Package -> Bool
-isProgram (Package {pkgType=Program}) = True
+isProgram (Package _ _ Program) = True
isProgram _ = False
-- TODO: Get rid of non-derived Show instances.
instance Show Package where
- show = show . pkgName
+ show = pkgNameString
instance Eq Package where
(==) = (==) `on` pkgName
More information about the ghc-commits
mailing list