Commit 86ee74dc authored by Alp Mestanogullari's avatar Alp Mestanogullari 🦑

compareByPreference: handle the integer-gmp vs -simple case

Currently, it assumes the package names are identical and this
breaks in the case where integer-gmp is in one package db and
integer-simple in another. This became a problem with
the commit: fc2ff6dd.

Instead of following the precedence information, leading to
the right choice, the current code would compare the
integer-gmp and integer-simple versions and pick integer-gmp
because it happened to have a greater version, despite having
a lower precedence. See for
a comprehensive report about the problem.

This effectively un-breaks integer-simple builds with hadrian.

Test Plan: hadrian/ --integer-simple

Reviewers: snowleopard, bgamari

Reviewed By: bgamari

Subscribers: snowleopard, rwbarton, carter

Differential Revision:
parent d30352ad
......@@ -891,15 +891,28 @@ sortByPreference prec_map = sortBy (flip (compareByPreference prec_map))
-- Pursuant to #12518, we could change this policy to, for example, remove
-- the version preference, meaning that we would always prefer the packages
-- in alter package database.
-- in later package database.
-- Instead, we use that preference based policy only when one of the packages
-- is integer-gmp and the other is integer-simple.
-- This currently only happens when we're looking up which concrete
-- package to use in place of @integer-wired-in@ and that two different
-- package databases supply a different integer library. For more about
-- the fake @integer-wired-in@ package, see Note [The integer library]
-- in the @PrelNames@ module.
:: PackagePrecedenceIndex
-> PackageConfig
-> PackageConfig
-> Ordering
compareByPreference prec_map pkg pkg' =
case comparing packageVersion pkg pkg' of
compareByPreference prec_map pkg pkg'
| Just prec <- Map.lookup (unitId pkg) prec_map
, Just prec' <- Map.lookup (unitId pkg') prec_map
, differentIntegerPkgs pkg pkg'
= compare prec prec'
| otherwise
= case comparing packageVersion pkg pkg' of
GT -> GT
EQ | Just prec <- Map.lookup (unitId pkg) prec_map
, Just prec' <- Map.lookup (unitId pkg') prec_map
......@@ -910,6 +923,12 @@ compareByPreference prec_map pkg pkg' =
-> EQ
LT -> LT
where isIntegerPkg p = packageNameString p `elem`
["integer-simple", "integer-gmp"]
differentIntegerPkgs p p' =
isIntegerPkg p && isIntegerPkg p' &&
(packageName p /= packageName p')
comparing :: Ord a => (t -> a) -> t -> t -> Ordering
comparing f a b = f a `compare` f b
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment