[Git][ghc/ghc][master] driver: Check transitive closure of haskell package dependencies when deciding whether to relink
Marge Bot (@marge-bot)
gitlab at gitlab.haskell.org
Tue Sep 5 18:03:36 UTC 2023
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
291d81ae by Matthew Pickering at 2023-09-05T14:03:10-04:00
driver: Check transitive closure of haskell package dependencies when deciding whether to relink
We were previously just checking whether direct package dependencies had
been modified. This caused issues when compiling without optimisations
as we wouldn't relink the direct dependency if one of its dependenices
changed.
Fixes #23724
- - - - -
17 changed files:
- compiler/GHC/Driver/Pipeline.hs
- + testsuite/tests/driver/t23724/LICENSE
- + testsuite/tests/driver/t23724/Makefile
- + testsuite/tests/driver/t23724/README.md
- + testsuite/tests/driver/t23724/Setup.hs
- + testsuite/tests/driver/t23724/all.T
- + testsuite/tests/driver/t23724/cabal.project
- + testsuite/tests/driver/t23724/packageA/Setup.hs
- + testsuite/tests/driver/t23724/packageA/packageA.cabal
- + testsuite/tests/driver/t23724/packageA/src/LibA.hs
- + testsuite/tests/driver/t23724/packageA/src/LibA1.hs
- + testsuite/tests/driver/t23724/packageA/src/LibA2.hs
- + testsuite/tests/driver/t23724/packageB/Setup.hs
- + testsuite/tests/driver/t23724/packageB/app/Main.hs
- + testsuite/tests/driver/t23724/packageB/packageB.cabal
- + testsuite/tests/driver/t23724/packageB/src/LibB.hs
- + testsuite/tests/driver/t23724/recompPkgLink.stdout
Changes:
=====================================
compiler/GHC/Driver/Pipeline.hs
=====================================
@@ -129,6 +129,7 @@ import qualified Data.Set as Set
import Data.Time ( getCurrentTime )
import GHC.Iface.Recomp
+import GHC.Types.Unique.DSet
-- Simpler type synonym for actions in the pipeline monad
type P m = TPipelineClass TPhase m
@@ -497,8 +498,18 @@ linkingNeeded logger dflags unit_env staticLink linkables pkg_deps = do
-- next, check libraries. XXX this only checks Haskell libraries,
-- not extra_libraries or -l things from the command line.
+ -- pkg_deps is just the direct dependencies so take the transitive closure here
+ -- to decide if we need to relink or not.
+ let pkg_hslibs acc uid
+ | uid `elementOfUniqDSet` acc = acc
+ | Just c <- lookupUnitId unit_state uid =
+ foldl' @[] pkg_hslibs (addOneToUniqDSet acc uid) (unitDepends c)
+ | otherwise = acc
+
+ all_pkg_deps = foldl' @[] pkg_hslibs emptyUniqDSet pkg_deps
+
let pkg_hslibs = [ (collectLibraryDirs (ways dflags) [c], lib)
- | Just c <- map (lookupUnitId unit_state) pkg_deps,
+ | Just c <- map (lookupUnitId unit_state) (uniqDSetToList all_pkg_deps),
lib <- unitHsLibs (ghcNameVersion dflags) (ways dflags) c ]
pkg_libfiles <- mapM (uncurry (findHSLib platform (ways dflags))) pkg_hslibs
=====================================
testsuite/tests/driver/t23724/LICENSE
=====================================
@@ -0,0 +1,30 @@
+Copyright Mike Pilgrem (c) 2023
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of Mike Pilgrem nor the names of other
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
=====================================
testsuite/tests/driver/t23724/Makefile
=====================================
@@ -0,0 +1,32 @@
+TOP=../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+SETUP='$(PWD)/Setup' -v0
+CONFIGURE=$(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --ghc-options='$(filter-out -rtsopts,$(TEST_HC_OPTS))' --package-db='$(PWD)/tmp.d' --prefix='$(PWD)/inst' $(VANILLA) $(PROF) $(DYN) --disable-optimisation
+
+recompPkgLink:
+ '$(GHC_PKG)' init tmp.d
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 --make Setup
+ # build libA
+ cp packageA/src/LibA1.hs packageA/src/LibA.hs
+ rm -rf packageA/dist
+ (cd packageA; $(CONFIGURE) --ipid "p-0.1")
+ (cd packageA; $(SETUP) build)
+ (cd packageA; $(SETUP) copy)
+ (cd packageA; $(SETUP) register)
+ # build libB
+ rm -rf packageB/dist
+ (cd packageB; $(CONFIGURE) --ipid "q-0.1")
+ (cd packageB; $(SETUP) build)
+ (cd packageB; $(SETUP) copy)
+ (cd packageB; $(SETUP) register)
+ ./inst/bin/progB
+ cp packageA/src/LibA2.hs packageA/src/LibA.hs
+ (cd packageA; $(SETUP) build)
+ (cd packageA; $(SETUP) copy)
+ (cd packageA; $(SETUP) register)
+ (cd packageB; $(SETUP) build)
+ (cd packageB; $(SETUP) copy)
+ (cd packageB; $(SETUP) register)
+ ./inst/bin/progB
=====================================
testsuite/tests/driver/t23724/README.md
=====================================
@@ -0,0 +1,4 @@
+# ghc-recomp-test
+
+A simple test of the effect of GHC's recompilation checker. See
+https://downloads.haskell.org/~ghc/9.4.5/docs/users_guide/separate_compilation.html#the-recompilation-checker.
=====================================
testsuite/tests/driver/t23724/Setup.hs
=====================================
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
=====================================
testsuite/tests/driver/t23724/all.T
=====================================
@@ -0,0 +1,20 @@
+if config.have_vanilla:
+ vanilla = '--enable-library-vanilla'
+else:
+ vanilla = '--disable-library-vanilla'
+
+if config.have_profiling:
+ prof = '--enable-library-profiling'
+else:
+ prof = '--disable-library-profiling'
+
+if not config.compiler_profiled and config.have_dynamic:
+ dyn = '--enable-shared'
+else:
+ dyn = '--disable-shared'
+
+test('recompPkgLink', [extra_files(['packageA', 'packageB', 'Setup.hs']),
+ when(fast(), skip),
+ js_broken(22349)],
+ run_command,
+ ['$MAKE -s --no-print-directory recompPkgLink VANILLA=' + vanilla + ' PROF=' + prof + ' DYN=' + dyn])
=====================================
testsuite/tests/driver/t23724/cabal.project
=====================================
@@ -0,0 +1,3 @@
+packages: packageA, packageB
+
+optimization: 0
=====================================
testsuite/tests/driver/t23724/packageA/Setup.hs
=====================================
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
=====================================
testsuite/tests/driver/t23724/packageA/packageA.cabal
=====================================
@@ -0,0 +1,10 @@
+cabal-version: 1.12
+name: packageA
+version: 0.1.0.0
+build-type: Simple
+
+library
+ exposed-modules: LibA
+ hs-source-dirs: src
+ build-depends: base >=4.7 && <5
+ default-language: Haskell2010
=====================================
testsuite/tests/driver/t23724/packageA/src/LibA.hs
=====================================
@@ -0,0 +1,4 @@
+module LibA where
+
+message :: IO ()
+message = putStrLn "Message #14"
=====================================
testsuite/tests/driver/t23724/packageA/src/LibA1.hs
=====================================
@@ -0,0 +1,4 @@
+module LibA where
+
+message :: IO ()
+message = putStrLn "Message #13"
=====================================
testsuite/tests/driver/t23724/packageA/src/LibA2.hs
=====================================
@@ -0,0 +1,4 @@
+module LibA where
+
+message :: IO ()
+message = putStrLn "Message #14"
=====================================
testsuite/tests/driver/t23724/packageB/Setup.hs
=====================================
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
=====================================
testsuite/tests/driver/t23724/packageB/app/Main.hs
=====================================
@@ -0,0 +1,6 @@
+module Main where
+
+import LibB
+
+main :: IO ()
+main = message
=====================================
testsuite/tests/driver/t23724/packageB/packageB.cabal
=====================================
@@ -0,0 +1,20 @@
+cabal-version: 1.12
+name: packageB
+version: 0.1.0.0
+build-type: Simple
+
+library
+ exposed-modules: LibB
+ hs-source-dirs: src
+ build-depends:
+ base >=4.7 && <5
+ , packageA
+ default-language: Haskell2010
+
+executable progB
+ main-is: Main.hs
+ hs-source-dirs: app
+ build-depends:
+ base >=4.7 && <5
+ , packageB
+ default-language: Haskell2010
=====================================
testsuite/tests/driver/t23724/packageB/src/LibB.hs
=====================================
@@ -0,0 +1,3 @@
+module LibB (message) where
+
+import LibA
=====================================
testsuite/tests/driver/t23724/recompPkgLink.stdout
=====================================
@@ -0,0 +1,2 @@
+Message #13
+Message #14
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/291d81aef8083290da0d2ce430fbc5e5a33bdb6e
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/291d81aef8083290da0d2ce430fbc5e5a33bdb6e
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230905/2a33e477/attachment-0001.html>
More information about the ghc-commits
mailing list