cabal-install: guard the base >= 4.22 constraint on wired-in unit ids - #12301
cabal-install: guard the base >= 4.22 constraint on wired-in unit ids#12301andreabedini wants to merge 1 commit into
base >= 4.22 constraint on wired-in unit ids#12301Conversation
09922d4 to
7adbb91
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes an unsound solver constraint interaction in cabal-install when --allow-boot-library-installs is enabled on compilers that do not report wired-in unit ids. It ensures the base >= 4.22 constraint introduced for reinstallable base is only applied when the corresponding wired-in unit-id pinning constraints are also in effect, and adds a regression test.
Changes:
- Guard the
base >= 4.22constraint independOnWiredInsonisJust (compilerInfoWiredInUnitIds compiler)so it is only applied when wired-in unit-id constraints are available. - Add a unit test covering the “GHC without wiredInUnitIds + allow-boot-library-installs + old base” scenario and asserting the plan is solvable.
- Add a changelog entry documenting the fix and its motivation.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
cabal-install/src/Distribution/Client/Dependency.hs |
Guards the base >= 4.22 constraint so it’s only added when wired-in unit-id constraints are present. |
cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs |
Adds a regression test ensuring old base plans remain solvable when no wired-in unit ids are reported. |
changelog.d/base-422-wired-in-guard.md |
Documents the solver fix and why the guard is necessary. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
7adbb91 to
21b4724
Compare
Those are not QA notes. QA notes are meant to add a human perspective in testing, challenging the assumption of the contributor. “Testsuite goes red without the patch” is good and expected, but not useful for QA. |
@ffaf1 Apologies, removed. PS: To be honest, CONTRIBUTING.md does not make very clear what the are meant to be. |
|
Could you also try to edit the PR description and commit message. Right now they are quite verbose and it's difficult for me to get the signal from the noise. Also it would be helpful to create an issue. |
This is backward, we fix a bug where using We have two cases: cabal/cabal-install/src/Distribution/Client/Dependency.hs Lines 919 to 921 in 5969ad6 Case 1: Case 2: The issue is that Therefore, someone using GHC 9.12.2 with I will rewrite the description. @TeofilC Do you want me to open an issue? |
Indeed it's < rather than >=.
Yes please. It's always helpful to have issues for history |
21b4724 to
b3b8da7
Compare
b3b8da7 to
e9d409a
Compare
| (PackageConstraint (ScopeAnyQualifier $ mkPackageName "base") (PackagePropertyVersion (orLaterVersion (mkVersion [4, 22])))) | ||
| ConstraintSourceNonReinstallablePackage | ||
| | isJust (compilerInfoWiredInUnitIds compiler) |
There was a problem hiding this comment.
The indentation change makes the diff look larger than it is but the indentation glitch is due to fourmolu. Remove the | isJust ... line and fourmolu decides it wants more indentation 🤷.
There was a problem hiding this comment.
I see dependOnWiredIns has two calls to compilerInfoWiredInUnitIds compiler. This could a single wiredInUnitIds binding.
$ git diff
diff --git a/cabal-install/src/Distribution/Client/Dependency.hs b/cabal-install/src/Distribution/Client/Dependency.hs
index 3e5da48be..dde549d6c 100644
--- a/cabal-install/src/Distribution/Client/Dependency.hs
+++ b/cabal-install/src/Distribution/Client/Dependency.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE ViewPatterns #-}
+
-----------------------------------------------------------------------------
-- |
@@ -445,13 +447,14 @@ setSolverVerbosity verbosity params =
}
dependOnWiredIns :: CompilerInfo -> DepResolverParams -> DepResolverParams
-dependOnWiredIns compiler params = addConstraints extraConstraints params
+dependOnWiredIns (compilerInfoWiredInUnitIds -> wiredInUnitIds) params =
+ addConstraints extraConstraints params
where
extraConstraints =
[ LabeledPackageConstraint
(PackageConstraint (ScopeAnyQualifier pkgName) (PackagePropertyInstalledSpecificUnitId unitId))
ConstraintSourceNonReinstallablePackage
- | (pkgName, unitId) <- fromMaybe [] $ compilerInfoWiredInUnitIds compiler
+ | (pkgName, unitId) <- fromMaybe [] wiredInUnitIds
]
++
-- Old versions of `base` must be excluded from build plans still as they do not depend on any version of a wired-in unit.
@@ -460,7 +463,7 @@ dependOnWiredIns compiler params = addConstraints extraConstraints params
[ LabeledPackageConstraint
(PackageConstraint (ScopeAnyQualifier $ mkPackageName "base") (PackagePropertyVersion (orLaterVersion (mkVersion [4, 22]))))
ConstraintSourceNonReinstallablePackage
- | isJust (compilerInfoWiredInUnitIds compiler)
+ | isJust wiredInUnitIds
]
-- | Some packages are specific to a given compiler version and should never beThere was a problem hiding this comment.
Or use a case statement over compilerInfoWiredInUnitIds compiler and only do anything in the Just case?
There was a problem hiding this comment.
Went with the case statement. It also drops the second compilerInfoWiredInUnitIds call, so it covers @philderbeast's point too. Behaviour is unchanged: with Nothing the function was already adding no constraints at all.
`dependOnWiredIns` adds two kinds of constraint: one installed-unit-id constraint per wired-in unit of the compiler, and one `base >= 4.22` version constraint. The second only makes sense next to the first. The unit-id constraints pin the new, reinstallable `base`; the version constraint then excludes the old, non-reinstallable one. But it was added unconditionally, while the unit-id constraints are empty for a compiler that reports no wired-in units. Such a compiler has no installed `base` satisfying the bound, so plans that reach this code fail, and `--allow-boot-library-installs` alone is enough to reach it. Fixes haskell#12328.
e9d409a to
3ff1bf0
Compare
Fixes #12328.
dependOnWiredInsadds two kinds of constraint: one installed-unit-idconstraint per wired-in unit of the compiler, and one
base >= 4.22versionconstraint added in #12055.
The second only makes sense next to the first. The unit-id constraints pin the
new, reinstallable
base; the version constraint then excludes the old,non-reinstallable one. But it is added unconditionally, while the unit-id
constraints are empty for a compiler that reports no wired-in units. Such a
compiler is affected because
--allow-boot-library-installsalone is enough toreach this code.
This makes
dependOnWiredInsa no-op for a compiler that reports no wired-inunit ids, so the version constraint applies only where the unit-id constraints
do. Behaviour is unchanged for a compiler that reports wired-in unit ids.
Test
UnitTests.Distribution.Solver.Modular.Solvergets one test in the group"Non-reinstallable base, template-haskell and ghc (GHC without wiredInUnitIds)".
It uses the existing
dbBaseOlddatabase, which holdsbase-1alone, enables--allow-boot-library-installsand expects a successful plan. Without the fixthe test fails.
QA notes
The script in #12328 exits non-zero on an unpatched
cabal. Against this branchit succeeds with GHC 9.10.3, 9.12.2 and 9.14.1.
Checklist
Template A: This PR modifies behaviour or interface