Skip to content

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

Merged
merged 1 commit into from
Mar 10, 2017

Conversation

Ericson2314
Copy link
Collaborator

There should be little-to-no functional changes with this commit

@mention-bot
Copy link

@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.

ezyang
ezyang previously requested changes Mar 8, 2017
@@ -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,
Copy link
Contributor

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh sure

Copy link
Collaborator Author

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
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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,
Copy link
Contributor

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.

Copy link
Collaborator Author

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?

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Collaborator Author

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 {
Copy link
Contributor

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!

Copy link
Collaborator Author

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.

Copy link
Contributor

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)

{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
module Distribution.Types.MungedId
( MungedId(..)
Copy link
Contributor

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.

Copy link
Collaborator Author

@Ericson2314 Ericson2314 Mar 8, 2017

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.

@ezyang
Copy link
Contributor

ezyang commented Mar 8, 2017

There are also general BC considerations which I've mentioned to @Ericson2314 on IRC.

@Ericson2314
Copy link
Collaborator Author

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 PackageId and MungedId in practice: to disambiguate between packages' origin in the context of new-build projects using local and git overrides. It's unclear how these other package sources interact with qualified goals---perhaps packages with the same name and version from different origins can exist in the same plan.

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
@ezyang
Copy link
Contributor

ezyang commented Mar 9, 2017

I guess this would be an argument for opacity if we can default new fields in a back-compat way (for construction).

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).

Perhaps they both should be opaque? The consistency would make me feel better about it, I think.

The difference is making PackageId opaque is a (gasp) BC-breaking change ;)

@ezyang ezyang dismissed their stale review March 9, 2017 05:59

new patchset

@ezyang ezyang merged commit 332d809 into haskell:master Mar 10, 2017
@Ericson2314 Ericson2314 deleted the munge branch March 10, 2017 16:51
ezyang added a commit to ezyang/cabal that referenced this pull request Mar 14, 2017
This reverts commit 332d809, reversing
changes made to 0c72bc8.
@ezyang ezyang mentioned this pull request Mar 14, 2017
ezyang added a commit to ezyang/cabal that referenced this pull request Mar 14, 2017
ezyang added a commit to ezyang/cabal that referenced this pull request Mar 14, 2017
ezyang added a commit to ezyang/cabal that referenced this pull request Mar 17, 2017
This reverts commit 332d809, reversing
changes made to 0c72bc8.
ezyang added a commit to ezyang/cabal that referenced this pull request Mar 17, 2017
ezyang added a commit to ezyang/cabal that referenced this pull request Mar 21, 2017
Distinguish between true package names, and munged package names
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants