[commit: ghc] wip/exceptions-note, wip/hadrian-import-packages, wip/splice-parsing, wip/trac-16270: Fix #16219: TemplateHaskell causes indefinite package build error (d6d735c)

git at git.haskell.org git at git.haskell.org
Sat Feb 2 09:00:01 UTC 2019


Repository : ssh://git@git.haskell.org/ghc

On branches: wip/exceptions-note,wip/hadrian-import-packages,wip/splice-parsing,wip/trac-16270
Link       : http://ghc.haskell.org/trac/ghc/changeset/d6d735c1114082b9e9cc1ba7da87c49f52891320/ghc

>---------------------------------------------------------------

commit d6d735c1114082b9e9cc1ba7da87c49f52891320
Author: Edward Z. Yang <ezyang at fb.com>
Date:   Thu Jan 31 20:00:50 2019 -0500

    Fix #16219: TemplateHaskell causes indefinite package build error
    
    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 at 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


>---------------------------------------------------------------

d6d735c1114082b9e9cc1ba7da87c49f52891320
 compiler/main/GhcMake.hs                           |  3 ++
 compiler/main/Packages.hs                          |  1 +
 .../cabal08/p1 => backpack/cabal/T16219}/LICENSE   |  4 +-
 .../backpack/cabal/{T15594 => T16219}/Makefile     |  6 +--
 .../backpack/cabal/{T14304 => T16219}/Setup.hs     |  0
 testsuite/tests/backpack/cabal/T16219/all.T        |  9 +++++
 .../backpack/cabal/T16219/backpack-issue.cabal     | 47 ++++++++++++++++++++++
 .../backpack/cabal/T16219/library-a-impl/A.hs      |  6 +++
 .../backpack/cabal/T16219/library-a/A/Sig.hsig     |  5 +++
 .../tests/backpack/cabal/T16219/library-a/B.hs     |  6 +++
 .../tests/backpack/cabal/T16219/library-b/C.hs     | 10 +++++
 11 files changed, 91 insertions(+), 6 deletions(-)

diff --git a/compiler/main/GhcMake.hs b/compiler/main/GhcMake.hs
index 85925b3..a6fe5c7 100644
--- a/compiler/main/GhcMake.hs
+++ b/compiler/main/GhcMake.hs
@@ -2045,6 +2045,9 @@ enableCodeGenForTH target nodemap =
         , ms_hspp_opts = dflags at 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 70c9c26..44258de 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/cabal/cabal08/p1/LICENSE b/testsuite/tests/backpack/cabal/T16219/LICENSE
similarity index 93%
copy from testsuite/tests/cabal/cabal08/p1/LICENSE
copy to testsuite/tests/backpack/cabal/T16219/LICENSE
index c8cc6ab..9488e98 100644
--- a/testsuite/tests/cabal/cabal08/p1/LICENSE
+++ b/testsuite/tests/backpack/cabal/T16219/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2015, Edward Z. Yang
+Copyright (c) 2019, Isaac Elliott
 
 All rights reserved.
 
@@ -13,7 +13,7 @@ modification, are permitted provided that the following conditions are met:
       disclaimer in the documentation and/or other materials provided
       with the distribution.
 
-    * Neither the name of Edward Z. Yang nor the names of other
+    * 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.
 
diff --git a/testsuite/tests/backpack/cabal/T15594/Makefile b/testsuite/tests/backpack/cabal/T16219/Makefile
similarity index 83%
copy from testsuite/tests/backpack/cabal/T15594/Makefile
copy to testsuite/tests/backpack/cabal/T16219/Makefile
index 57ef67f..e98af4b 100644
--- a/testsuite/tests/backpack/cabal/T15594/Makefile
+++ b/testsuite/tests/backpack/cabal/T16219/Makefile
@@ -1,17 +1,15 @@
-TOP=/home/ezyang/Dev/ghc-known-nat/testsuite
+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'
 
-T15594: clean
+T16219: clean
 	'$(GHC_PKG)' init tmp.d
 	'$(TEST_HC)' $(TEST_HC_OPTS) -v0 --make Setup
 	$(CONFIGURE)
 	$(SETUP) build
-	$(SETUP) copy
-	$(SETUP) register
 ifneq "$(CLEANUP)" ""
 	$(MAKE) -s --no-print-directory clean
 endif
diff --git a/testsuite/tests/backpack/cabal/T14304/Setup.hs b/testsuite/tests/backpack/cabal/T16219/Setup.hs
similarity index 100%
copy from testsuite/tests/backpack/cabal/T14304/Setup.hs
copy to testsuite/tests/backpack/cabal/T16219/Setup.hs
diff --git a/testsuite/tests/backpack/cabal/T16219/all.T b/testsuite/tests/backpack/cabal/T16219/all.T
new file mode 100644
index 0000000..29dd8a4
--- /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 0000000..4c3f673
--- /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 at 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 0000000..6598c36
--- /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 0000000..ce90fea
--- /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 0000000..ad89656
--- /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 0000000..4d4f7e8
--- /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



More information about the ghc-commits mailing list