summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2021-06-21 16:00:40 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-06-25 15:41:58 -0400
commit6cc8076684db27e9bb3e320421e844a7cbcb2545 (patch)
treea7c0585e9e235bcc4f63c4b8a19520ffd21fc011
parent0bb78838e213467b9b5bd2b38767b39b46a294c5 (diff)
downloadhaskell-6cc8076684db27e9bb3e320421e844a7cbcb2545.tar.gz
driver: Add implicit package dependencies for template-haskell package
When TemplateHaskellQuotes is enabled, we also generate programs which mention symbols from the template-haskell module. So that package is added conditionally if the extension is turned on. We should really do the same for other wired-in packages: * base * ghc-bignum * ghc-prim * rts When we link an executable, we must also link against these libraries. In accordance with every other package, these dependencies should be added into the direct dependencies for a module automatically and end up in the interface file to record the fact the object file was created by linking against these packages. Unfortunately it is not so easy to work out when symbols from each of these libraries ends up in the generated program. You might think that `base` would always be used but the `ghc-prim` package doesn't depend on `base`, so you have to be a bit careful and this futher enhancement is left to a future patch.
-rw-r--r--compiler/GHC/Iface/Recomp.hs5
-rw-r--r--compiler/GHC/Rename/Names.hs7
-rw-r--r--compiler/GHC/Unit/State.hs13
3 files changed, 21 insertions, 4 deletions
diff --git a/compiler/GHC/Iface/Recomp.hs b/compiler/GHC/Iface/Recomp.hs
index 9bfbe218d6..fc53b91d68 100644
--- a/compiler/GHC/Iface/Recomp.hs
+++ b/compiler/GHC/Iface/Recomp.hs
@@ -74,6 +74,7 @@ import Data.Either
import qualified Data.Semigroup
import GHC.List (uncons)
import Data.Ord
+import Data.Containers.ListUtils
{-
-----------------------------------------------
@@ -461,7 +462,7 @@ checkDependencies hsc_env summary iface
let (hs, ps) = partitionEithers es
res1 <- liftIO $ check_mods (sort hs) prev_dep_mods
- let allPkgDeps = sortBy (comparing snd) (ps ++ bkpk_units)
+ let allPkgDeps = sortBy (comparing snd) $ nubOrdOn snd (ps ++ implicit_deps ++ bkpk_units)
res2 <- liftIO $ check_packages allPkgDeps prev_dep_pkgs
return (res1 `mappend` res2)
where
@@ -475,6 +476,8 @@ checkDependencies hsc_env summary iface
bkpk_units = map (("Signature",) . indefUnit . instUnitInstanceOf . moduleUnit) (requirementMerges units (moduleName (mi_module iface)))
+ implicit_deps = map ("Implicit",) (implicitPackageDeps dflags)
+
classify _ (Found _ mod)
| isHomeUnit home_unit (moduleUnit mod) = Right (Left (moduleName mod))
diff --git a/compiler/GHC/Rename/Names.hs b/compiler/GHC/Rename/Names.hs
index 7fbbb7167e..4a8e80dca2 100644
--- a/compiler/GHC/Rename/Names.hs
+++ b/compiler/GHC/Rename/Names.hs
@@ -94,6 +94,7 @@ import qualified Data.Set as S
import System.FilePath ((</>))
import System.IO
+import GHC.Unit.State
{-
************************************************************************
@@ -200,7 +201,11 @@ rnImports imports = do
-- Safe Haskell: See Note [Tracking Trust Transitively]
let (decls, rdr_env, imp_avails, hpc_usage) = combine (stuff1 ++ stuff2)
-- Update imp_boot_mods if imp_direct_mods mentions any of them
- let final_import_avail = clobberSourceImports imp_avails
+ let merged_import_avail = clobberSourceImports imp_avails
+ dflags <- getDynFlags
+ let final_import_avail =
+ merged_import_avail { imp_dep_direct_pkgs = S.fromList (implicitPackageDeps dflags)
+ `S.union` imp_dep_direct_pkgs merged_import_avail}
return (decls, rdr_env, final_import_avail, hpc_usage)
where
diff --git a/compiler/GHC/Unit/State.hs b/compiler/GHC/Unit/State.hs
index f3fb9d7645..32e35161b2 100644
--- a/compiler/GHC/Unit/State.hs
+++ b/compiler/GHC/Unit/State.hs
@@ -65,8 +65,8 @@ module GHC.Unit.State (
pprWithUnitState,
-- * Utils
- unwireUnit
- )
+ unwireUnit,
+ implicitPackageDeps)
where
import GHC.Prelude
@@ -113,6 +113,7 @@ import qualified Data.Semigroup as Semigroup
import qualified Data.Map as Map
import qualified Data.Map.Strict as MapStrict
import qualified Data.Set as Set
+import GHC.LanguageExtensions
-- ---------------------------------------------------------------------------
-- The Unit state
@@ -2153,3 +2154,11 @@ pprWithUnitState :: UnitState -> SDoc -> SDoc
pprWithUnitState state = updSDocContext (\ctx -> ctx
{ sdocUnitIdForUser = \fs -> pprUnitIdForUser state (UnitId fs)
})
+
+-- | Add package dependencies on the wired-in packages we use
+implicitPackageDeps :: DynFlags -> [UnitId]
+implicitPackageDeps dflags
+ = [thUnitId | xopt TemplateHaskellQuotes dflags]
+ -- TODO: Should also include `base` and `ghc-prim` if we use those implicitly, but
+ -- it is possible to not depend on base (for example, see `ghc-prim`)
+