From 9adf58c295065e4104e9aecc8a91f7b0b973457b Mon Sep 17 00:00:00 2001 From: Kristen Kozak Date: Mon, 24 Jul 2023 23:09:44 -0700 Subject: [PATCH 1/2] Combine non-installable and non-upgradable package lists (fixes #8581) This commit continues the work in b016e597d0bfdcc462d1b8b1fbc7220d1209028c to combine the lists of non-installable and non-upgradable packages. When a package is in the list, it means that the solver will only consider installed instances of that package. This commit renames the list from "non-upgradable" to "non-reinstallable" to clarify that the packages cannot be upgraded or downgraded. There should be no change in behavior, except for the wording of solver error messages. --- .../Distribution/Solver/Modular/Message.hs | 1 - .../Distribution/Solver/Modular/Preference.hs | 13 ------- .../src/Distribution/Solver/Modular/Solver.hs | 5 --- .../src/Distribution/Solver/Modular/Tree.hs | 1 - .../Solver/Types/ConstraintSource.hs | 6 +-- .../src/Distribution/Client/Dependency.hs | 39 +++++-------------- .../Distribution/Solver/Modular/Solver.hs | 6 +-- 7 files changed, 16 insertions(+), 55 deletions(-) diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs index d802079d04c..73580aff3e6 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Message.hs @@ -228,7 +228,6 @@ showFR _ (NewPackageHasUnbuildableRequiredComponent comp dr) = " (" ++ showExpos showFR _ (PackageRequiresMissingComponent qpn comp) = " (requires " ++ showExposedComponent comp ++ " from " ++ showQPN qpn ++ ", but the component does not exist)" showFR _ (PackageRequiresPrivateComponent qpn comp) = " (requires " ++ showExposedComponent comp ++ " from " ++ showQPN qpn ++ ", but the component is private)" showFR _ (PackageRequiresUnbuildableComponent qpn comp) = " (requires " ++ showExposedComponent comp ++ " from " ++ showQPN qpn ++ ", but the component is not buildable in the current environment)" -showFR _ CannotInstall = " (only already installed instances can be used)" showFR _ CannotReinstall = " (avoiding to reinstall a package with same version but new dependencies)" showFR _ NotExplicit = " (not a user-provided goal nor mentioned as a constraint, but reject-unconstrained-dependencies was set)" showFR _ Shadowed = " (shadowed by another installed package with same version)" diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs index 3c5b6c5f984..9e0d5fb4d22 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs @@ -12,7 +12,6 @@ module Distribution.Solver.Modular.Preference , preferLinked , preferPackagePreferences , preferReallyEasyGoalChoices - , requireInstalled , onlyConstrained , sortGoals , pruneAfterFirstSuccess @@ -318,18 +317,6 @@ enforceManualFlags pcs = go in W.mapWithKey (restrictToggling d flagConstraintValues) ts go x = x --- | Require installed packages. -requireInstalled :: (PN -> Bool) -> EndoTreeTrav d c -requireInstalled p = go - where - go (PChoiceF v@(Q _ pn) rdm gr cs) - | p pn = PChoiceF v rdm gr (W.mapWithKey installed cs) - | otherwise = PChoiceF v rdm gr cs - where - installed (POption (I _ (Inst _)) _) x = x - installed _ _ = Fail (varToConflictSet (P v)) CannotInstall - go x = x - -- | Avoid reinstalls. -- -- This is a tricky strategy. If a package version is installed already and the diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs index 87ce414059f..39bd7bf4690 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs @@ -66,8 +66,6 @@ data SolverConfig = SolverConfig { avoidReinstalls :: AvoidReinstalls, shadowPkgs :: ShadowPkgs, strongFlags :: StrongFlags, - allowBootLibInstalls :: AllowBootLibInstalls, - nonInstallablePackages :: [PackageName], onlyConstrained :: OnlyConstrained, maxBackjumps :: Maybe Int, enableBackjumping :: EnableBackjumping, @@ -141,9 +139,6 @@ solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals = validateLinking idx . validateTree cinfo idx pkgConfigDB prunePhase = (if asBool (avoidReinstalls sc) then P.avoidReinstalls (const True) else id) . - (if asBool (allowBootLibInstalls sc) - then id - else P.requireInstalled (`elem` nonInstallablePackages sc)) . (case onlyConstrained sc of OnlyConstrainedAll -> P.onlyConstrained pkgIsExplicit diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Tree.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Tree.hs index 039da4b41b0..10d372525b1 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Tree.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Tree.hs @@ -110,7 +110,6 @@ data FailReason = UnsupportedExtension Extension | PackageRequiresMissingComponent QPN ExposedComponent | PackageRequiresPrivateComponent QPN ExposedComponent | PackageRequiresUnbuildableComponent QPN ExposedComponent - | CannotInstall | CannotReinstall | NotExplicit | Shadowed diff --git a/cabal-install-solver/src/Distribution/Solver/Types/ConstraintSource.hs b/cabal-install-solver/src/Distribution/Solver/Types/ConstraintSource.hs index 7d821257234..dadf8bf08b1 100644 --- a/cabal-install-solver/src/Distribution/Solver/Types/ConstraintSource.hs +++ b/cabal-install-solver/src/Distribution/Solver/Types/ConstraintSource.hs @@ -27,7 +27,7 @@ data ConstraintSource = | ConstraintSourceUserTarget -- | Internal requirement to use installed versions of packages like ghc-prim. - | ConstraintSourceNonUpgradeablePackage + | ConstraintSourceNonReinstallablePackage -- | Internal constraint used by @cabal freeze@. | ConstraintSourceFreeze @@ -64,8 +64,8 @@ showConstraintSource (ConstraintSourceProjectConfig path) = showConstraintSource (ConstraintSourceUserConfig path)= "user config " ++ path showConstraintSource ConstraintSourceCommandlineFlag = "command line flag" showConstraintSource ConstraintSourceUserTarget = "user target" -showConstraintSource ConstraintSourceNonUpgradeablePackage = - "non-upgradeable package" +showConstraintSource ConstraintSourceNonReinstallablePackage = + "non-reinstallable package" showConstraintSource ConstraintSourceFreeze = "cabal freeze" showConstraintSource ConstraintSourceConfigFlagOrTarget = "config file, command line flag, or user target" diff --git a/cabal-install/src/Distribution/Client/Dependency.hs b/cabal-install/src/Distribution/Client/Dependency.hs index 056d0ffed05..f5a0d3a9b9f 100644 --- a/cabal-install/src/Distribution/Client/Dependency.hs +++ b/cabal-install/src/Distribution/Client/Dependency.hs @@ -436,26 +436,18 @@ setSolverVerbosity verbosity params = } -- | Some packages are specific to a given compiler version and should never be --- upgraded. -dontUpgradeNonUpgradeablePackages :: DepResolverParams -> DepResolverParams -dontUpgradeNonUpgradeablePackages params = +-- reinstalled. +dontInstallNonReinstallablePackages :: DepResolverParams -> DepResolverParams +dontInstallNonReinstallablePackages params = addConstraints extraConstraints params where extraConstraints = [ LabeledPackageConstraint (PackageConstraint (ScopeAnyQualifier pkgname) PackagePropertyInstalled) - ConstraintSourceNonUpgradeablePackage - | Set.notMember (mkPackageName "base") (depResolverTargets params) - , pkgname <- nonUpgradeablePackages - , isInstalled pkgname + ConstraintSourceNonReinstallablePackage + | pkgname <- nonReinstallablePackages ] - isInstalled = - not - . null - . InstalledPackageIndex.lookupPackageName - (depResolverInstalledPkgIndex params) - -- | The set of non-reinstallable packages includes those which cannot be -- rebuilt using a GHC installation and Hackage-published source distribution. -- There are a few reasons why this might be true: @@ -471,15 +463,8 @@ dontUpgradeNonUpgradeablePackages params = -- * the package does not have a complete (that is, buildable) source distribution. -- For instance, some packages provided by GHC rely on files outside of the -- source tree generated by GHC's build system. --- --- Note: the list of non-upgradable/non-installable packages used to be --- respectively in this module and in `Distribution.Solver.Modular.Solver`. --- Since they were kept synced, they are now combined in the following list. --- --- See: https://github.com/haskell/cabal/issues/8581 and --- https://github.com/haskell/cabal/issues/9064. -nonUpgradeablePackages :: [PackageName] -nonUpgradeablePackages = +nonReinstallablePackages :: [PackageName] +nonReinstallablePackages = [ mkPackageName "base" , mkPackageName "ghc-bignum" , mkPackageName "ghc-prim" @@ -792,7 +777,7 @@ resolveDependencies -> Solver -> DepResolverParams -> Progress String String SolverInstallPlan --- TODO: is this needed here? see dontUpgradeNonUpgradeablePackages +-- TODO: is this needed here? see dontInstallNonReinstallablePackages resolveDependencies platform comp _pkgConfigDB _solver params | Set.null (depResolverTargets params) = return (validateSolverResult platform comp indGoals []) @@ -812,10 +797,6 @@ resolveDependencies platform comp pkgConfigDB solver params = noReinstalls shadowing strFlags - allowBootLibs - -- See comment of nonUpgradeablePackages about - -- non-installable and non-upgradable packages. - nonUpgradeablePackages onlyConstrained_ maxBkjumps enableBj @@ -848,7 +829,7 @@ resolveDependencies platform comp pkgConfigDB solver params = noReinstalls shadowing strFlags - allowBootLibs + _allowBootLibs onlyConstrained_ maxBkjumps enableBj @@ -858,7 +839,7 @@ resolveDependencies platform comp pkgConfigDB solver params = ) = if asBool (depResolverAllowBootLibInstalls params) then params - else dontUpgradeNonUpgradeablePackages params + else dontInstallNonReinstallablePackages params preferences :: PackageName -> PackagePreferences preferences = interpretPackagesPreference targets defpref prefs diff --git a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs index d5973598fa9..123979921b1 100644 --- a/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs @@ -192,17 +192,17 @@ tests = , runTest $ mkTest db12 "baseShim6" ["E"] (solverSuccess [("E", 1), ("syb", 2)]) ] , testGroup - "Base and Nonupgradable" + "Base and non-reinstallable" [ runTest $ mkTest dbBase "Refuse to install base without --allow-boot-library-installs" ["base"] $ - solverFailure (isInfixOf "only already installed instances can be used") + solverFailure (isInfixOf "rejecting: base-1.0.0 (constraint from non-reinstallable package requires installed instance)") , runTest $ allowBootLibInstalls $ mkTest dbBase "Install base with --allow-boot-library-installs" ["base"] $ solverSuccess [("base", 1), ("ghc-prim", 1), ("integer-gmp", 1), ("integer-simple", 1)] , runTest $ mkTest dbNonupgrade "Refuse to install newer ghc requested by another library" ["A"] $ - solverFailure (isInfixOf "rejecting: ghc-2.0.0 (constraint from non-upgradeable package requires installed instance)") + solverFailure (isInfixOf "rejecting: ghc-2.0.0 (constraint from non-reinstallable package requires installed instance)") ] , testGroup "reject-unconstrained" From e0d283ba0b849da448177498447a689f7f498972 Mon Sep 17 00:00:00 2001 From: Kristen Kozak Date: Wed, 26 Jul 2023 10:10:47 -0700 Subject: [PATCH 2/2] Remove special case for running solver with no targets The TODO deleted in 4d3f7b5ee70fdbcaacf1ee021672752a86f2de89 suggests that the special case was only needed for the top-down solver, which has been removed. --- cabal-install/src/Distribution/Client/Dependency.hs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cabal-install/src/Distribution/Client/Dependency.hs b/cabal-install/src/Distribution/Client/Dependency.hs index f5a0d3a9b9f..749ae0df6d6 100644 --- a/cabal-install/src/Distribution/Client/Dependency.hs +++ b/cabal-install/src/Distribution/Client/Dependency.hs @@ -777,12 +777,6 @@ resolveDependencies -> Solver -> DepResolverParams -> Progress String String SolverInstallPlan --- TODO: is this needed here? see dontInstallNonReinstallablePackages -resolveDependencies platform comp _pkgConfigDB _solver params - | Set.null (depResolverTargets params) = - return (validateSolverResult platform comp indGoals []) - where - indGoals = depResolverIndependentGoals params resolveDependencies platform comp pkgConfigDB solver params = Step (showDepResolverParams finalparams) $ fmap (validateSolverResult platform comp indGoals) $