-
Notifications
You must be signed in to change notification settings - Fork 711
Distinguish between true package names, and munged package names #4382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@Ericson2314, thanks for your PR! By analyzing the history of the files in this pull request, we identified @ezyang, @23Skidoo and @dcoutts to be potential reviewers. |
@@ -46,9 +48,10 @@ ipiToPreExistingComponent ipi = | |||
PreExistingComponent { | |||
pc_pkgname = case Installed.sourcePackageName ipi of | |||
Just n -> n | |||
Nothing -> pkgName $ Installed.sourcePackageId ipi, | |||
Nothing -> mkPackageName $ unMungedName | |||
$ mungedName $ Installed.sourceMungedId ipi, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This deserves a comment, since it is doing something dodgy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well hmm, I moved the functionality to Distribution.InstalledPackageInfo
, and give a it a quick comment, but perhaps the fact that ghc-pkg
can strip this metadata so care must be taken should also be mentioned.
@@ -151,6 +162,10 @@ instance Package ConfiguredId where | |||
instance Package (ConfiguredPackage loc) where | |||
packageId cpkg = packageId (confPkgSource cpkg) | |||
|
|||
instance HasMungedId (ConfiguredPackage loc) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has munged id... of what?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I everywhere rename MungedId
to MungedPackageId
? I don't think this is any more or less clear than the type itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At your discretion!
-- 'sourcePackageId' actually stores a *munged* version of the | ||
-- package identifier that also incorporates the component name. | ||
-- The /real/ package name is stored in 'sourcePackageName'. | ||
sourcePackageId :: PackageId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the very least, we need a compatibility definition of sourcePackageId from this module. You can DEPRECATE it if you like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that would solve most problems. Should it recover original name or just be straight synonym?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it depends on whether or not sourcePackageId returns a PackageId or a MungedId ;)
@@ -73,7 +76,8 @@ generate :: PackageDescription -> LocalBuildInfo -> ComponentLocalBuildInfo -> S | |||
generate pkg_descr lbi clbi = | |||
"/* DO NOT EDIT: This file is automatically generated by Cabal */\n\n" ++ | |||
generatePackageVersionMacros | |||
(package pkg_descr : map snd (componentPackageDeps clbi)) ++ | |||
(computeCompatPackageId (package pkg_descr) CLibName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a no-op right, because CLibName always is the real package name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's a no-op. I like to convert in this way this as a warning sign that the code might not be very component-aware.
data PackageIdentifier = PackageIdentifier { | ||
pkgName :: String, | ||
pkgVersion :: Version | ||
data MungedId = MungedId { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't right. The reason why PackageIdentifier is redefined here is because the conversion function needs the Read instance (see below) to be compatible with the output of a Show instance from an old version of Cabal. If you change the data structure as you've done here, you break the Read instance!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change the type name as long as the constructor stays the same? I'm trying that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not only does the constructor have to be, but each record selector has to be the same.
ezyang@sabre:~$ runghc T.hs
MkT {f = 2}
ezyang@sabre:~$ cat T.hs
data T = MkT {f :: Int }
deriving (Show)
main = print (MkT 2)
Cabal/Distribution/Types/MungedId.hs
Outdated
{-# LANGUAGE DeriveDataTypeable #-} | ||
{-# LANGUAGE DeriveGeneric #-} | ||
module Distribution.Types.MungedId | ||
( MungedId(..) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this abstract please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh oops that was never intended.
There are also general BC considerations which I've mentioned to @Ericson2314 on IRC. |
Ok fixed everything but the opacity. Whatever is done there I think is best to do in a second commit (though in this PR is fine.) To put some things into context, I just thought of an example why we hypothetically might want to change I guess this would be an argument for opacity if we can default new fields in a back-compat way (for construction). Perhaps they both should be opaque? The consistency would make me feel better about it, I think. |
There should be little-to-no functional changes with this commit
It depends on how you setup the smart constructor. One reasonably forwards compatible scheme is to have the constructor take package name, library name, and version number. Then you can switch representation between (MungedName, Version) versus (PackageName, LibraryName, Version).
The difference is making PackageId opaque is a (gasp) BC-breaking change ;) |
This reverts commit 4774fb6.
This reverts commit 4774fb6.
This reverts commit 4774fb6.
Distinguish between true package names, and munged package names
There should be little-to-no functional changes with this commit