diff options
author | Joachim Breitner <mail@joachim-breitner.de> | 2018-10-03 15:36:55 +0200 |
---|---|---|
committer | Krzysztof Gogolewski <krz.gogolewski@gmail.com> | 2018-10-03 15:40:22 +0200 |
commit | fc2ff6dd7496a33bf68165b28f37f40b7d647418 (patch) | |
tree | 4cb624e2a8046da6c0bdcb3c6acf0aa1dfd4fa5e /compiler/main/Packages.hs | |
parent | 3dedffa2a51952b05c22b2d08668155ac07d7320 (diff) | |
download | haskell-fc2ff6dd7496a33bf68165b28f37f40b7d647418.tar.gz |
Make GHC (the library) flexible in the choice of integer library
Summary:
We have more and more users of GHC as a library, for example the
Haskell-to-WebAssembly-compiler https://github.com/tweag/asterius.
These need to make different decisions about various aspects of
code generation than the host compiler, and ideally GHC-the-library
allows them to set the `DynFlags` as needed.
This patch adds a new `DynFlag` that configures which `integer`
library to use. This flag is initialized by `cIntegerLibraryType`
(as before), and is only used in `CorePrep` to decide whether to
use `S#` or not.
The other code paths that were varying based on `cIntegerLibraryType`
are no now longer varying: The trick is to use `integer-wired-in`
as the `-this-unit-id` when compiling either `integer-gmp` or
`integer-simple`.
Test Plan: Validate is happy.
Reviewers: hvr, bgamari
Reviewed By: bgamari
Subscribers: TerrorJack, adamse, simonpj, rwbarton, carter
GHC Trac Issues: #13477
Differential Revision: https://phabricator.haskell.org/D5079
Diffstat (limited to 'compiler/main/Packages.hs')
-rw-r--r-- | compiler/main/Packages.hs | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/compiler/main/Packages.hs b/compiler/main/Packages.hs index 04efa1fe51..fadcd31f1e 100644 --- a/compiler/main/Packages.hs +++ b/compiler/main/Packages.hs @@ -953,12 +953,15 @@ pprTrustFlag flag = case flag of -- ----------------------------------------------------------------------------- -- Wired-in packages +-- +-- See Note [Wired-in packages] in Module -wired_in_pkgids :: [String] -wired_in_pkgids = map unitIdString wiredInUnitIds - +type WiredInUnitId = String type WiredPackagesMap = Map WiredUnitId WiredUnitId +wired_in_pkgids :: [WiredInUnitId] +wired_in_pkgids = map unitIdString wiredInUnitIds + findWiredInPackages :: DynFlags -> PackagePrecedenceIndex @@ -969,12 +972,15 @@ findWiredInPackages WiredPackagesMap) -- map from unit id to wired identity findWiredInPackages dflags prec_map pkgs vis_map = do - -- -- Now we must find our wired-in packages, and rename them to - -- their canonical names (eg. base-1.0 ==> base). - -- + -- their canonical names (eg. base-1.0 ==> base), as described + -- in Note [Wired-in packages] in Module let - matches :: PackageConfig -> String -> Bool + matches :: PackageConfig -> WiredInUnitId -> Bool + pc `matches` pid + -- See Note [The integer library] in PrelNames + | pid == unitIdString integerUnitId + = packageNameString pc `elem` ["integer-gmp", "integer-simple"] pc `matches` pid = packageNameString pc == pid -- find which package corresponds to each wired-in package @@ -994,8 +1000,8 @@ findWiredInPackages dflags prec_map pkgs vis_map = do -- this works even when there is no exposed wired in package -- available. -- - findWiredInPackage :: [PackageConfig] -> String - -> IO (Maybe PackageConfig) + findWiredInPackage :: [PackageConfig] -> WiredInUnitId + -> IO (Maybe (WiredInUnitId, PackageConfig)) findWiredInPackage pkgs wired_pkg = let all_ps = [ p | p <- pkgs, p `matches` wired_pkg ] all_exposed_ps = @@ -1014,20 +1020,19 @@ findWiredInPackages dflags prec_map pkgs vis_map = do <> text " not found." return Nothing pick :: PackageConfig - -> IO (Maybe PackageConfig) + -> IO (Maybe (WiredInUnitId, PackageConfig)) pick pkg = do debugTraceMsg dflags 2 $ text "wired-in package " <> text wired_pkg <> text " mapped to " <> ppr (unitId pkg) - return (Just pkg) + return (Just (wired_pkg, pkg)) mb_wired_in_pkgs <- mapM (findWiredInPackage pkgs) wired_in_pkgids let wired_in_pkgs = catMaybes mb_wired_in_pkgs - wired_in_ids = mapMaybe definitePackageConfigId wired_in_pkgs -- this is old: we used to assume that if there were -- multiple versions of wired-in packages installed that @@ -1043,18 +1048,17 @@ findWiredInPackages dflags prec_map pkgs vis_map = do -} wiredInMap :: Map WiredUnitId WiredUnitId - wiredInMap = foldl' add_mapping Map.empty pkgs - where add_mapping m pkg - | Just key <- definitePackageConfigId pkg - , key `elem` wired_in_ids - = Map.insert key (DefUnitId (stringToInstalledUnitId (packageNameString pkg))) m - | otherwise = m + wiredInMap = Map.fromList + [ (key, DefUnitId (stringToInstalledUnitId wiredInUnitId)) + | (wiredInUnitId, pkg) <- wired_in_pkgs + , Just key <- pure $ definitePackageConfigId pkg + ] updateWiredInDependencies pkgs = map (upd_deps . upd_pkg) pkgs where upd_pkg pkg | Just def_uid <- definitePackageConfigId pkg - , def_uid `elem` wired_in_ids - = let PackageName fs = packageName pkg + , Just wiredInUnitId <- Map.lookup def_uid wiredInMap + = let fs = installedUnitIdFS (unDefUnitId wiredInUnitId) in pkg { unitId = fsToInstalledUnitId fs, componentId = ComponentId fs @@ -1074,7 +1078,9 @@ findWiredInPackages dflags prec_map pkgs vis_map = do -- Helper functions for rewiring Module and UnitId. These -- rewrite UnitIds of modules in wired-in packages to the form known to the --- compiler. For instance, base-4.9.0.0 will be rewritten to just base, to match +-- compiler, as described in Note [Wired-in packages] in Module. +-- +-- For instance, base-4.9.0.0 will be rewritten to just base, to match -- what appears in PrelNames. upd_wired_in_mod :: WiredPackagesMap -> Module -> Module |