summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Z. Yang <ezyang@cs.stanford.edu>2014-12-01 21:07:33 -0800
committerEdward Z. Yang <ezyang@cs.stanford.edu>2014-12-02 18:06:45 -0800
commit46b278fb75c708256e0a8cfefb8a2bce10fddef4 (patch)
tree70d4f83aa919220770339b21fe34f323da2f2b9c
parentbf2d75417b5be7e8a79a26ee57a81e00682dabd4 (diff)
downloadhaskell-46b278fb75c708256e0a8cfefb8a2bce10fddef4.tar.gz
Generate real (but empty) object files for signatures.
Summary: It's not great, but it preserves a nice invariant that every Haskell source file has an object file (we already have a hack in place ensure this is the case for hs-boot files) and further ensures every package has a library associated with it (which would not be the case if the package had all signatures and we didn't make object files.) Contains Cabal submodule update. Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu> Test Plan: validate Reviewers: simonpj, austin Subscribers: carter, thomie Differential Revision: https://phabricator.haskell.org/D548
-rw-r--r--compiler/main/DriverPipeline.hs49
-rw-r--r--compiler/main/HscMain.hs5
-rw-r--r--compiler/main/HscTypes.lhs1
-rw-r--r--docs/users_guide/separate_compilation.xml6
m---------libraries/Cabal0
5 files changed, 49 insertions, 12 deletions
diff --git a/compiler/main/DriverPipeline.hs b/compiler/main/DriverPipeline.hs
index eefa0a6ba3..fdec73e1ce 100644
--- a/compiler/main/DriverPipeline.hs
+++ b/compiler/main/DriverPipeline.hs
@@ -240,7 +240,7 @@ compileOne' m_tc_result mHscMessage
_ ->
case ms_hsc_src summary of
- t | isHsBootOrSig t ->
+ HsBootFile ->
do (iface, changed, details) <- hscSimpleIface hsc_env tc_result mb_old_hash
hscWriteIface dflags iface changed summary
touchObjectFile dflags object_filename
@@ -248,7 +248,23 @@ compileOne' m_tc_result mHscMessage
hm_iface = iface,
hm_linkable = maybe_old_linkable })
- _ -> do guts0 <- hscDesugar hsc_env summary tc_result
+ HsigFile ->
+ do (iface, changed, details) <-
+ hscSimpleIface hsc_env tc_result mb_old_hash
+ hscWriteIface dflags iface changed summary
+ compileEmptyStub dflags hsc_env basename location
+
+ -- Same as Hs
+ 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 })
+
+ HsSrcFile ->
+ do guts0 <- hscDesugar hsc_env summary tc_result
guts <- hscSimplify hsc_env guts0
(iface, changed, details, cgguts) <- hscNormalIface hsc_env guts mb_old_hash
hscWriteIface dflags iface changed summary
@@ -287,6 +303,21 @@ compileStub hsc_env stub_c = do
return stub_o
+compileEmptyStub :: DynFlags -> HscEnv -> FilePath -> ModLocation -> IO ()
+compileEmptyStub dflags hsc_env basename location = do
+ -- To maintain the invariant that every Haskell file
+ -- compiles to object code, we make an empty (but
+ -- valid) stub object file for signatures
+ empty_stub <- newTempName dflags "c"
+ writeFile empty_stub ""
+ _ <- runPipeline StopLn hsc_env
+ (empty_stub, Nothing)
+ (Just basename)
+ Persistent
+ (Just location)
+ Nothing
+ return ()
+
-- ---------------------------------------------------------------------------
-- Link
@@ -341,11 +372,7 @@ link' dflags batch_attempt_linking hpt
LinkStaticLib -> True
_ -> platformBinariesAreStaticLibs (targetPlatform dflags)
- -- Don't attempt to link hsigs; they don't actually produce objects.
- -- This is in contrast to hs-boot files, which will /eventually/
- -- get objects.
- home_mod_infos =
- filter ((==Nothing).mi_sig_of.hm_iface) (eltsUFM hpt)
+ home_mod_infos = eltsUFM hpt
-- the packages we depend on
pkg_deps = concatMap (map fst . dep_pkgs . mi_deps . hm_iface) home_mod_infos
@@ -981,6 +1008,14 @@ runPhase (HscOut src_flavour mod_name result) _ dflags = do
-- stamp file for the benefit of Make
liftIO $ touchObjectFile dflags o_file
return (RealPhase next_phase, o_file)
+ HscUpdateSig ->
+ do -- We need to create a REAL but empty .o file
+ -- because we are going to attempt to put it in a library
+ PipeState{hsc_env=hsc_env'} <- getPipeState
+ let input_fn = expectJust "runPhase" (ml_hs_file location)
+ basename = dropExtension input_fn
+ liftIO $ compileEmptyStub dflags hsc_env' basename location
+ return (RealPhase next_phase, o_file)
HscRecomp cgguts mod_summary
-> do output_fn <- phaseOutputFilename next_phase
diff --git a/compiler/main/HscMain.hs b/compiler/main/HscMain.hs
index fcf0c48de0..8f8da0266b 100644
--- a/compiler/main/HscMain.hs
+++ b/compiler/main/HscMain.hs
@@ -647,7 +647,10 @@ hscCompileOneShot' hsc_env mod_summary src_changed
t | isHsBootOrSig t ->
do (iface, changed, _) <- hscSimpleIface' tc_result mb_old_hash
liftIO $ hscWriteIface dflags iface changed mod_summary
- return HscUpdateBoot
+ return (case t of
+ HsBootFile -> HscUpdateBoot
+ HsigFile -> HscUpdateSig
+ HsSrcFile -> panic "hscCompileOneShot Src")
_ ->
do guts <- hscSimplify' guts0
(iface, changed, _details, cgguts) <- hscNormalIface' guts mb_old_hash
diff --git a/compiler/main/HscTypes.lhs b/compiler/main/HscTypes.lhs
index cf3db52c94..b6e3a98a50 100644
--- a/compiler/main/HscTypes.lhs
+++ b/compiler/main/HscTypes.lhs
@@ -195,6 +195,7 @@ data HscStatus
= HscNotGeneratingCode
| HscUpToDate
| HscUpdateBoot
+ | HscUpdateSig
| HscRecomp CgGuts ModSummary
-- -----------------------------------------------------------------------------
diff --git a/docs/users_guide/separate_compilation.xml b/docs/users_guide/separate_compilation.xml
index 43ab182729..b30eff86ae 100644
--- a/docs/users_guide/separate_compilation.xml
+++ b/docs/users_guide/separate_compilation.xml
@@ -966,10 +966,8 @@ ghc -c A.hs
<para>Just like <literal>hs-boot</literal> files, when an
<literal>hsig</literal> file is compiled it is checked for type
- consistency against the backing implementation; furthermore, it also
- produces a pseudo-object file <literal>A.o</literal> which you should
- not link with. Signature files are also written in a subset
- of Haskell similar to essentially identical to that of
+ consistency against the backing implementation. Signature files are also
+ written in a subset of Haskell essentially identical to that of
<literal>hs-boot</literal> files.</para>
<para>There is one important gotcha with the current implementation:
diff --git a/libraries/Cabal b/libraries/Cabal
-Subproject 6c395bb8f22961ce5267df64e6d9351c310fcbb
+Subproject ea062bf522e015f6e643bcc833487098edba839