summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2019-05-20 12:17:36 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-05-29 10:41:02 -0400
commitfb26d46754564bfacda98618d86d3ee4eda1fcf2 (patch)
tree1aa4bf43107a19ea23fd3bdedd11bed3d77e8778
parent5b90e0a173f69c9babb3201f62cd5096798c5240 (diff)
downloadhaskell-fb26d46754564bfacda98618d86d3ee4eda1fcf2.tar.gz
downsweep: Allow TargetFile not to exist when a buffer is given
Currently 'getRootSummary' will fail with an exception if a 'TargetFile' is given but it does not exist even if an input buffer is passed along for this target. In this case it is not necessary for the file to exist since the buffer will be used as input for the compilation pipeline instead of the file anyways.
-rw-r--r--compiler/main/GhcMake.hs2
-rw-r--r--compiler/main/HscTypes.hs5
-rw-r--r--testsuite/tests/ghc-api/target-contents/TargetContents.hs3
-rw-r--r--testsuite/tests/ghc-api/target-contents/TargetContents.stderr22
4 files changed, 14 insertions, 18 deletions
diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs
index b55a4e3760..3e62558e78 100644
--- a/compiler/main/GhcMake.hs
+++ b/compiler/main/GhcMake.hs
@@ -1978,7 +1978,7 @@ downsweep hsc_env old_summaries excl_mods allow_dup_roots
getRootSummary :: Target -> IO (Either ErrMsg ModSummary)
getRootSummary (Target (TargetFile file mb_phase) obj_allowed maybe_buf)
= do exists <- liftIO $ doesFileExist file
- if exists
+ if exists || isJust maybe_buf
then Right `fmap` summariseFile hsc_env old_summaries file mb_phase
obj_allowed maybe_buf
else return $ Left $ mkPlainErrMsg dflags noSrcSpan $
diff --git a/compiler/main/HscTypes.hs b/compiler/main/HscTypes.hs
index 744841a63d..e75b2457f0 100644
--- a/compiler/main/HscTypes.hs
+++ b/compiler/main/HscTypes.hs
@@ -517,6 +517,11 @@ data Target
--
-- Since GHC version 8.10 modules which require preprocessors such as
-- Literate Haskell or CPP to run are also supported.
+ --
+ -- If a corresponding source file does not exist on disk this will
+ -- result in a 'SourceError' exception if @targetId = TargetModule _@
+ -- is used. However together with @targetId = TargetFile _@ GHC will
+ -- not complain about the file missing.
}
data TargetId
diff --git a/testsuite/tests/ghc-api/target-contents/TargetContents.hs b/testsuite/tests/ghc-api/target-contents/TargetContents.hs
index db02dbde2b..eaa30697f8 100644
--- a/testsuite/tests/ghc-api/target-contents/TargetContents.hs
+++ b/testsuite/tests/ghc-api/target-contents/TargetContents.hs
@@ -90,8 +90,7 @@ main = do
data Sync
= OnDisk -- | Write generated module to disk
- | InMemory -- | Only fill targetContents, place an empty dummy module
- -- on disk though to make Finder shut up though.
+ | InMemory -- | Only fill in targetContents.
ppSync OnDisk = "D"
ppSync InMemory = "M"
diff --git a/testsuite/tests/ghc-api/target-contents/TargetContents.stderr b/testsuite/tests/ghc-api/target-contents/TargetContents.stderr
index b0a363c1e5..2743f5135e 100644
--- a/testsuite/tests/ghc-api/target-contents/TargetContents.stderr
+++ b/testsuite/tests/ghc-api/target-contents/TargetContents.stderr
@@ -3,8 +3,6 @@
A.hs:3:5: error: Variable not in scope: z
== CPP_D
== CPP_M
-can't find file: A.hs
-
== Dep_DD_AB
== Dep_Error_DD_AB
@@ -13,33 +11,27 @@ B.hs:3:5: error: Variable not in scope: z
B.hs:3:5: error: Variable not in scope: z
== Dep_MM_AB
-can't find file: A.hs
-can't find file: B.hs
-
== Dep_Error_MM_AB
-can't find file: A.hs
-can't find file: B.hs
+B.hs:3:5: error: Variable not in scope: z
== Dep_Error_MM_A
-can't find file: A.hs
+A.hs:3:1: error:
+ Could not find module ‘B’
+ Use -v (or `:set -v` in ghci) to see a list of the files searched for.
== Dep_DM_AB
-can't find file: B.hs
-
== Dep_Error_DM_AB
-can't find file: B.hs
+B.hs:3:5: error: Variable not in scope: z
== Dep_Error_DM_A
A.hs:3:1: error:
Could not find module ‘B’
Use -v (or `:set -v` in ghci) to see a list of the files searched for.
== Dep_MD_AB
-can't find file: A.hs
-
== Dep_Error_MD_AB
-can't find file: A.hs
+B.hs:3:5: error: Variable not in scope: z
== Dep_Error_MD_A
-can't find file: A.hs
+B.hs:3:5: error: Variable not in scope: z