Commit 7378066d authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺 Committed by GitHub
Browse files

Make `AbiHash` opaque & `ShortText`-backed (#3921)

This doesn't have any noteworthy performance impact since
there aren't that many `AbiHash` values to keep track of and is
rather for consistency with the other opaque types.
parent 32bdc993
......@@ -146,7 +146,7 @@ emptyInstalledPackageInfo
synopsis = "",
description = "",
category = "",
abiHash = AbiHash "",
abiHash = mkAbiHash "",
exposed = False,
exposedModules = [],
hiddenModules = [],
......
......@@ -35,7 +35,7 @@ module Distribution.Package (
Module(..),
-- * ABI hash
AbiHash(..),
AbiHash, unAbiHash, mkAbiHash,
-- * Package source dependencies
Dependency(..),
......@@ -188,6 +188,8 @@ mkComponentId :: String -> ComponentId
mkComponentId = ComponentId . toShortText
-- | Convert 'ComponentId' to 'String'
--
-- @since 2.0
unComponentId :: ComponentId -> String
unComponentId (ComponentId s) = fromShortText s
......@@ -307,10 +309,36 @@ class (HasUnitId pkg) => PackageInstalled pkg where
-- -----------------------------------------------------------------------------
-- ABI hash
newtype AbiHash = AbiHash String
-- | ABI Hashes
--
-- Use 'mkAbiHash' and 'unAbiHash' to convert from/to a
-- 'String'.
--
-- This type is opaque since @Cabal-2.0@
--
-- @since 2.0
newtype AbiHash = AbiHash ShortText
deriving (Eq, Show, Read, Generic)
-- | Construct a 'AbiHash' from a 'String'
--
-- 'mkAbiHash' is the inverse to 'unAbiHash'
--
-- Note: No validations are performed to ensure that the resulting
-- 'AbiHash' is valid
--
-- @since 2.0
unAbiHash :: AbiHash -> String
unAbiHash (AbiHash h) = fromShortText h
-- | Convert 'AbiHash' to 'String'
--
-- @since 2.0
mkAbiHash :: String -> AbiHash
mkAbiHash = AbiHash . toShortText
instance Binary AbiHash
instance Text AbiHash where
disp (AbiHash abi) = Disp.text abi
parse = fmap AbiHash (Parse.munch isAlphaNum)
disp = Disp.text . unAbiHash
parse = fmap mkAbiHash (Parse.munch isAlphaNum)
......@@ -222,7 +222,7 @@ buildComponent verbosity numJobs pkg_descr lbi suffixes
pwd <- getCurrentDirectory
let -- The in place registration uses the "-inplace" suffix, not an ABI hash
installedPkgInfo = inplaceInstalledPackageInfo pwd distPref pkg_descr
(AbiHash "") lib' lbi clbi
(mkAbiHash "") lib' lbi clbi
registerPackage verbosity (compiler lbi) (withPrograms lbi) HcPkg.MultiInstance
(withPackageDB lbi) installedPkgInfo
......@@ -444,7 +444,7 @@ testSuiteLibV09AsLibAndExe pkg_descr
, testSuites = []
, subLibraries = [lib]
}
ipi = inplaceInstalledPackageInfo pwd distPref pkg (AbiHash "") lib lbi libClbi
ipi = inplaceInstalledPackageInfo pwd distPref pkg (mkAbiHash "") lib lbi libClbi
testDir = buildDir lbi </> stubName test
</> stubName test ++ "-tmp"
testLibDep = thisPackageVersion $ package pkg
......
......@@ -70,7 +70,7 @@ toCurrent ipi@InstalledPackageInfo{} =
Current.sourcePackageId = pid,
Current.installedUnitId = Current.mkLegacyUnitId pid,
Current.compatPackageKey = "",
Current.abiHash = Current.AbiHash "", -- bogus but old GHCs don't care.
Current.abiHash = Current.mkAbiHash "", -- bogus but old GHCs don't care.
Current.license = convertLicense (license ipi),
Current.copyright = copyright ipi,
Current.maintainer = maintainer ipi,
......
......@@ -237,10 +237,10 @@ generateRegistrationInfo verbosity pkg lib lbi clbi inplace reloc distPref packa
abi_hash <-
case compilerFlavor comp of
GHC | compilerVersion comp >= mkVersion [6,11] -> do
fmap AbiHash $ GHC.libAbiHash verbosity pkg lbi' lib clbi
fmap mkAbiHash $ GHC.libAbiHash verbosity pkg lbi' lib clbi
GHCJS -> do
fmap AbiHash $ GHCJS.libAbiHash verbosity pkg lbi' lib clbi
_ -> return (AbiHash "")
fmap mkAbiHash $ GHCJS.libAbiHash verbosity pkg lbi' lib clbi
_ -> return (mkAbiHash "")
installedPkgInfo <-
if inplace
......
......@@ -52,6 +52,9 @@
* Backwards incompatible change to 'ComponentId' (#3917):
'ComponentId' is now opaque; conversion to/from 'String' now works
via 'unComponentId' and 'mkComponentId' functions.
* Backwards incompatible change to 'AbiHash' (#3921):
'AbiHash' is now opaque; conversion to/from 'String' now works
via 'unAbiHash' and 'mkAbiHash' functions.
* Backwards incompatible change to 'Version' (#3905):
Version is now opaque; conversion to/from '[Int]' now works
via 'versionNumbers' and 'mkVersion' functions.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment