Commit e0eaea91 authored by Edward Z. Yang's avatar Edward Z. Yang

Correctly account for -package-db ordering when picking packages.

When I originally implemented ABI-based shadowing as per
ee4e1654, I switched our strategy
from pasting together lists to creating a map of all units first,
and then selecting packages from this.  However, what I did
not realize when doing this was that we actually depended
on the *ordering* of these lists later, when we selected
a preferred package to use.

The crux is if I have -package-db db1 -package-db db2 -package p-0.1,
and p-0.1 is provided by both db1 and db2, which one does the
-package flag select?  Previously, this was undetermined; now
we always select the instance from the LATEST package database.
(If p-0.1 shows up multiple times in the same database, once again
the chosen package is undefined.)

The reason why cabal08 intermittently failed was that, in practice,
we were sorting on the UnitId, so when we bumped version numbers,
that often wibbled the UnitIds so that they compared oppositely.
I've extended the test so that we check that the relation is

Fixes #13313Signed-off-by: default avatarEdward Z. Yang <>

Test Plan: validate

Reviewers: bgamari, austin

Subscribers: rwbarton, thomie

Differential Revision:
parent 40b65db4
This diff is collapsed.
......@@ -11,19 +11,23 @@ cabal08: clean
'$(GHC_PKG)' init tmp2.d
'$(TEST_HC)' -v0 --make Setup
cd p1 && $(SETUP) clean
cd p1 && $(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)' --package-db=../tmp1.d --prefix='$(PWD)/inst-p1'
cd p1 && $(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)' --package-db=../tmp1.d --prefix='$(PWD)/inst-p1' --ipid="p-0.1-aaa"
cd p1 && $(SETUP) build
cd p1 && $(SETUP) copy
cd p1 && $(SETUP) register
cd p2 && $(SETUP) clean
cd p2 && $(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)' --package-db=../tmp2.d --prefix='$(PWD)/inst-p2'
cd p2 && $(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)' --package-db=../tmp2.d --prefix='$(PWD)/inst-p2' --ipid="p-0.1-bbb"
cd p2 && $(SETUP) build
cd p2 && $(SETUP) copy
cd p2 && $(SETUP) register
'$(TEST_HC)' $(TEST_HC_OPTS) -package-db tmp1.d -package-db tmp2.d Main.hs
'$(TEST_HC)' $(TEST_HC_OPTS) -fforce-recomp -package-db tmp2.d -package-db tmp1.d Main.hs
'$(TEST_HC)' $(TEST_HC_OPTS) -fforce-recomp -package-db tmp1.d -package-db tmp2.d -hide-all-packages -package base -package p Main.hs
'$(TEST_HC)' $(TEST_HC_OPTS) -fforce-recomp -package-db tmp2.d -package-db tmp1.d -hide-all-packages -package base -package p Main.hs
ifneq "$(CLEANUP)" ""
$(MAKE) -s --no-print-directory clean
......@@ -4,7 +4,6 @@ else:
cleanup = 'CLEANUP=0'
[extra_files(['Main.hs', 'Setup.hs', 'p1/', 'p2/']),
extra_files(['Main.hs', 'Setup.hs', 'p1/', 'p2/']),
['$MAKE -s --no-print-directory cabal08 ' + cleanup])
......@@ -3,4 +3,10 @@ Linking Main ...
[1 of 1] Compiling Main ( Main.hs, Main.o )
Linking Main ...
[1 of 1] Compiling Main ( Main.hs, Main.o )
Linking Main ...
[1 of 1] Compiling Main ( Main.hs, Main.o )
Linking Main ...
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