Commit 06d46b1e authored by Edward Z. Yang's avatar Edward Z. Yang

Unify hsig and hs-boot; add preliminary "hs-boot" merging.

This patch drops the file level distinction between hs-boot and hsig;
we figure out which one we are compiling based on whether or not there
is a corresponding hs file lying around.

To make the "import A" syntax continue to work for bare hs-boot
files, we also introduce hs-boot merging, which takes an A.hi-boot
and converts it to an A.hi when there is no A.hs file in scope.
This will be generalized in Backpack to merge multiple A.hi files together;
which means we can jettison the "load multiple interface files" functionality.

This works automatically for --make, but for one-shot compilation
we need a new mode: ghc --merge-requirements A will generate an A.hi/A.o
from a local A.hi-boot file; Backpack will extend this mechanism further.

Has Haddock submodule update to deal with change in msHsFilePath behavior.

    - This commit drops support for the hsig extension. Can
      we support it?  It's annoying because the finder code is
      written with the assumption that where there's an hs-boot
      file, there's always an hs file too.  To support hsig, you'd
      have to probe two locations.  Easier to just not support it.

    - #10333 affects us, modifying an hs-boot still doesn't trigger
      recomp.

    - See compiler/main/Finder.hs: this diff is very skeevy, but
      it seems to work.

    - This code cunningly doesn't drop hs-boot files from the
      "drop hs-boot files" module graph, if they don't have a
      corresponding hs file.  I have no idea if this actually is useful.
Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>

Test Plan: validate

Reviewers: simonpj, austin, bgamari, spinda

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D1098
parent 09d214dc
......@@ -106,7 +106,7 @@ deSugar hsc_env
hpcInfo = emptyHpcInfo other_hpc_info
; (binds_cvr, ds_hpc_info, modBreaks)
<- if not (isHsBootOrSig hsc_src)
<- if not (isHsBoot hsc_src)
then addTicksToBinds dflags mod mod_loc export_set
(typeEnvTyCons type_env) binds
else return (binds, hpcInfo, emptyModBreaks)
......
......@@ -896,7 +896,7 @@ pprModIface iface
]
where
pp_hsc_src HsBootFile = ptext (sLit "[boot]")
pp_hsc_src HsigFile = ptext (sLit "[hsig]")
pp_hsc_src HsBootMerge = ptext (sLit "[merge]")
pp_hsc_src HsSrcFile = Outputable.empty
{-
......
......@@ -15,6 +15,7 @@ module MkIface (
-- including computing version information
mkIfaceTc,
mkIfaceDirect,
writeIfaceFile, -- Write the interface file
......@@ -160,6 +161,35 @@ mkIface hsc_env maybe_old_fingerprint mod_details
warns hpc_info dir_imp_mods self_trust dependent_files
safe_mode mod_details
-- | Make an interface from a manually constructed 'ModIface'. We use
-- this when we are merging 'ModIface's. We assume that the 'ModIface'
-- has accurate entries but not accurate fingerprint information (so,
-- like @intermediate_iface@ in 'mkIface_'.)
mkIfaceDirect :: HscEnv
-> Maybe Fingerprint
-> ModIface
-> IO (ModIface, Bool)
mkIfaceDirect hsc_env maybe_old_fingerprint iface0 = do
-- Sort some things to make sure we're deterministic
let intermediate_iface = iface0 {
mi_exports = mkIfaceExports (mi_exports iface0),
mi_insts = sortBy cmp_inst (mi_insts iface0),
mi_fam_insts = sortBy cmp_fam_inst (mi_fam_insts iface0),
mi_rules = sortBy cmp_rule (mi_rules iface0)
}
dflags = hsc_dflags hsc_env
(final_iface, no_change_at_all)
<- {-# SCC "versioninfo" #-}
addFingerprints hsc_env maybe_old_fingerprint
intermediate_iface
(map snd (mi_decls iface0))
-- Debug printing
dumpIfSet_dyn dflags Opt_D_dump_hi "FINAL INTERFACE"
(pprModIface final_iface)
return (final_iface, no_change_at_all)
-- | make an interface from the results of typechecking only. Useful
-- for non-optimising compilation, or where we aren't generating any
-- object code at all ('HscNothing').
......@@ -357,11 +387,6 @@ mkIface_ hsc_env maybe_old_fingerprint
return (errs_and_warns, Just (final_iface, no_change_at_all))
where
cmp_rule = comparing ifRuleName
-- Compare these lexicographically by OccName, *not* by unique,
-- because the latter is not stable across compilations:
cmp_inst = comparing (nameOccName . ifDFun)
cmp_fam_inst = comparing (nameOccName . ifFamInstTcName)
dflags = hsc_dflags hsc_env
......@@ -379,8 +404,6 @@ mkIface_ hsc_env maybe_old_fingerprint
deliberatelyOmitted :: String -> a
deliberatelyOmitted x = panic ("Deliberately omitted: " ++ x)
ifFamInstTcName = ifFamInstFam
flattenVectInfo (VectInfo { vectInfoVar = vVar
, vectInfoTyCon = vTyCon
, vectInfoParallelVars = vParallelVars
......@@ -394,6 +417,16 @@ mkIface_ hsc_env maybe_old_fingerprint
, ifaceVectInfoParallelTyCons = nameSetElems vParallelTyCons
}
cmp_rule :: IfaceRule -> IfaceRule -> Ordering
cmp_rule = comparing ifRuleName
-- Compare these lexicographically by OccName, *not* by unique,
-- because the latter is not stable across compilations:
cmp_inst :: IfaceClsInst -> IfaceClsInst -> Ordering
cmp_inst = comparing (nameOccName . ifDFun)
cmp_fam_inst :: IfaceFamInst -> IfaceFamInst -> Ordering
cmp_fam_inst = comparing (nameOccName . ifFamInstFam)
-----------------------------
writeIfaceFile :: DynFlags -> FilePath -> ModIface -> IO ()
writeIfaceFile dflags hi_file_path new_iface
......
......@@ -199,9 +199,9 @@ processDeps dflags _ _ _ _ (CyclicSCC nodes)
throwGhcExceptionIO (ProgramError (showSDoc dflags $ GHC.cyclicModuleErr nodes))
processDeps dflags hsc_env excl_mods root hdl (AcyclicSCC node)
| Just src_file <- msHsFilePath node
= do { let extra_suffixes = depSuffixes dflags
include_pkg_deps = depIncludePkgDeps dflags
src_file = msHsFilePath node
obj_file = msObjFilePath node
obj_files = insertSuffixes obj_file extra_suffixes
......@@ -236,6 +236,10 @@ processDeps dflags hsc_env excl_mods root hdl (AcyclicSCC node)
; do_imps False (ms_imps node)
}
| otherwise
= ASSERT( ms_hsc_src node == HsBootMerge )
panic "HsBootMerge not supported in DriverMkDepend yet"
findDependency :: HscEnv
-> SrcSpan
......
......@@ -10,7 +10,7 @@
-----------------------------------------------------------------------------
module DriverPhases (
HscSource(..), isHsBootOrSig, hscSourceString,
HscSource(..), isHsBoot, hscSourceString,
Phase(..),
happensBefore, eqPhase, anyHsc, isStopLn,
startPhase,
......@@ -22,12 +22,10 @@ module DriverPhases (
isCishSuffix,
isDynLibSuffix,
isHaskellUserSrcSuffix,
isHaskellSigSuffix,
isSourceSuffix,
isHaskellishFilename,
isHaskellSrcFilename,
isHaskellSigFilename,
isObjectFilename,
isCishFilename,
isDynLibFilename,
......@@ -60,63 +58,51 @@ import Binary
-- Note [HscSource types]
-- ~~~~~~~~~~~~~~~~~~~~~~
-- There are three types of source file for Haskell code:
-- There are two types of source file for user-written Haskell code:
--
-- * HsSrcFile is an ordinary hs file which contains code,
--
-- * HsBootFile is an hs-boot file, which is used to break
-- recursive module imports (there will always be an
-- HsSrcFile associated with it), and
-- * HsBootFile is an hs-boot file. Within a unit, it can
-- be used to break recursive module imports, in which case there's an
-- HsSrcFile associated with it. However, externally, it can
-- also be used to specify the *requirements* of a package,
-- in which case there is an HsBootMerge associated with it.
--
-- * HsigFile is an hsig file, which contains only type
-- signatures and is used to specify signatures for
-- modules.
--
-- Syntactically, hs-boot files and hsig files are quite similar: they
-- only include type signatures and must be associated with an
-- actual HsSrcFile. isHsBootOrSig allows us to abstract over code
-- which is indifferent to which. However, there are some important
-- differences, mostly owing to the fact that hsigs are proper
-- modules (you `import Sig` directly) whereas HsBootFiles are
-- temporary placeholders (you `import {-# SOURCE #-} Mod).
-- When we finish compiling the true implementation of an hs-boot,
-- we replace the HomeModInfo with the real HsSrcFile. An HsigFile, on the
-- other hand, is never replaced (in particular, we *cannot* use the
-- HomeModInfo of the original HsSrcFile backing the signature, since it
-- will export too many symbols.)
--
-- Additionally, while HsSrcFile is the only Haskell file
-- which has *code*, we do generate .o files for HsigFile, because
-- this is how the recompilation checker figures out if a file
-- needs to be recompiled. These are fake object files which
-- should NOT be linked against.
-- An HsBootMerge is a "fake" source file, which is constructed
-- by collecting up non-recursive HsBootFiles into a single interface.
-- HsBootMerges get an hi and o file, and are treated as "non-boot"
-- sources.
data HscSource
= HsSrcFile | HsBootFile | HsigFile
= HsSrcFile | HsBootFile | HsBootMerge
deriving( Eq, Ord, Show )
-- Ord needed for the finite maps we build in CompManager
instance Outputable HscSource where
ppr HsSrcFile = text "HsSrcFile"
ppr HsBootFile = text "HsBootFile"
ppr HsBootMerge = text "HsBootMerge"
instance Binary HscSource where
put_ bh HsSrcFile = putByte bh 0
put_ bh HsBootFile = putByte bh 1
put_ bh HsigFile = putByte bh 2
put_ bh HsBootMerge = putByte bh 2
get bh = do
h <- getByte bh
case h of
0 -> return HsSrcFile
1 -> return HsBootFile
_ -> return HsigFile
_ -> return HsBootMerge
hscSourceString :: HscSource -> String
hscSourceString HsSrcFile = ""
hscSourceString HsBootFile = "[boot]"
hscSourceString HsigFile = "[sig]"
hscSourceString HsBootMerge = "[merge]"
-- See Note [isHsBootOrSig]
isHsBootOrSig :: HscSource -> Bool
isHsBootOrSig HsBootFile = True
isHsBootOrSig HsigFile = True
isHsBootOrSig _ = False
isHsBoot :: HscSource -> Bool
isHsBoot HsBootFile = True
isHsBoot HsSrcFile = False
isHsBoot HsBootMerge = False
data Phase
= Unlit HscSource
......@@ -232,10 +218,8 @@ nextPhase dflags p
startPhase :: String -> Phase
startPhase "lhs" = Unlit HsSrcFile
startPhase "lhs-boot" = Unlit HsBootFile
startPhase "lhsig" = Unlit HsigFile
startPhase "hs" = Cpp HsSrcFile
startPhase "hs-boot" = Cpp HsBootFile
startPhase "hsig" = Cpp HsigFile
startPhase "hscpp" = HsPp HsSrcFile
startPhase "hspp" = Hsc HsSrcFile
startPhase "hc" = HCc
......@@ -264,7 +248,9 @@ startPhase _ = StopLn -- all unknown file types
phaseInputExt :: Phase -> String
phaseInputExt (Unlit HsSrcFile) = "lhs"
phaseInputExt (Unlit HsBootFile) = "lhs-boot"
phaseInputExt (Unlit HsigFile) = "lhsig"
phaseInputExt (Unlit HsBootMerge) = panic "phaseInputExt: Unlit HsBootMerge"
-- You can't Unlit an HsBootMerge, because there's no source
-- file to Unlit!
phaseInputExt (Cpp _) = "lpp" -- intermediate only
phaseInputExt (HsPp _) = "hscpp" -- intermediate only
phaseInputExt (Hsc _) = "hspp" -- intermediate only
......@@ -289,7 +275,7 @@ phaseInputExt MergeStub = "o"
phaseInputExt StopLn = "o"
haskellish_src_suffixes, haskellish_suffixes, cish_suffixes,
haskellish_user_src_suffixes, haskellish_sig_suffixes
haskellish_user_src_suffixes
:: [String]
-- When a file with an extension in the haskellish_src_suffixes group is
-- loaded in --make mode, its imports will be loaded too.
......@@ -300,9 +286,7 @@ haskellish_suffixes = haskellish_src_suffixes ++
cish_suffixes = [ "c", "cpp", "C", "cc", "cxx", "s", "S", "ll", "bc", "lm_s", "m", "M", "mm" ]
-- Will not be deleted as temp files:
haskellish_user_src_suffixes =
haskellish_sig_suffixes ++ [ "hs", "lhs", "hs-boot", "lhs-boot" ]
haskellish_sig_suffixes = [ "hsig", "lhsig" ]
haskellish_user_src_suffixes = [ "hs", "lhs", "hs-boot", "lhs-boot" ]
objish_suffixes :: Platform -> [String]
-- Use the appropriate suffix for the system on which
......@@ -318,10 +302,9 @@ dynlib_suffixes platform = case platformOS platform of
_ -> ["so"]
isHaskellishSuffix, isHaskellSrcSuffix, isCishSuffix,
isHaskellUserSrcSuffix, isHaskellSigSuffix
isHaskellUserSrcSuffix
:: String -> Bool
isHaskellishSuffix s = s `elem` haskellish_suffixes
isHaskellSigSuffix s = s `elem` haskellish_sig_suffixes
isHaskellSrcSuffix s = s `elem` haskellish_src_suffixes
isCishSuffix s = s `elem` cish_suffixes
isHaskellUserSrcSuffix s = s `elem` haskellish_user_src_suffixes
......@@ -334,7 +317,7 @@ isSourceSuffix :: String -> Bool
isSourceSuffix suff = isHaskellishSuffix suff || isCishSuffix suff
isHaskellishFilename, isHaskellSrcFilename, isCishFilename,
isHaskellUserSrcFilename, isSourceFilename, isHaskellSigFilename
isHaskellUserSrcFilename, isSourceFilename
:: FilePath -> Bool
-- takeExtension return .foo, so we drop 1 to get rid of the .
isHaskellishFilename f = isHaskellishSuffix (drop 1 $ takeExtension f)
......@@ -342,7 +325,6 @@ isHaskellSrcFilename f = isHaskellSrcSuffix (drop 1 $ takeExtension f)
isCishFilename f = isCishSuffix (drop 1 $ takeExtension f)
isHaskellUserSrcFilename f = isHaskellUserSrcSuffix (drop 1 $ takeExtension f)
isSourceFilename f = isSourceSuffix (drop 1 $ takeExtension f)
isHaskellSigFilename f = isHaskellSigSuffix (drop 1 $ takeExtension f)
isObjectFilename, isDynLibFilename :: Platform -> FilePath -> Bool
isObjectFilename platform f = isObjectSuffix platform (drop 1 $ takeExtension f)
......
......@@ -13,7 +13,7 @@
module DriverPipeline (
-- Run a series of compilation steps in a pipeline, for a
-- collection of source files.
oneShot, compileFile,
oneShot, compileFile, mergeRequirement,
-- Interfaces for the batch-mode driver
linkBinary,
......@@ -23,6 +23,9 @@ module DriverPipeline (
compileOne, compileOne',
link,
-- Misc utility
makeMergeRequirementSummary,
-- Exports for hooks to override runPhase and link
PhasePlus(..), CompPipeline(..), PipeEnv(..), PipeState(..),
phaseOutputFilename, getPipeState, getPipeEnv,
......@@ -61,6 +64,7 @@ import MonadUtils
import Platform
import TcRnTypes
import Hooks
import MkIface
import Exception
import Data.IORef ( readIORef )
......@@ -71,6 +75,7 @@ import Control.Monad
import Data.List ( isSuffixOf )
import Data.Maybe
import Data.Char
import Data.Time
-- ---------------------------------------------------------------------------
-- Pre-process
......@@ -128,56 +133,75 @@ compileOne' :: Maybe TcGblEnv
compileOne' m_tc_result mHscMessage
hsc_env0 summary mod_index nmods mb_old_iface maybe_old_linkable
source_modified0
= do
let dflags0 = ms_hspp_opts summary
this_mod = ms_mod summary
src_flavour = ms_hsc_src summary
location = ms_location summary
input_fn = expectJust "compile:hs" (ml_hs_file location)
input_fnpp = ms_hspp_file summary
mod_graph = hsc_mod_graph hsc_env0
needsTH = any (xopt Opt_TemplateHaskell . ms_hspp_opts) mod_graph
needsQQ = any (xopt Opt_QuasiQuotes . ms_hspp_opts) mod_graph
needsLinker = needsTH || needsQQ
isDynWay = any (== WayDyn) (ways dflags0)
isProfWay = any (== WayProf) (ways dflags0)
-- #8180 - when using TemplateHaskell, switch on -dynamic-too so
-- the linker can correctly load the object files.
let dflags1 = if needsLinker && dynamicGhc && not isDynWay && not isProfWay
then gopt_set dflags0 Opt_BuildDynamicToo
else dflags0
debugTraceMsg dflags1 2 (text "compile: input file" <+> text input_fnpp)
| HsBootMerge <- ms_hsc_src summary
= do -- Do a boot merge instead! For now, something very simple
output_fn <- getOutputFilename next_phase
Temporary basename dflags next_phase (Just location)
e <- genericHscMergeRequirement mHscMessage
hsc_env summary mb_old_iface (mod_index, nmods)
let basename = dropExtension input_fn
case e of
-- TODO: dedup
Left iface ->
do details <- genModDetails hsc_env iface
return (HomeModInfo{ hm_details = details,
hm_iface = iface,
hm_linkable = maybe_old_linkable })
Right (iface0, mb_old_hash) ->
case hsc_lang of
HscInterpreted ->
do (iface, _no_change) <- mkIfaceDirect hsc_env mb_old_hash iface0
details <- genModDetails hsc_env iface
-- Merges don't need to link in any bytecode, unlike
-- HsSrcFiles.
let linkable = LM (ms_hs_date summary) this_mod []
return (HomeModInfo{ hm_details = details,
hm_iface = iface,
hm_linkable = Just linkable })
HscNothing ->
do (iface, no_change) <- mkIfaceDirect hsc_env mb_old_hash iface0
details <- genModDetails hsc_env iface
when (gopt Opt_WriteInterface dflags) $
hscWriteIface dflags iface no_change summary
let linkable = LM (ms_hs_date summary) this_mod []
return (HomeModInfo{ hm_details = details,
hm_iface = iface,
hm_linkable = Just linkable })
_ ->
do (iface, no_change) <- mkIfaceDirect hsc_env mb_old_hash iface0
hscWriteIface dflags iface no_change summary
-- #10660: Use the pipeline instead of calling
-- compileEmptyStub directly, so -dynamic-too gets
-- handled properly
let mod_name = ms_mod_name summary
_ <- runPipeline StopLn hsc_env
(output_fn,
Just (HscOut src_flavour
mod_name HscUpdateBootMerge))
(Just basename)
Persistent
(Just location)
Nothing
details <- genModDetails hsc_env iface
o_time <- getModificationUTCTime object_filename
let linkable =
LM o_time this_mod [DotO object_filename]
return (HomeModInfo{ hm_details = details,
hm_iface = iface,
hm_linkable = Just linkable })
-- We add the directory in which the .hs files resides) to the import path.
-- This is needed when we try to compile the .hc file later, if it
-- imports a _stub.h file that we created here.
let current_dir = takeDirectory basename
old_paths = includePaths dflags1
dflags = dflags1 { includePaths = current_dir : old_paths }
hsc_env = hsc_env0 {hsc_dflags = dflags}
| otherwise
= do
-- Figure out what lang we're generating
let hsc_lang = hscTarget dflags
-- ... and what the next phase should be
let next_phase = hscPostBackendPhase dflags src_flavour hsc_lang
-- ... and what file to generate the output into
debugTraceMsg dflags1 2 (text "compile: input file" <+> text input_fnpp)
-- What file to generate the output into?
output_fn <- getOutputFilename next_phase
Temporary basename dflags next_phase (Just location)
-- -fforce-recomp should also work with --make
let force_recomp = gopt Opt_ForceRecomp dflags
source_modified
| force_recomp = SourceModified
| otherwise = source_modified0
object_filename = ml_obj_file location
let always_do_basic_recompilation_check = case hsc_lang of
HscInterpreted -> True
_ -> False
e <- genericHscCompileGetFrontendResult
always_do_basic_recompilation_check
m_tc_result mHscMessage
......@@ -196,7 +220,7 @@ compileOne' m_tc_result mHscMessage
case hsc_lang of
HscInterpreted ->
case ms_hsc_src summary of
t | isHsBootOrSig t ->
HsBootFile ->
do (iface, _changed, details) <- hscSimpleIface hsc_env tc_result mb_old_hash
return (HomeModInfo{ hm_details = details,
hm_iface = iface,
......@@ -230,7 +254,7 @@ compileOne' m_tc_result mHscMessage
do (iface, changed, details) <- hscSimpleIface hsc_env tc_result mb_old_hash
when (gopt Opt_WriteInterface dflags) $
hscWriteIface dflags iface changed summary
let linkable = if isHsBootOrSig src_flavour
let linkable = if isHsBoot src_flavour
then maybe_old_linkable
else Just (LM (ms_hs_date summary) this_mod [])
return (HomeModInfo{ hm_details = details,
......@@ -239,39 +263,17 @@ compileOne' m_tc_result mHscMessage
_ ->
case ms_hsc_src summary of
HsBootMerge -> panic "This driver can't handle it"
HsBootFile ->
do (iface, changed, details) <- hscSimpleIface hsc_env tc_result mb_old_hash
hscWriteIface dflags iface changed summary
touchObjectFile dflags object_filename
return (HomeModInfo{ hm_details = details,
hm_iface = iface,
hm_linkable = maybe_old_linkable })
HsigFile ->
do (iface, changed, details) <-
hscSimpleIface hsc_env tc_result mb_old_hash
hscWriteIface dflags iface changed summary
-- #10660: Use the pipeline instead of calling
-- compileEmptyStub directly, so -dynamic-too gets
-- handled properly
let mod_name = ms_mod_name summary
_ <- runPipeline StopLn hsc_env
(output_fn,
Just (HscOut src_flavour mod_name HscUpdateSig))
(Just basename)
Persistent
(Just location)
Nothing
-- Same as Hs
o_time <- getModificationUTCTime object_filename
let linkable =
LM o_time this_mod [DotO object_filename]
touchObjectFile dflags object_filename
return (HomeModInfo{ hm_details = details,
hm_iface = iface,
hm_linkable = Just linkable })
return (HomeModInfo{
hm_details = details,
hm_iface = iface,
hm_linkable = maybe_old_linkable })
HsSrcFile ->
do guts0 <- hscDesugar hsc_env summary tc_result
......@@ -295,6 +297,51 @@ compileOne' m_tc_result mHscMessage
return (HomeModInfo{ hm_details = details,
hm_iface = iface,
hm_linkable = Just linkable })
where dflags0 = ms_hspp_opts summary
this_mod = ms_mod summary
src_flavour = ms_hsc_src summary
location = ms_location summary
input_fn = expectJust "compile:hs" (ml_hs_file location)
input_fnpp = ms_hspp_file summary
mod_graph = hsc_mod_graph hsc_env0
needsTH = any (xopt Opt_TemplateHaskell . ms_hspp_opts) mod_graph
needsQQ = any (xopt Opt_QuasiQuotes . ms_hspp_opts) mod_graph
needsLinker = needsTH || needsQQ
isDynWay = any (== WayDyn) (ways dflags0)
isProfWay = any (== WayProf) (ways dflags0)
-- #8180 - when using TemplateHaskell, switch on -dynamic-too so
-- the linker can correctly load the object files.
dflags1 = if needsLinker && dynamicGhc && not isDynWay && not isProfWay
then gopt_set dflags0 Opt_BuildDynamicToo
else dflags0
basename = dropExtension input_fn
-- We add the directory in which the .hs files resides) to the import
-- path. This is needed when we try to compile the .hc file later, if it
-- imports a _stub.h file that we created here.
current_dir = takeDirectory basename
old_paths = includePaths dflags1
dflags = dflags1 { includePaths = current_dir : old_paths }
hsc_env = hsc_env0 {hsc_dflags = dflags}
-- Figure out what lang we're generating
hsc_lang = hscTarget dflags
-- ... and what the next phase should be
next_phase = hscPostBackendPhase dflags src_flavour hsc_lang
-- -fforce-recomp should also work with --make
force_recomp = gopt Opt_ForceRecomp dflags
source_modified
| force_recomp = SourceModified
| otherwise = source_modified0
object_filename = ml_obj_file location
always_do_basic_recompilation_check = case hsc_lang of
HscInterpreted -> True
_ -> False
-----------------------------------------------------------------------------
-- stub .h and .c files (for foreign export support)
......@@ -511,6 +558,50 @@ oneShot hsc_env stop_phase srcs = do
o_files <- mapM (compileFile hsc_env stop_phase) srcs
doLink (hsc_dflags hsc_env) stop_phase o_files
-- | Constructs a 'ModSummary' for a "signature merge" node.
-- This is a simplified construction function which only checks
-- for a local hs-boot file.
makeMergeRequirementSummary :: HscEnv -> Bool -> ModuleName -> IO ModSummary
makeMergeRequirementSummary hsc_env obj_allowed mod_name = do
let dflags = hsc_dflags hsc_env
location <- liftIO $ mkHomeModLocation2 dflags mod_name
(moduleNameSlashes mod_name) (hiSuf dflags)
obj_timestamp <-
if isObjectTarget (hscTarget dflags) || obj_allowed -- bug #1205
then liftIO $ modificationTimeIfExists (ml_obj_file location)
else return Nothing
r <- findHomeModule hsc_env mod_name
let has_local_boot = case r of
Found _ _ -> True
_ -> False
src_timestamp <- case obj_timestamp of
Just date -> return date
Nothing -> getCurrentTime -- something fake
return ModSummary {
ms_mod = mkModule (thisPackage dflags) mod_name,
ms_hsc_src = HsBootMerge,
ms_location = location,
ms_hs_date = src_timestamp,
ms_obj_date = obj_timestamp,
ms_iface_date = Nothing,
-- TODO: fill this in with all the imports eventually
ms_srcimps = [],
ms_textual_imps = [],
ms_merge_imps = (has_local_boot, []),
ms_hspp_file = "FAKE",
ms_hspp_opts = dflags,
ms_hspp_buf = Nothing
}
-- | Top-level entry point for @ghc -merge-requirement ModName@.
mergeRequirement :: HscEnv -> ModuleName -> IO ()
mergeRequirement hsc_env mod_name = do
mod_summary <- makeMergeRequirementSummary hsc_env True mod_name
-- Based off of GhcMake handling
_ <- liftIO $ compileOne' Nothing Nothing hsc_env mod_summary 1 1 Nothing
Nothing SourceUnmodified
return ()
compileFile :: HscEnv -> Phase -> (FilePath, Maybe Phase) -> IO FilePath
compileFile hsc_env stop_phase (src, mb_phase) = do
exists <- doesFileExist src
......@@ -992,7 +1083,8 @@ runPhase (RealPhase (Hsc src_flavour)) input_fn dflags0
ms_obj_date = Nothing,
ms_iface_date = Nothing,
ms_textual_imps = imps,