summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Z. Yang <ezyang@fb.com>2019-02-01 01:00:50 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-04-01 02:56:10 -0400
commit9ba0a4bd6eacaa8aeb5513658a10a17d52c32e8f (patch)
tree455d2fb6392981f871cfc7ff226ae728d2080a12
parent6c27fd3517e17813baef2cb0130ec50798ff6543 (diff)
downloadhaskell-cherry-pick-d6d735c1.tar.gz
Fix #16219: TemplateHaskell causes indefinite package build errorcherry-pick-d6d735c1
It should work to write an indefinite package using TemplateHaskell, so long as all of the actual TH code lives outside of the package. However, cleverness we had to build TH code even when building with -fno-code meant that we attempted to build object code for modules in an indefinite package, even when the signatures were not instantiated. This patch disables said logic in the event that an indefinite package is being typechecked. Signed-off-by: Edward Z. Yang <ezyang@fb.com> Test Plan: validate Reviewers: simonpj, bgamari Reviewed By: bgamari Subscribers: rwbarton, carter GHC Trac Issues: #16219 Differential Revision: https://phabricator.haskell.org/D5475 (cherry picked from commit d6d735c1114082b9e9cc1ba7da87c49f52891320)
-rw-r--r--compiler/main/GhcMake.hs3
-rw-r--r--compiler/main/Packages.hs1
-rw-r--r--testsuite/tests/backpack/cabal/T16219/LICENSE30
-rw-r--r--testsuite/tests/backpack/cabal/T16219/Makefile18
-rw-r--r--testsuite/tests/backpack/cabal/T16219/Setup.hs2
-rw-r--r--testsuite/tests/backpack/cabal/T16219/all.T9
-rw-r--r--testsuite/tests/backpack/cabal/T16219/backpack-issue.cabal47
-rw-r--r--testsuite/tests/backpack/cabal/T16219/library-a-impl/A.hs6
-rw-r--r--testsuite/tests/backpack/cabal/T16219/library-a/A/Sig.hsig5
-rw-r--r--testsuite/tests/backpack/cabal/T16219/library-a/B.hs6
-rw-r--r--testsuite/tests/backpack/cabal/T16219/library-b/C.hs10
11 files changed, 137 insertions, 0 deletions
diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs
index ae27d4e7fe..d5f58f8f9b 100644
--- a/compiler/main/GhcMake.hs
+++ b/compiler/main/GhcMake.hs
@@ -2045,6 +2045,9 @@ enableCodeGenForTH target nodemap =
, ms_hspp_opts = dflags@DynFlags
{hscTarget = HscNothing}
} <- ms
+ -- Don't enable codegen for TH on indefinite packages; we
+ -- can't compile anything anyway! See #16219.
+ , not (isIndefinite dflags)
, ms_mod `Set.member` needs_codegen_set
= do
let new_temp_file suf dynsuf = do
diff --git a/compiler/main/Packages.hs b/compiler/main/Packages.hs
index 70c9c26c11..44258de70c 100644
--- a/compiler/main/Packages.hs
+++ b/compiler/main/Packages.hs
@@ -58,6 +58,7 @@ module Packages (
pprPackages,
pprPackagesSimple,
pprModuleMap,
+ isIndefinite,
isDllName
)
where
diff --git a/testsuite/tests/backpack/cabal/T16219/LICENSE b/testsuite/tests/backpack/cabal/T16219/LICENSE
new file mode 100644
index 0000000000..9488e98f0f
--- /dev/null
+++ b/testsuite/tests/backpack/cabal/T16219/LICENSE
@@ -0,0 +1,30 @@
+Copyright (c) 2019, Isaac Elliott
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of Isaac Elliott nor the names of other
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/testsuite/tests/backpack/cabal/T16219/Makefile b/testsuite/tests/backpack/cabal/T16219/Makefile
new file mode 100644
index 0000000000..e98af4b2fc
--- /dev/null
+++ b/testsuite/tests/backpack/cabal/T16219/Makefile
@@ -0,0 +1,18 @@
+TOP=/../../..
+include $(TOP)/mk/boilerplate.mk
+include $(TOP)/mk/test.mk
+
+SETUP='$(PWD)/Setup' -v0
+CONFIGURE=$(SETUP) configure $(CABAL_MINIMAL_BUILD) --with-ghc='$(TEST_HC)' --ghc-options='$(TEST_HC_OPTS)' --package-db='$(PWD)/tmp.d' --prefix='$(PWD)/inst'
+
+T16219: clean
+ '$(GHC_PKG)' init tmp.d
+ '$(TEST_HC)' $(TEST_HC_OPTS) -v0 --make Setup
+ $(CONFIGURE)
+ $(SETUP) build
+ifneq "$(CLEANUP)" ""
+ $(MAKE) -s --no-print-directory clean
+endif
+
+clean :
+ $(RM) -rf tmp.d inst dist Setup$(exeext)
diff --git a/testsuite/tests/backpack/cabal/T16219/Setup.hs b/testsuite/tests/backpack/cabal/T16219/Setup.hs
new file mode 100644
index 0000000000..9a994af677
--- /dev/null
+++ b/testsuite/tests/backpack/cabal/T16219/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/testsuite/tests/backpack/cabal/T16219/all.T b/testsuite/tests/backpack/cabal/T16219/all.T
new file mode 100644
index 0000000000..29dd8a4d0b
--- /dev/null
+++ b/testsuite/tests/backpack/cabal/T16219/all.T
@@ -0,0 +1,9 @@
+if config.cleanup:
+ cleanup = 'CLEANUP=1'
+else:
+ cleanup = 'CLEANUP=0'
+
+test('T16219',
+ extra_files(['Setup.hs', 'backpack-issue.cabal', 'library-a', 'library-a-impl', 'library-b']),
+ run_command,
+ ['$MAKE -s --no-print-directory T16219 ' + cleanup])
diff --git a/testsuite/tests/backpack/cabal/T16219/backpack-issue.cabal b/testsuite/tests/backpack/cabal/T16219/backpack-issue.cabal
new file mode 100644
index 0000000000..4c3f673750
--- /dev/null
+++ b/testsuite/tests/backpack/cabal/T16219/backpack-issue.cabal
@@ -0,0 +1,47 @@
+-- Initial backpack-issue.cabal generated by cabal init. For further
+-- documentation, see http://haskell.org/cabal/users-guide/
+
+name: backpack-issue
+version: 0.1.0.0
+-- synopsis:
+-- description:
+license: BSD3
+license-file: LICENSE
+author: Isaac Elliott
+maintainer: isaace71295@gmail.com
+-- copyright:
+-- category:
+build-type: Simple
+extra-source-files: CHANGELOG.md
+cabal-version: >=2
+
+library library-a
+ signatures: A.Sig
+ exposed-modules: B
+ build-depends: base >=4.12 && <4.13
+ hs-source-dirs: library-a
+ default-language: Haskell2010
+
+library library-a-impl
+ exposed-modules: A
+ build-depends: base >=4.12 && <4.13
+ hs-source-dirs: library-a-impl
+ default-language: Haskell2010
+
+library library-b
+ exposed-modules: C
+ build-depends: base >=4.12 && <4.13
+ , library-a
+ hs-source-dirs: library-b
+ default-language: Haskell2010
+ extensions: TemplateHaskell
+
+library
+ mixins: library-a requires (A.Sig as A)
+ , library-b requires (A.Sig as A)
+ reexported-modules: A, B, C
+ build-depends: base >=4.12 && <4.13
+ , library-a
+ , library-a-impl
+ , library-b
+ default-language: Haskell2010
diff --git a/testsuite/tests/backpack/cabal/T16219/library-a-impl/A.hs b/testsuite/tests/backpack/cabal/T16219/library-a-impl/A.hs
new file mode 100644
index 0000000000..6598c3608a
--- /dev/null
+++ b/testsuite/tests/backpack/cabal/T16219/library-a-impl/A.hs
@@ -0,0 +1,6 @@
+module A where
+
+newtype A = A { unA :: Int }
+
+showA :: A -> String
+showA = show . unA
diff --git a/testsuite/tests/backpack/cabal/T16219/library-a/A/Sig.hsig b/testsuite/tests/backpack/cabal/T16219/library-a/A/Sig.hsig
new file mode 100644
index 0000000000..ce90feac71
--- /dev/null
+++ b/testsuite/tests/backpack/cabal/T16219/library-a/A/Sig.hsig
@@ -0,0 +1,5 @@
+signature A.Sig where
+
+data A
+
+showA :: A -> String
diff --git a/testsuite/tests/backpack/cabal/T16219/library-a/B.hs b/testsuite/tests/backpack/cabal/T16219/library-a/B.hs
new file mode 100644
index 0000000000..ad896562af
--- /dev/null
+++ b/testsuite/tests/backpack/cabal/T16219/library-a/B.hs
@@ -0,0 +1,6 @@
+module B where
+
+import A.Sig
+
+exclaimA :: A -> String
+exclaimA = (++ "!") . showA
diff --git a/testsuite/tests/backpack/cabal/T16219/library-b/C.hs b/testsuite/tests/backpack/cabal/T16219/library-b/C.hs
new file mode 100644
index 0000000000..4d4f7e8284
--- /dev/null
+++ b/testsuite/tests/backpack/cabal/T16219/library-b/C.hs
@@ -0,0 +1,10 @@
+{-# language TemplateHaskell #-}
+module C where
+
+import Data.Char (toUpper)
+
+import A.Sig
+import B
+
+veryExclaimA :: A -> String
+veryExclaimA = fmap toUpper . exclaimA