diff options
| author | David Terei <davidterei@gmail.com> | 2011-04-25 12:14:21 -0700 |
|---|---|---|
| committer | David Terei <davidterei@gmail.com> | 2011-06-17 18:19:48 -0700 |
| commit | 6de1b0f2f4fe0455df72adb7b43449586b40ba89 (patch) | |
| tree | f8ef6e2b5348103132fbe0a1d419947b0cc90792 /compiler/iface | |
| parent | f8279ea9fef8c16782a3cd5bc81cf90de3e46cb5 (diff) | |
| download | haskell-6de1b0f2f4fe0455df72adb7b43449586b40ba89.tar.gz | |
SafeHaskell: Add safe import flag (not functional)
Diffstat (limited to 'compiler/iface')
| -rw-r--r-- | compiler/iface/BinIface.hs | 8 | ||||
| -rw-r--r-- | compiler/iface/LoadIface.lhs | 14 | ||||
| -rw-r--r-- | compiler/iface/MkIface.lhs | 28 |
3 files changed, 33 insertions, 17 deletions
diff --git a/compiler/iface/BinIface.hs b/compiler/iface/BinIface.hs index 211417debb..904d5a6877 100644 --- a/compiler/iface/BinIface.hs +++ b/compiler/iface/BinIface.hs @@ -511,12 +511,14 @@ instance Binary Usage where putByte bh 0 put_ bh (usg_mod usg) put_ bh (usg_mod_hash usg) + put_ bh (usg_safe usg) put_ bh usg@UsageHomeModule{} = do putByte bh 1 put_ bh (usg_mod_name usg) put_ bh (usg_mod_hash usg) put_ bh (usg_exports usg) put_ bh (usg_entities usg) + put_ bh (usg_safe usg) get bh = do h <- getByte bh @@ -524,14 +526,16 @@ instance Binary Usage where 0 -> do nm <- get bh mod <- get bh - return UsagePackageModule { usg_mod = nm, usg_mod_hash = mod } + safe <- get bh + return UsagePackageModule { usg_mod = nm, usg_mod_hash = mod, usg_safe = safe } _ -> do nm <- get bh mod <- get bh exps <- get bh ents <- get bh + safe <- get bh return UsageHomeModule { usg_mod_name = nm, usg_mod_hash = mod, - usg_exports = exps, usg_entities = ents } + usg_exports = exps, usg_entities = ents, usg_safe = safe } instance Binary Warnings where put_ bh NoWarnings = putByte bh 0 diff --git a/compiler/iface/LoadIface.lhs b/compiler/iface/LoadIface.lhs index ccaaf6928a..219ab6a917 100644 --- a/compiler/iface/LoadIface.lhs +++ b/compiler/iface/LoadIface.lhs @@ -697,16 +697,22 @@ pprExport (mod, items) pprUsage :: Usage -> SDoc pprUsage usage@UsagePackageModule{} - = hsep [ptext (sLit "import"), ppr (usg_mod usage), - ppr (usg_mod_hash usage)] + = pprUsageImport usage usg_mod pprUsage usage@UsageHomeModule{} - = hsep [ptext (sLit "import"), ppr (usg_mod_name usage), - ppr (usg_mod_hash usage)] $$ + = pprUsageImport usage usg_mod_name $$ nest 2 ( maybe empty (\v -> text "exports: " <> ppr v) (usg_exports usage) $$ vcat [ ppr n <+> ppr v | (n,v) <- usg_entities usage ] ) +pprUsageImport :: Outputable a => Usage -> (Usage -> a) -> SDoc +pprUsageImport usage usg_mod' + = hsep [ptext (sLit "import"), safe, ppr (usg_mod' usage), + ppr (usg_mod_hash usage)] + where + safe | usg_safe usage = ptext $ sLit "safe" + | otherwise = ptext $ sLit " -/ " + pprDeps :: Dependencies -> SDoc pprDeps (Deps { dep_mods = mods, dep_pkgs = pkgs, dep_orphs = orphs, dep_finsts = finsts }) diff --git a/compiler/iface/MkIface.lhs b/compiler/iface/MkIface.lhs index 9deceb53b9..6ff91919c9 100644 --- a/compiler/iface/MkIface.lhs +++ b/compiler/iface/MkIface.lhs @@ -873,7 +873,8 @@ mk_usage_info pit hsc_env this_mod direct_imports used_names | modulePackageId mod /= this_pkg = Just UsagePackageModule{ usg_mod = mod, - usg_mod_hash = mod_hash } + usg_mod_hash = mod_hash, + usg_safe = imp_safe } -- for package modules, we record the module hash only | (null used_occs @@ -888,22 +889,27 @@ mk_usage_info pit hsc_env this_mod direct_imports used_names | otherwise = Just UsageHomeModule { usg_mod_name = moduleName mod, - usg_mod_hash = mod_hash, - usg_exports = export_hash, - usg_entities = Map.toList ent_hashs } + usg_mod_hash = mod_hash, + usg_exports = export_hash, + usg_entities = Map.toList ent_hashs, + usg_safe = imp_safe } where - maybe_iface = lookupIfaceByModule dflags hpt pit mod - -- In one-shot mode, the interfaces for home-package - -- modules accumulate in the PIT not HPT. Sigh. - - is_direct_import = mod `elemModuleEnv` direct_imports + maybe_iface = lookupIfaceByModule dflags hpt pit mod + -- In one-shot mode, the interfaces for home-package + -- modules accumulate in the PIT not HPT. Sigh. Just iface = maybe_iface finsts_mod = mi_finsts iface hash_env = mi_hash_fn iface mod_hash = mi_mod_hash iface export_hash | depend_on_exports = Just (mi_exp_hash iface) - | otherwise = Nothing + | otherwise = Nothing + + (is_direct_import, imp_safe) + = case lookupModuleEnv direct_imports mod of + Just ((_,_,_,safe):xs) -> (True, safe) + Just _ -> pprPanic "mkUsage: empty direct import" empty + Nothing -> (False, False) used_occs = lookupModuleEnv ent_map mod `orElse` [] @@ -1158,7 +1164,7 @@ checkDependencies hsc_env summary iface orM = foldr f (return False) where f m rest = do b <- m; if b then return True else rest - dep_missing (L _ (ImportDecl (L _ mod) pkg _ _ _ _)) = do + dep_missing (L _ (ImportDecl (L _ mod) pkg _ _ _ _ _)) = do find_res <- liftIO $ findImportedModule hsc_env mod pkg case find_res of Found _ mod |
