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

Support for abi-depends for computing shadowing.

Summary:
This is a complete fix based off of
ed7af26606b3a605a4511065ca1a43b1c0f3b51d for handling
shadowing and out-of-order -package-db flags simultaneously.

The general strategy is we first put all databases together,
overriding packages as necessary.  Once this is done, we successfully
prune out broken packages, including packages which depend on a package
whose ABI differs from the ABI we need.

Our check gracefully degrades in the absence of abi-depends, as
we only check deps which are recorded in abi-depends.

Contains time and Cabal submodule update.
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>

Test Plan: validate

Reviewers: niteria, austin, bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2846

GHC Trac Issues: #12485
parent 21892398
......@@ -302,6 +302,7 @@ buildUnit session cid insts lunit = do
$ deps ++ [ moduleUnitId mod
| (_, mod) <- insts
, not (isHoleModule mod) ],
abiDepends = [],
ldOptions = case session of
TcSession -> []
_ -> obj_files,
......
......@@ -55,7 +55,7 @@ Library
process >= 1 && < 1.5,
bytestring >= 0.9 && < 0.11,
binary == 0.8.*,
time >= 1.4 && < 1.7,
time >= 1.4 && < 1.8,
containers >= 0.5 && < 0.6,
array >= 0.1 && < 0.6,
filepath >= 1 && < 1.5,
......
This diff is collapsed.
......@@ -52,7 +52,7 @@ Executable ghc
deepseq == 1.4.*,
ghci == @ProjectVersionMunged@,
haskeline == 0.7.*,
time == 1.6.*,
time == 1.7.*,
transformers == 0.5.*
CPP-Options: -DGHCI
GHC-Options: -fno-warn-name-shadowing
......
Subproject commit 034b44191740214c9e691439b604a8ac95ee9946
Subproject commit 09865f60caa55a7b02880f2a779c9dd8e1be5ac0
......@@ -66,7 +66,8 @@ import System.Directory
-- | This is a subset of Cabal's 'InstalledPackageInfo', with just the bits
-- that GHC is interested in.
-- that GHC is interested in. See Cabal's documentation for a more detailed
-- description of all of the fields.
--
data InstalledPackageInfo compid srcpkgid srcpkgname instunitid unitid modulename mod
= InstalledPackageInfo {
......@@ -78,6 +79,9 @@ data InstalledPackageInfo compid srcpkgid srcpkgname instunitid unitid modulenam
packageVersion :: Version,
abiHash :: String,
depends :: [instunitid],
-- | Like 'depends', but each dependency is annotated with the
-- ABI hash we expect the dependency to respect.
abiDepends :: [(instunitid, String)],
importDirs :: [FilePath],
hsLibraries :: [String],
extraLibraries :: [String],
......@@ -159,6 +163,7 @@ emptyInstalledPackageInfo =
packageVersion = Version [] [],
abiHash = "",
depends = [],
abiDepends = [],
importDirs = [],
hsLibraries = [],
extraLibraries = [],
......@@ -307,7 +312,7 @@ instance (RepInstalledPackageInfo a b c d e f g) =>
put (InstalledPackageInfo
unitId componentId instantiatedWith sourcePackageId
packageName packageVersion
abiHash depends importDirs
abiHash depends abiDepends importDirs
hsLibraries extraLibraries extraGHCiLibraries
libraryDirs libraryDynDirs
frameworks frameworkDirs
......@@ -325,6 +330,7 @@ instance (RepInstalledPackageInfo a b c d e f g) =>
instantiatedWith)
put abiHash
put (map toStringRep depends)
put (map (\(k,v) -> (toStringRep k, v)) abiDepends)
put importDirs
put hsLibraries
put extraLibraries
......@@ -355,6 +361,7 @@ instance (RepInstalledPackageInfo a b c d e f g) =>
instantiatedWith <- get
abiHash <- get
depends <- get
abiDepends <- get
importDirs <- get
hsLibraries <- get
extraLibraries <- get
......@@ -383,6 +390,7 @@ instance (RepInstalledPackageInfo a b c d e f g) =>
(fromStringRep packageName) packageVersion
abiHash
(map fromStringRep depends)
(map (\(k,v) -> (fromStringRep k, v)) abiDepends)
importDirs
hsLibraries extraLibraries extraGHCiLibraries
libraryDirs libraryDynDirs
......
Subproject commit 8625c1c0550719437acad89d49401cf048990084
Subproject commit 92673292ab7ce7878e982d0a02df3e548ef15b52
Subproject commit 52e0f5e85ffbaab77b155d48720fb216021c8a73
Subproject commit b6098be8a4facfa854c633f2a3a82ab8e72962ef
......@@ -88,6 +88,7 @@ extra_src_files = {
'T12035j': ['T12035.hs', 'T12035a.hs', 'T12035.hs-boot'],
'T12042': ['T12042.hs', 'T12042a.hs', 'T12042.hs-boot'],
'T12485': ['a.pkg', 'b.pkg', 'Main.hs'],
'T12485a': ['shadow1.pkg', 'shadow2.pkg', 'shadow3.pkg'],
'T12733': ['p/', 'q/', 'Setup.hs'],
'T1372': ['p1/', 'p2/'],
'T1407': ['A.c'],
......
......@@ -136,12 +136,14 @@ LOCAL_GHC_PKGSHADOW13 = '$(GHC_PKG)' --no-user-package-db -f $(PKGCONFSHADOW1) -
# Test package shadowing behaviour.
#
# localshadow1.package.conf: shadowdep-1-XXX <- shadow-1-XXX
# localshadow2.package.conf: shadow-1-XXX
# The general principle is that we shadow in order of declarations,
# but we determine what gets overridden based on ABI dependencies.
#
# If the ABI hash of boths shadow-1s are the same, we'll just accept
# the later shadow version. However, if the ABIs are different, we
# should complain!
# Here is the structure of our databases (unitid=abi):
#
# localshadow1.package.conf: shadowdep-1-XXX=ddd -> shadow-1-XXX=aaa
# localshadow2.package.conf: shadow-1-XXX=bbb
# localshadow3.package.conf: shadow-1-XXX=aaa
shadow:
rm -rf $(PKGCONFSHADOW1) $(PKGCONFSHADOW2) $(PKGCONFSHADOW3) shadow.hs shadow.o shadow.hi shadow.out shadow.hs shadow.hi
$(LOCAL_GHC_PKGSHADOW1) init $(PKGCONFSHADOW1)
......@@ -164,8 +166,8 @@ shadow:
if '$(TEST_HC)' $(TEST_HC_OPTS) -package-db $(PKGCONFSHADOW1) -package-db $(PKGCONFSHADOW2) -package shadowdep -c shadow.hs -fno-code; then false; else true; fi
#
# Reversing the orders of the configs fixes the problem, because now
# the shadow-1-XXX defined in the same DB as shadowdep shadows
# shadow-1-XXX in localshadow2.package.conf
# we prefer the shadow-1 from the first database, which has the correct
# ABI hash for shadowdep-1.
#
@echo "should SUCCEED:"
'$(TEST_HC)' $(TEST_HC_OPTS) -package-db $(PKGCONFSHADOW2) -package-db $(PKGCONFSHADOW1) -package shadowdep -c shadow.hs -fno-code
......@@ -175,6 +177,31 @@ shadow:
@echo "should SUCCEED:"
'$(TEST_HC)' $(TEST_HC_OPTS) -package-db $(PKGCONFSHADOW3) -package-db $(PKGCONFSHADOW1) -package shadowdep -c shadow.hs -fno-code
# Test that order we pass databases doesn't matter
#
# 1. shadow-1-XXX=aaa
# 2. shadowdep-1-XXX=ddd (shadow-1-XXX=aaa)
# 3. shadow-1-XXX=bbb
.PHONY: T12485a
T12485a:
rm -rf T12485a.package.conf T12485b.package.conf T12485c.package.conf
'$(GHC_PKG)' --no-user-package-db init T12485a.package.conf
'$(GHC_PKG)' --no-user-package-db init T12485b.package.conf
'$(GHC_PKG)' --no-user-package-db init T12485c.package.conf
'$(GHC_PKG)' --no-user-package-db -f T12485a.package.conf register -v0 --force shadow1.pkg
'$(GHC_PKG)' --no-user-package-db -f T12485b.package.conf register -v0 --force shadow2.pkg
'$(GHC_PKG)' --no-user-package-db -f T12485c.package.conf register -v0 --force shadow3.pkg
echo "main = return ()" > T12485a.hs
# Normal test
@echo "should SUCCEED"
'$(TEST_HC)' $(TEST_HC_OPTS) -package-db T12485a.package.conf -package-db T12485b.package.conf -package shadowdep -c T12485a.hs -fno-code
# Reversed test
@echo "should SUCCEED"
'$(TEST_HC)' $(TEST_HC_OPTS) -package-db T12485b.package.conf -package-db T12485a.package.conf -package shadowdep -c T12485a.hs -fno-code
# Shadow OK, as long as correct one is chosen eventually, even when reversed
@echo "should SUCCEED"
'$(TEST_HC)' $(TEST_HC_OPTS) -package-db T12485b.package.conf -package-db T12485c.package.conf -package-db T12485a.package.conf -package shadowdep -c T12485a.hs -fno-code
# If we pass --global, we should ignore instances in the user database
T5442a:
@rm -rf package.conf.T5442a.global package.conf.T5442a.user
......
......@@ -9,6 +9,6 @@ T12485 :
'$(GHC_PKG)' init b.db
'$(GHC_PKG)' -f a.db/ -f b.db/ register b.pkg # register b.pkg in b.db
# -package-db in dependency order
'$(TEST_HC)' -XNoImplicitPrelude -fforce-recomp -hide-all-packages -no-user-package-db -package-db a.db -package-db b.db -package-id a-1-XXX -package-id b-1-XXX Main.hs
'$(TEST_HC)' $(TEST_HC_OPTS) -XNoImplicitPrelude -fforce-recomp -hide-all-packages -no-user-package-db -package-db a.db -package-db b.db -package-id a-1-XXX -package-id b-1-XXX Main.hs
# -package-db in reverse dependency order
'$(TEST_HC)' -XNoImplicitPrelude -fforce-recomp -hide-all-packages -no-user-package-db -package-db b.db -package-db a.db -package-id a-1-XXX -package-id b-1-XXX Main.hs
'$(TEST_HC)' $(TEST_HC_OPTS) -XNoImplicitPrelude -fforce-recomp -hide-all-packages -no-user-package-db -package-db b.db -package-db a.db -package-id a-1-XXX -package-id b-1-XXX Main.hs
test('T12485',
[extra_clean(['a.db', 'b.db', 'Main.o', 'Main', 'Main.hi']),
expect_broken(12485)],
[extra_clean(['a.db', 'b.db', 'Main.o', 'Main', 'Main.hi'])],
run_command,
['$MAKE -s --no-print-directory T12485'])
should SUCCEED
should SUCCEED
should SUCCEED
WARNING: there are broken packages. Run 'ghc-pkg check' for more details.
<command line>: cannot satisfy -package T1750A:
T1750A-1-XXX is unusable due to missing or recursive dependencies:
T1750A-1-XXX is unusable due to cyclic dependencies:
T1750B-1-XXX
(use -v for more information)
......@@ -101,3 +101,10 @@ test('shadow',
'local1shadow2.package.conf',
'local1shadow2.package.conf.old']),
run_command, ['$MAKE -s --no-print-directory shadow'])
test('T12485a',
extra_clean(['T12485a.hi', 'T1750.out',
'T12485a.package.conf',
'T12485b.package.conf',
'T12485c.package.conf']),
run_command, ['$MAKE -s --no-print-directory T12485a'])
......@@ -4,3 +4,4 @@ id: shadow-1-XXX
key: shadow-1-XXX
abi: aaa
depends:
abi-depends:
name: shadowdep
version: 1
abi: ddd
id: shadowdep-1-XXX
key: shadowdep-1-XXX
depends: shadow-1-XXX
abi-depends: shadow-1-XXX=aaa
......@@ -4,3 +4,4 @@ id: shadow-1-XXX
key: shadow-1-XXX
abi: bbb
depends:
abi-depends:
......@@ -52,7 +52,7 @@ test('haddock.base',
test('haddock.Cabal',
[unless(in_tree_compiler(), skip), req_haddock
,stats_num_field('bytes allocated',
[(wordsize(64), 23706190072, 5)
[(wordsize(64), 25478853176 , 5)
# 2012-08-14: 3255435248 (amd64/Linux)
# 2012-08-29: 3324606664 (amd64/Linux, new codegen)
# 2012-10-08: 3373401360 (amd64/Linux)
......@@ -91,6 +91,7 @@ test('haddock.Cabal',
# 2016-10-01: 20619433656 (amd64/Linux) - Cabal update
# 2016-10-03: 21554874976 (amd64/Linux) - Cabal update
# 2016-10-06: 23706190072 (amd64/Linux) - Cabal update
# 2016-12-20: 25478853176 (amd64/Linux) - Cabal update
,(platform('i386-unknown-mingw32'), 3293415576, 5)
# 2012-10-30: 1733638168 (x86/Windows)
......
......@@ -316,7 +316,7 @@ generate directory distdir dll0Modules config_args
do cwd <- getCurrentDirectory
let ipid = mkUnitId (display (packageId pd))
let installedPkgInfo = inplaceInstalledPackageInfo cwd distdir
pd (mkAbiHash "") lib lbi clbi
pd (mkAbiHash "inplace") lib lbi clbi
final_ipi = mangleIPI directory distdir lbi $ installedPkgInfo {
Installed.installedUnitId = ipid,
Installed.compatPackageKey = display (packageId pd),
......
......@@ -1107,6 +1107,7 @@ convertPackageInfoToCacheFormat pkg =
GhcPkg.packageName = packageName pkg,
GhcPkg.packageVersion = Version.Version (versionNumbers (packageVersion pkg)) [],
GhcPkg.depends = depends pkg,
GhcPkg.abiDepends = map (\(AbiDependency k v) -> (k,unAbiHash v)) (abiDepends pkg),
GhcPkg.abiHash = unAbiHash (abiHash pkg),
GhcPkg.importDirs = importDirs pkg,
GhcPkg.hsLibraries = hsLibraries pkg,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment