-
Notifications
You must be signed in to change notification settings - Fork 711
Resurrect MungedId patch, and a pile of bugfixes #4397
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
@ezyang, thanks for your PR! By analyzing the history of the files in this pull request, we identified @dcoutts, @Ericson2314 and @23Skidoo to be potential reviewers. |
pp_pn = | ||
-- NB: This syntax isn't quite the source syntax, but it | ||
-- should be clear enough. To do source syntax, we'd | ||
-- need to know what the package we're linking is. |
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 will become the source syntax with my changes, right? :)
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.
Yep.
|
||
instance Package ReadyComponent where | ||
packageId = rc_pkgid | ||
|
||
instance HasMungedPackageId ReadyComponent 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.
Ah good to avoid non-totality in instances 👍
@@ -138,7 +143,7 @@ data PackageIndex a = PackageIndex { | |||
-- | |||
-- FIXME: Clarify what "preference order" means. Check that this invariant is | |||
-- preserved. See #1463 for discussion. | |||
packageIdIndex :: !(Map PackageName (Map Version [a])) | |||
packageIdIndex :: !(Map (PackageName, Maybe UnqualComponentName) (Map Version [a])) |
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.
What about Map PackageName (Map (Maybe UnqualComponentName) (Map Version [a]))
? This matches what you ended up on for Backpack.ConfiguredComponent
(and what I did in my branch :D).
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.
I can push that (if I haven't already) if that would help.
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.
I think that variant is OK too, but it turned out that there weren't really any cases where you wanted to find all components of a PackageName; and this version required less code changes. Notice that in all the functions below, we generally default to looking for the public library.
Actually, in your other PR (still open, but probably a little obsolete now), you did the Map as Map PackageName (Map Version (Map (Maybe UnqualComponentName) [a])))
. I tried using this version first, but it's actually not the right way to go about doing things, because in a lot of ops you just want the public library...
Maybe a three level map makes sense if we decide to handle the solver more correctly than the hack I have right now, but it still doesn't make too much sense, because you still need to work out the relationships between components with the same package identifier.
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 wait that's what I meant write. My goal was eventually that prefiltering of the index that I mentioned on IRC, but that can be done with this too.
@@ -435,12 +464,42 @@ lookupPackageName index name = | |||
-- We get back any number of versions of the specified package name, all | |||
-- satisfying the version range constraint. | |||
-- | |||
-- This does NOT work for internal dependencies, DO NOT use this | |||
-- function on those; use 'lookupInternalDependency' instead. | |||
-- | |||
-- INVARIANT: List of eligible 'IPI.InstalledPackageInfo' is non-empty. | |||
-- | |||
lookupDependency :: InstalledPackageIndex -> Dependency | |||
-> [(Version, [IPI.InstalledPackageInfo])] | |||
lookupDependency index (Dependency name versionRange) = |
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't this be a tiny shim around lookupInternalDependency
with Nothing
?
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.
Yes you're right.
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.
Also perhaps that can mean using only the internal on in configure to save a little code as I did before. I bring it up because with LibDependency it will work that way anyways.
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, this will all get rewritten when LibDependency lands.
53862ec
to
853750d
Compare
CI failures are legit but I probably won't have time to debug until after my defense. |
Oh! When is that? |
Oh, I guess as a maintainer I can push to this? |
Thursday! And yes you can! |
Good luck! |
@ezyang Good luck with your defense! |
-- with anyone else (except other instances of itself). But | ||
-- yet, we ought NOT to say that PNs in the solver are munged | ||
-- package names, because they're not; for source packages, | ||
-- we really will never see source package names. |
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.
I don't really understand this sentence. Should it say "never see munged source package names"?
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.
Yes, it should say munged.
Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
This reverts commit 4774fb6.
This makes the necessary changes to 4dc0f30 to handle component configuring correctly. It probably is a good step towards pkg:lib style dependencies. The big ideas: * There's a new AnnotatedId type, which is any identifier (like ComponentId), but also with a PackageId and ComponentName. It's a bit like ConfiguredId, but ConfiguredId is specialized for ComponentId. There's a conversion function annotatedIdToConfiguredId. * We adopt a totally new strategy for handling MungedPackageId in InstalledPackageInfo. Rather than store the munged package identifier in IPI, we NEVER store it, instead computing it from the package name and library name (which are stored.) There is now code to PARSE a munged package name into these two components, so that when we read 'name' we get the correct info. The resulting code is splendidly clear. * Some places where we took a ComponentName (notably computeCompatPackageName) we now take 'Maybe UnqualComponentName'. This is more accurate, because compatibility package names are only computed for libraries, not other components. Some code in Distribution.Backpack.ReadyComponent is partial now, but the invariants should hold up. * A number of places where MungedId was applied, I undid them. Most notable are macro generation (that should be PACKAGES, not components) and mkLegacyUnitId (since REALLY old style unit identifiers, we won't support internal libraries anyway.) * Many functions in PackageIndex are monomorphized to InstalledPackageInfo. Fortunately cabal-install's usage still works. * Distribution/Client/SolverPlanIndex.hs, not used by anyone, got the axe. * Dependency solving has a hack to solve the problem of how to interpret installed internal libraries in the package database. The basic idea is that, although in most cases where we used a MungedId, we say it explicitly, in the SOLVER, we munge *installed package names* only, and keep the type PackageName. It's a hack, but the alternative is to write a lot more code. Note that is MORALLY PN is indeed a PackageName, since we really are solving for honest to goodness packages, not components! See Note [Index conversion with internal libraries] for more details. * ConfiguredId now records the ComponentName. This is quite important, because we need to use it to figure out how we are going to phrase --dependency. In fact, it is a miracle that this worked at all (and it only worked because of a very skeevy update to the PackageId in the creation of ConfiguredComponent). Irritatingly, this must be a Maybe ComponentName, because a ConfiguredId MIGHT refer to a setup component. Very distressing. Signed-off-by: Edward Z. Yang <[email protected]>
Previously, configCompilerEx was setting Haddock as known, but not actually configuring it; thus, later when we required haddockProgram, we configured the WRONG program. By configuring known programs, we can fix this problem. Signed-off-by: Edward Z. Yang <[email protected]>
* Add missing record selector. * Correctly mkPackageIndex * Skip T4375 on GHC 8.2, it doesn't have a Cabal to actually use! Signed-off-by: Edward Z. Yang <[email protected]>
* Propagate ComponentName to ModuleSource, allowing us to accurately specify both package and library name of references. (Arguably, should just stuff a ComponentInclude in there.) Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
5dd8617
to
c7cd985
Compare
Resurrect MungedId patch, and a pile of bugfixes
I recently was running Backpack tests manually, and noticed that they didn't work! As it turned out, our CI setup for testing with ghc-head had been broken, and so the tests weren't actually being run at all. Ooops.
When I turned the tests back on, I noticed a lot of failures. These were due to #4382, which did not correctly handle picking up internal libraries when --dependency is not explicitly specified (the proximate problem was that PackageIndex was indexed on un-munged PackageName, but we really do need an index from PackageName + LibName when we're testing if package names are defined or not.) The most expedient thing was to undo the change for now, hoping to merge it back once this problem is fixed.
There were some miscellaneous small test drift, but the rest of it didn't have any major problems.
That was the first five patches. THEN, I resurrected @Ericson2314's patch, with a huge pile of refactoring to make everything work.
The big ideas:
There's a new AnnotatedId type, which is any identifier (like
ComponentId), but also with a PackageId and ComponentName.
It's a bit like ConfiguredId, but ConfiguredId is specialized
for ComponentId. There's a conversion function
annotatedIdToConfiguredId.
We adopt a totally new strategy for handling MungedPackageId in
InstalledPackageInfo. Rather than store the munged package
identifier in IPI, we NEVER store it, instead computing it
from the package name and library name (which are stored.)
There is now code to PARSE a munged package name into these
two components, so that when we read 'name' we get the
correct info. The resulting code is splendidly clear.
Some places where we took a ComponentName (notably
computeCompatPackageName) we now take 'Maybe UnqualComponentName'.
This is more accurate, because compatibility package names are
only computed for libraries, not other components. Some code
in Distribution.Backpack.ReadyComponent is partial now,
but the invariants should hold up.
A number of places where MungedId was applied, I undid them.
Most notable are macro generation (that should be PACKAGES,
not components) and mkLegacyUnitId (since REALLY old style
unit identifiers, we won't support internal libraries anyway.)
Many functions in PackageIndex are monomorphized to
InstalledPackageInfo. Fortunately cabal-install's usage
still works.
Distribution/Client/SolverPlanIndex.hs, not used by anyone,
got the axe.
Dependency solving has a hack to solve the problem of how to
interpret installed internal libraries in the package database.
The basic idea is that, although in most cases where we used
a MungedId, we say it explicitly, in the SOLVER, we munge
installed package names only, and keep the type PackageName.
It's a hack, but the alternative is to write a lot more code.
Note that is MORALLY PN is indeed a PackageName, since we really
are solving for honest to goodness packages, not components!
See Note [Index conversion with internal libraries] for more
details.
ConfiguredId now records the ComponentName. This is quite important,
because we need to use it to figure out how we are going to phrase
--dependency. In fact, it is a miracle that this worked at all
(and it only worked because of a very skeevy update to the PackageId
in the creation of ConfiguredComponent). Irritatingly, this must
be a Maybe ComponentName, because a ConfiguredId MIGHT refer to
a setup component. Very distressing.
There's some final extra bugfixes at the end as I was bludgeoning the test suite into passing.