summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/main/DynFlags.hs16
-rw-r--r--compiler/main/HscMain.hs5
-rw-r--r--compiler/main/HscTypes.hs2
3 files changed, 18 insertions, 5 deletions
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index b574ba9080..3fb3874c63 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -74,7 +74,8 @@ module DynFlags (
-- ** Safe Haskell
SafeHaskellMode(..),
- safeHaskellOn, safeImportsOn, safeLanguageOn, safeInferOn,
+ safeHaskellOn, safeHaskellModeEnabled,
+ safeImportsOn, safeLanguageOn, safeInferOn,
packageTrustOn,
safeDirectImpsReq, safeImplicitImpsReq,
unsafeFlags, unsafeFlagsForInfer,
@@ -844,6 +845,7 @@ data SafeHaskellMode
| Sf_Unsafe
| Sf_Trustworthy
| Sf_Safe
+ | Sf_Ignore
deriving (Eq)
instance Show SafeHaskellMode where
@@ -851,6 +853,7 @@ instance Show SafeHaskellMode where
show Sf_Unsafe = "Unsafe"
show Sf_Trustworthy = "Trustworthy"
show Sf_Safe = "Safe"
+ show Sf_Ignore = "Ignore"
instance Outputable SafeHaskellMode where
ppr = text . show
@@ -2391,7 +2394,12 @@ packageTrustOn = gopt Opt_PackageTrust
-- | Is Safe Haskell on in some way (including inference mode)
safeHaskellOn :: DynFlags -> Bool
-safeHaskellOn dflags = safeHaskell dflags /= Sf_None || safeInferOn dflags
+safeHaskellOn dflags = safeHaskellModeEnabled dflags || safeInferOn dflags
+
+safeHaskellModeEnabled :: DynFlags -> Bool
+safeHaskellModeEnabled dflags = safeHaskell dflags `elem` [Sf_Unsafe, Sf_Trustworthy
+ , Sf_Safe ]
+
-- | Is the Safe Haskell safe language in use
safeLanguageOn :: DynFlags -> Bool
@@ -2440,6 +2448,7 @@ safeImplicitImpsReq d = safeLanguageOn d
combineSafeFlags :: SafeHaskellMode -> SafeHaskellMode -> DynP SafeHaskellMode
combineSafeFlags a b | a == Sf_None = return b
| b == Sf_None = return a
+ | a == Sf_Ignore || b == Sf_Ignore = return Sf_Ignore
| a == b = return a
| otherwise = addErr errm >> pure a
where errm = "Incompatible Safe Haskell flags! ("
@@ -2776,7 +2785,7 @@ safeFlagCheck cmdl dflags =
-- dynflags and warn for when -fpackage-trust by itself with no safe
-- haskell flag
(dflags', warn)
- | safeHaskell dflags == Sf_None && not cmdl && packageTrustOn dflags
+ | not (safeHaskellModeEnabled dflags) && not cmdl && packageTrustOn dflags
= (gopt_unset dflags Opt_PackageTrust, pkgWarnMsg)
| otherwise = (dflags, [])
@@ -3643,6 +3652,7 @@ dynamic_flags_deps = [
, make_ord_flag defFlag "fpackage-trust" (NoArg setPackageTrust)
, make_ord_flag defFlag "fno-safe-infer" (noArg (\d ->
d { safeInfer = False }))
+ , make_ord_flag defFlag "fno-safe-haskell" (NoArg (setSafeHaskell Sf_Ignore))
, make_ord_flag defGhcFlag "fPIC" (NoArg (setGeneralFlag Opt_PIC))
, make_ord_flag defGhcFlag "fno-PIC" (NoArg (unSetGeneralFlag Opt_PIC))
, make_ord_flag defGhcFlag "fPIE" (NoArg (setGeneralFlag Opt_PIC))
diff --git a/compiler/main/HscMain.hs b/compiler/main/HscMain.hs
index 5102fa09ba..9b9edf7d21 100644
--- a/compiler/main/HscMain.hs
+++ b/compiler/main/HscMain.hs
@@ -1002,7 +1002,7 @@ checkSafeImports tcg_env
pkgTrustReqs :: DynFlags -> Set InstalledUnitId -> Set InstalledUnitId ->
Bool -> ImportAvails
pkgTrustReqs dflags req inf infPassed | safeInferOn dflags
- && safeHaskell dflags == Sf_None && infPassed
+ && not (safeHaskellModeEnabled dflags) && infPassed
= emptyImportAvails {
imp_trust_pkgs = req `S.union` inf
}
@@ -1095,6 +1095,7 @@ hscCheckSafe' m l = do
-- otherwise we check the package trust flag.
packageTrusted :: DynFlags -> SafeHaskellMode -> Bool -> Module -> Bool
packageTrusted _ Sf_None _ _ = False -- shouldn't hit these cases
+ packageTrusted _ Sf_Ignore _ _ = False -- shouldn't hit these cases
packageTrusted _ Sf_Unsafe _ _ = False -- prefer for completeness.
packageTrusted dflags _ _ _
| not (packageTrustOn dflags) = True
@@ -1163,7 +1164,7 @@ markUnsafeInfer tcg_env whyUnsafe = do
-- NOTE: Only wipe trust when not in an explicitly safe haskell mode. Other
-- times inference may be on but we are in Trustworthy mode -- so we want
-- to record safe-inference failed but not wipe the trust dependencies.
- case safeHaskell dflags == Sf_None of
+ case not (safeHaskellModeEnabled dflags) of
True -> return $ tcg_env { tcg_imports = wiped_trust }
False -> return tcg_env
diff --git a/compiler/main/HscTypes.hs b/compiler/main/HscTypes.hs
index d57d69bda6..d0cf7e0dd8 100644
--- a/compiler/main/HscTypes.hs
+++ b/compiler/main/HscTypes.hs
@@ -2920,6 +2920,7 @@ trustInfoToNum it
Sf_Unsafe -> 1
Sf_Trustworthy -> 2
Sf_Safe -> 3
+ Sf_Ignore -> 0
numToTrustInfo :: Word8 -> IfaceTrustInfo
numToTrustInfo 0 = setSafeMode Sf_None
@@ -2933,6 +2934,7 @@ numToTrustInfo n = error $ "numToTrustInfo: bad input number! (" ++ show n ++ ")
instance Outputable IfaceTrustInfo where
ppr (TrustInfo Sf_None) = text "none"
+ ppr (TrustInfo Sf_Ignore) = text "none"
ppr (TrustInfo Sf_Unsafe) = text "unsafe"
ppr (TrustInfo Sf_Trustworthy) = text "trustworthy"
ppr (TrustInfo Sf_Safe) = text "safe"