Commit d6d735c1 authored by Edward Z. Yang's avatar Edward Z. Yang Committed by Ben Gamari

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: default avatarEdward 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
parent ebe2d344
......@@ -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
......
......@@ -58,6 +58,7 @@ module Packages (
pprPackages,
pprPackagesSimple,
pprModuleMap,
isIndefinite,
isDllName
)
where
......
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.
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)
import Distribution.Simple
main = defaultMain
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])
-- 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
module A where
newtype A = A { unA :: Int }
showA :: A -> String
showA = show . unA
signature A.Sig where
data A
showA :: A -> String
module B where
import A.Sig
exclaimA :: A -> String
exclaimA = (++ "!") . showA
{-# language TemplateHaskell #-}
module C where
import Data.Char (toUpper)
import A.Sig
import B
veryExclaimA :: A -> String
veryExclaimA = fmap toUpper . exclaimA
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment