diff options
Diffstat (limited to 'compiler/main')
-rw-r--r-- | compiler/main/DynFlags.hs | 4 | ||||
-rw-r--r-- | compiler/main/Packages.hs | 48 |
2 files changed, 31 insertions, 21 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 7726001a47..f9ccc25225 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -850,6 +850,9 @@ data DynFlags = DynFlags { ghcLink :: GhcLink, hscTarget :: HscTarget, settings :: Settings, + integerLibrary :: IntegerLibrary, + -- ^ IntegerGMP or IntegerSimple. Set at configure time, but may be overriden + -- by GHC-API users. See Note [The integer library] in PrelNames llvmTargets :: LlvmTargets, llvmPasses :: LlvmPasses, verbosity :: Int, -- ^ Verbosity level: see Note [Verbosity levels] @@ -1755,6 +1758,7 @@ defaultDynFlags mySettings (myLlvmTargets, myLlvmPasses) = ghcMode = CompManager, ghcLink = LinkBinary, hscTarget = defaultHscTarget (sTargetPlatform mySettings), + integerLibrary = cIntegerLibraryType, verbosity = 0, optLevel = 0, debugLevel = 0, 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 |