Commit 998739df authored by Edward Z. Yang's avatar Edward Z. Yang

Refactor package flags into several distinct types.

Summary:
Previously, all package flags (-package, -trust-package,
-ignore-package) were bundled up into a single packageFlags
field in DynFlags, under a single type.  This commit separates
them based on what they do.

This is a nice improvement, because it means that Packages can
then be refactored so that a number of functions are "tighter":

    - We know longer have to partition PackageFlags into
      the ignore flag and other flags; ignore flags are just
      put into their own field.

    - Trust flags modify the package database, but exposed
      flags do not (they modify the visibility map); now
      applyPackageFlag and applyTrustFlag have tighter signatures
      which reflect this.

This patch was motivated by the need to have a separate visibility
map for plugin packages, which will be in a companion patch.
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>

Test Plan: validate

Reviewers: austin, bgamari, duncan

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1659
parent 21b25dff
......@@ -45,6 +45,7 @@ module DynFlags (
GhcMode(..), isOneShot,
GhcLink(..), isNoLink,
PackageFlag(..), PackageArg(..), ModRenaming(..),
IgnorePackageFlag(..), TrustFlag(..),
PkgConfRef(..),
Option(..), showOpt,
DynLibLoader(..),
......@@ -691,8 +692,12 @@ data DynFlags = DynFlags {
-- ^ The @-package-db@ flags given on the command line, in the order
-- they appeared.
ignorePackageFlags :: [IgnorePackageFlag],
-- ^ The @-ignore-package@ flags from the command line
packageFlags :: [PackageFlag],
-- ^ The @-package@ and @-hide-package@ flags from the command-line
trustFlags :: [TrustFlag],
-- ^ The @-trust@ and @-distrust@ flags
packageEnv :: Maybe FilePath,
-- ^ Filepath to the package environment file (if overriding default)
......@@ -1088,13 +1093,16 @@ data ModRenaming = ModRenaming {
} deriving (Eq)
-- | Flags for manipulating packages.
newtype IgnorePackageFlag = IgnorePackage String -- ^ @-ignore-package@
data TrustFlag
= TrustPackage String -- ^ @-trust@
| DistrustPackage String -- ^ @-distrust@
data PackageFlag
= ExposePackage PackageArg ModRenaming -- ^ @-package@, @-package-id@
-- and @-package-key@
| HidePackage String -- ^ @-hide-package@
| IgnorePackage String -- ^ @-ignore-package@
| TrustPackage String -- ^ @-trust-package@
| DistrustPackage String -- ^ @-distrust-package@
deriving (Eq)
defaultHscTarget :: Platform -> HscTarget
......@@ -1424,6 +1432,8 @@ defaultDynFlags mySettings =
extraPkgConfs = id,
packageFlags = [],
ignorePackageFlags = [],
trustFlags = [],
packageEnv = Nothing,
pkgDatabase = Nothing,
-- This gets filled in with GHC.setSessionDynFlags
......@@ -3778,11 +3788,12 @@ exposeUnitId p =
hidePackage p =
upd (\s -> s{ packageFlags = HidePackage p : packageFlags s })
ignorePackage p =
upd (\s -> s{ packageFlags = IgnorePackage p : packageFlags s })
upd (\s -> s{ ignorePackageFlags = IgnorePackage p : ignorePackageFlags s })
trustPackage p = exposePackage p >> -- both trust and distrust also expose a package
upd (\s -> s{ packageFlags = TrustPackage p : packageFlags s })
upd (\s -> s{ trustFlags = TrustPackage p : trustFlags s })
distrustPackage p = exposePackage p >>
upd (\s -> s{ packageFlags = DistrustPackage p : packageFlags s })
upd (\s -> s{ trustFlags = DistrustPackage p : trustFlags s })
exposePackage' :: String -> DynFlags -> DynFlags
exposePackage' p dflags
......
This diff is collapsed.
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