Skip to content

Commit

Permalink
compareByPreference: handle the integer-gmp vs -simple case
Browse files Browse the repository at this point in the history
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: fc2ff6d.

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
snowleopard/hadrian#702 for
a comprehensive report about the problem.

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

Test Plan: hadrian/build.sh --integer-simple

Reviewers: snowleopard, bgamari

Reviewed By: bgamari

Subscribers: snowleopard, rwbarton, carter

Differential Revision: https://phabricator.haskell.org/D5266
  • Loading branch information
alpmestan committed Nov 12, 2018
1 parent d30352a commit 86ee74d
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions compiler/main/Packages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
compareByPreference
:: 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
Expand All @@ -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

Expand Down

0 comments on commit 86ee74d

Please sign in to comment.