summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Bolingbroke <batterseapower@hotmail.com>2011-06-30 10:55:28 +0100
committerMax Bolingbroke <batterseapower@hotmail.com>2011-06-30 10:55:28 +0100
commite49dae36a00b2af8f6ad583dd24f9bacf5711242 (patch)
tree907ea95e662f6090310aea44c4b05cddc045eb3c
parentfe7eac515ae2d072aec4b4e7a576841b27540114 (diff)
downloadhaskell-e49dae36a00b2af8f6ad583dd24f9bacf5711242.tar.gz
Restore home-package-plugin functionality
-rw-r--r--compiler/main/DriverPipeline.hs4
-rw-r--r--compiler/main/DynFlags.hs6
-rw-r--r--compiler/main/GHC.hs2
-rw-r--r--compiler/main/GhcMake.hs6
-rw-r--r--compiler/main/HscTypes.lhs42
-rw-r--r--compiler/typecheck/TcRnDriver.lhs10
6 files changed, 49 insertions, 21 deletions
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index 112dac0439..aa987d7327 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -934,8 +934,8 @@ runPhase (Hsc src_flavour) input_fn dflags0
ms_location = location4,
ms_hs_date = src_timestamp,
ms_obj_date = Nothing,
- ms_imps = imps,
- ms_srcimps = src_imps }
+ ms_textual_imps = imps,
+ ms_srcimps = src_imps }
-- run the compiler!
result <- io $ hscCompileOneShot hsc_env'
diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 9f53666d78..144d6d1fbe 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -30,7 +30,7 @@ module DynFlags (
DynLibLoader(..),
fFlags, fLangFlags, xFlags,
DPHBackend(..), dphPackageMaybe,
- wayNames,
+ wayNames, dynFlagDependencies,
-- ** Safe Haskell
SafeHaskellMode(..),
@@ -980,6 +980,10 @@ setLanguage l = upd f
extensionFlags = flattenExtensionFlags mLang oneoffs
}
+-- | Some modules have dependencies on others through the DynFlags rather than textual imports
+dynFlagDependencies :: DynFlags -> [ModuleName]
+dynFlagDependencies = pluginModNames
+
-- | Is the Safe Haskell safe language in use
safeLanguageOn :: DynFlags -> Bool
safeLanguageOn dflags = s == Sf_SafeLanguage
diff --git a/compiler/main/GHC.hs b/compiler/main/GHC.hs
index c8ca482784..8f5c894ac2 100644
--- a/compiler/main/GHC.hs
+++ b/compiler/main/GHC.hs
@@ -816,7 +816,7 @@ compileCoreToObj simplify cm@(CoreModule{ cm_module = mName }) = do
ms_obj_date = Nothing,
-- Only handling the single-module case for now, so no imports.
ms_srcimps = [],
- ms_imps = [],
+ ms_textual_imps = [],
-- No source file
ms_hspp_file = "",
ms_hspp_opts = dflags,
diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs
index 8ccf0a5a81..5dcea1b139 100644
--- a/compiler/main/GhcMake.hs
+++ b/compiler/main/GhcMake.hs
@@ -1254,7 +1254,7 @@ summariseFile hsc_env old_summaries file mb_phase obj_allowed maybe_buf
ms_hspp_file = hspp_fn,
ms_hspp_opts = dflags',
ms_hspp_buf = Just buf,
- ms_srcimps = srcimps, ms_imps = the_imps,
+ ms_srcimps = srcimps, ms_textual_imps = the_imps,
ms_hs_date = src_timestamp,
ms_obj_date = obj_timestamp })
@@ -1379,8 +1379,8 @@ summariseModule hsc_env old_summary_map is_boot (L loc wanted_mod)
ms_hspp_file = hspp_fn,
ms_hspp_opts = dflags',
ms_hspp_buf = Just buf,
- ms_srcimps = srcimps,
- ms_imps = the_imps,
+ ms_srcimps = srcimps,
+ ms_textual_imps = the_imps,
ms_hs_date = src_timestamp,
ms_obj_date = obj_timestamp }))
diff --git a/compiler/main/HscTypes.lhs b/compiler/main/HscTypes.lhs
index bc3d02654e..7f43414111 100644
--- a/compiler/main/HscTypes.lhs
+++ b/compiler/main/HscTypes.lhs
@@ -17,7 +17,7 @@ module HscTypes (
ModGuts(..), CgGuts(..), ForeignStubs(..), appendStubC,
ImportedMods, ImportedModsVal,
- ModSummary(..), ms_mod_name, showModMsg, isBootSummary,
+ ModSummary(..), ms_imps, ms_mod_name, showModMsg, isBootSummary,
msHsFilePath, msHiFilePath, msObjFilePath,
-- * Information about the module being compiled
@@ -131,7 +131,7 @@ import DataCon ( DataCon, dataConImplicitIds, dataConWrapId )
import PrelNames ( gHC_PRIM )
import Packages hiding ( Version(..) )
import DynFlags ( DynFlags(..), isOneShot, HscTarget (..), dopt,
- DynFlag(..), SafeHaskellMode(..) )
+ DynFlag(..), SafeHaskellMode(..), dynFlagDependencies )
import DriverPhases ( HscSource(..), isHsBoot, hscSourceString, Phase )
import BasicTypes ( IPName, defaultFixity, WarningTxt(..) )
import OptimizationFuel ( OptFuelState )
@@ -1656,22 +1656,38 @@ emptyMG = []
-- * An external-core source module
data ModSummary
= ModSummary {
- ms_mod :: Module, -- ^ Identity of the module
- ms_hsc_src :: HscSource, -- ^ The module source either plain Haskell, hs-boot or external core
- ms_location :: ModLocation, -- ^ Location of the various files belonging to the module
- ms_hs_date :: ClockTime, -- ^ Timestamp of source file
- ms_obj_date :: Maybe ClockTime, -- ^ Timestamp of object, if we have one
- ms_srcimps :: [Located (ImportDecl RdrName)], -- ^ Source imports of the module
- ms_imps :: [Located (ImportDecl RdrName)], -- ^ Non-source imports of the module
- ms_hspp_file :: FilePath, -- ^ Filename of preprocessed source file
- ms_hspp_opts :: DynFlags, -- ^ Cached flags from @OPTIONS@, @INCLUDE@
+ ms_mod :: Module, -- ^ Identity of the module
+ ms_hsc_src :: HscSource, -- ^ The module source either plain Haskell, hs-boot or external core
+ ms_location :: ModLocation, -- ^ Location of the various files belonging to the module
+ ms_hs_date :: ClockTime, -- ^ Timestamp of source file
+ ms_obj_date :: Maybe ClockTime, -- ^ Timestamp of object, if we have one
+ ms_srcimps :: [Located (ImportDecl RdrName)], -- ^ Source imports of the module
+ ms_textual_imps :: [Located (ImportDecl RdrName)], -- ^ Non-source imports of the module from the module *text*
+ ms_hspp_file :: FilePath, -- ^ Filename of preprocessed source file
+ ms_hspp_opts :: DynFlags, -- ^ Cached flags from @OPTIONS@, @INCLUDE@
-- and @LANGUAGE@ pragmas in the modules source code
- ms_hspp_buf :: Maybe StringBuffer -- ^ The actual preprocessed source, if we have it
+ ms_hspp_buf :: Maybe StringBuffer -- ^ The actual preprocessed source, if we have it
}
ms_mod_name :: ModSummary -> ModuleName
ms_mod_name = moduleName . ms_mod
+ms_imps :: ModSummary -> [Located (ImportDecl RdrName)]
+ms_imps ms = ms_textual_imps ms ++ map mk_additional_import (dynFlagDependencies (ms_hspp_opts ms))
+ where
+ -- This is a not-entirely-satisfactory means of creating an import that corresponds to an
+ -- import that did not occur in the program text, such as those induced by the use of
+ -- plugins (the -plgFoo flag)
+ mk_additional_import mod_nm = noLoc $ ImportDecl {
+ ideclName = noLoc mod_nm,
+ ideclPkgQual = Nothing,
+ ideclSource = False,
+ ideclQualified = False,
+ ideclAs = Nothing,
+ ideclHiding = Nothing,
+ ideclSafe = False
+ }
+
-- The ModLocation contains both the original source filename and the
-- filename of the cleaned-up source file after all preprocessing has been
-- done. The point is that the summariser will have to cpp/unlit/whatever
@@ -1697,7 +1713,7 @@ instance Outputable ModSummary where
nest 3 (sep [text "ms_hs_date = " <> text (show (ms_hs_date ms)),
text "ms_mod =" <+> ppr (ms_mod ms)
<> text (hscSourceString (ms_hsc_src ms)) <> comma,
- text "ms_imps =" <+> ppr (ms_imps ms),
+ text "ms_textual_imps =" <+> ppr (ms_textual_imps ms),
text "ms_srcimps =" <+> ppr (ms_srcimps ms)]),
char '}'
]
diff --git a/compiler/typecheck/TcRnDriver.lhs b/compiler/typecheck/TcRnDriver.lhs
index 1faa8e6366..1c289f1574 100644
--- a/compiler/typecheck/TcRnDriver.lhs
+++ b/compiler/typecheck/TcRnDriver.lhs
@@ -204,7 +204,15 @@ tcRnImports hsc_env this_mod import_decls
= do { (rn_imports, rdr_env, imports,hpc_info) <- rnImports import_decls ;
; let { dep_mods :: ModuleNameEnv (ModuleName, IsBootInterface)
- ; dep_mods = imp_dep_mods imports
+ -- Make sure we record the dependencies from the DynFlags in the EPS or we
+ -- end up hitting the sanity check in LoadIface.loadInterface that
+ -- checks for unknown home-package modules being loaded. We put
+ -- these dependencies on the left so their (non-source) imports
+ -- take precedence over the (possibly-source) imports on the right.
+ -- We don't add them to any other field (e.g. the imp_dep_mods of
+ -- imports) because we don't want to load their instances etc.
+ ; dep_mods = listToUFM [(mod_nm, (mod_nm, False)) | mod_nm <- dynFlagDependencies (hsc_dflags hsc_env)]
+ `plusUFM` imp_dep_mods imports
-- We want instance declarations from all home-package
-- modules below this one, including boot modules, except