Fix recompilation tracking on signatures.
authorEdward Z. Yang <ezyang@cs.stanford.edu>
Sun, 12 Feb 2017 12:28:38 +0000 (04:28 -0800)
committerEdward Z. Yang <ezyang@cs.stanford.edu>
Fri, 17 Feb 2017 21:46:28 +0000 (13:46 -0800)
Summary:
Previously we weren't tracking these dependencies at all,
because we couldn't "find" the interface for {A.H}.  Now
we've associated hole names to the correct module identity
so we will pick them up.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Test Plan: validate

Reviewers: bgamari, austin

Subscribers: thomie, snowleopard

Differential Revision: https://phabricator.haskell.org/D3131

12 files changed:
compiler/deSugar/DsUsage.hs
compiler/typecheck/TcRnTypes.hs
testsuite/driver/extra_files.py
testsuite/tests/backpack/cabal/bkpcabal05/.gitignore [new file with mode: 0644]
testsuite/tests/backpack/cabal/bkpcabal05/A.hsig.in1 [new file with mode: 0644]
testsuite/tests/backpack/cabal/bkpcabal05/A.hsig.in2 [new file with mode: 0644]
testsuite/tests/backpack/cabal/bkpcabal05/M.hs [new file with mode: 0644]
testsuite/tests/backpack/cabal/bkpcabal05/Makefile [new file with mode: 0644]
testsuite/tests/backpack/cabal/bkpcabal05/Setup.hs [new file with mode: 0644]
testsuite/tests/backpack/cabal/bkpcabal05/all.T [new file with mode: 0644]
testsuite/tests/backpack/cabal/bkpcabal05/bkpcabal05.cabal [new file with mode: 0644]
testsuite/tests/backpack/cabal/bkpcabal05/bkpcabal05.stderr [new file with mode: 0644]

index 665f293..da29ac0 100644 (file)
@@ -119,11 +119,16 @@ mk_mod_usage_info pit hsc_env this_mod direct_imports used_names
              Nothing  -> ASSERT2( isSystemName name, ppr name ) mv_map
                 -- See Note [Internal used_names]
 
-             Just mod -> -- This lambda function is really just a
-                         -- specialised (++); originally came about to
-                         -- avoid quadratic behaviour (trac #2680)
-                         extendModuleEnvWith (\_ xs -> occ:xs) mv_map mod [occ]
-                where occ = nameOccName name
+             Just mod ->
+                -- See Note [Identity versus semantic module]
+                let mod' = if isHoleModule mod
+                            then mkModule this_pkg (moduleName mod)
+                            else mod
+                -- This lambda function is really just a
+                -- specialised (++); originally came about to
+                -- avoid quadratic behaviour (trac #2680)
+                in extendModuleEnvWith (\_ xs -> occ:xs) mv_map mod' [occ]
+            where occ = nameOccName name
 
     -- We want to create a Usage for a home module if
     --  a) we used something from it; has something in used_names
index 6b9db48..f0ca574 100644 (file)
@@ -475,6 +475,10 @@ data FrontendResult
 --        in the home library we are compiling.  (See LoadIface.)
 --        Similarly, in RnNames we check for self-imports using
 --        identity modules, to allow signatures to import their implementor.
+--
+--      - For recompilation avoidance, you want the identity module,
+--        since that will actually say the specific interface you
+--        want to track (and recompile if it changes)
 
 
 -- | 'TcGblEnv' describes the top-level of the module at the
index 82d2c99..28e9348 100644 (file)
@@ -162,6 +162,7 @@ extra_src_files = {
   'bkpcabal02': ['p', 'q', 'bkpcabal02.cabal', 'Setup.hs'],
   'bkpcabal03': ['asig1', 'asig2', 'bkpcabal03.cabal.in1', 'bkpcabal03.cabal.in2', 'Setup.hs', 'Mod.hs'],
   'bkpcabal04': ['p','q','bkpcabal04.cabal.in1','bkpcabal04.cabal.in2','Setup.hs'],
+  'bkpcabal05': ['bkpcabal05.cabal','A.hsig.in1','A.hsig.in2','M.hs','Setup.hs'],
   'break001': ['../Test2.hs'],
   'break002': ['../Test2.hs'],
   'break003': ['../Test3.hs'],
diff --git a/testsuite/tests/backpack/cabal/bkpcabal05/.gitignore b/testsuite/tests/backpack/cabal/bkpcabal05/.gitignore
new file mode 100644 (file)
index 0000000..d73b31a
--- /dev/null
@@ -0,0 +1 @@
+A.hsig
diff --git a/testsuite/tests/backpack/cabal/bkpcabal05/A.hsig.in1 b/testsuite/tests/backpack/cabal/bkpcabal05/A.hsig.in1
new file mode 100644 (file)
index 0000000..7f47064
--- /dev/null
@@ -0,0 +1,3 @@
+signature A where
+data T
+instance Show T
diff --git a/testsuite/tests/backpack/cabal/bkpcabal05/A.hsig.in2 b/testsuite/tests/backpack/cabal/bkpcabal05/A.hsig.in2
new file mode 100644 (file)
index 0000000..19a83e4
--- /dev/null
@@ -0,0 +1,2 @@
+signature A where
+data T
diff --git a/testsuite/tests/backpack/cabal/bkpcabal05/M.hs b/testsuite/tests/backpack/cabal/bkpcabal05/M.hs
new file mode 100644 (file)
index 0000000..7f4f64a
--- /dev/null
@@ -0,0 +1,4 @@
+module M where
+import A
+f :: T -> String
+f = show
diff --git a/testsuite/tests/backpack/cabal/bkpcabal05/Makefile b/testsuite/tests/backpack/cabal/bkpcabal05/Makefile
new file mode 100644 (file)
index 0000000..d4c116b
--- /dev/null
@@ -0,0 +1,23 @@
+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'
+
+bkpcabal05: clean
+       $(MAKE) -s --no-print-directory clean
+       '$(GHC_PKG)' init tmp.d
+       '$(TEST_HC)' -v0 --make Setup
+       $(CONFIGURE)
+       cp A.hsig.in1 A.hsig
+       # typecheck
+       $(SETUP) build
+       cp A.hsig.in2 A.hsig
+       ! $(SETUP) build
+ifneq "$(CLEANUP)" ""
+       $(MAKE) -s --no-print-directory clean
+endif
+
+clean :
+       $(RM) -rf tmp.d inst dist Setup$(exeext) A.hsig
diff --git a/testsuite/tests/backpack/cabal/bkpcabal05/Setup.hs b/testsuite/tests/backpack/cabal/bkpcabal05/Setup.hs
new file mode 100644 (file)
index 0000000..9a994af
--- /dev/null
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/testsuite/tests/backpack/cabal/bkpcabal05/all.T b/testsuite/tests/backpack/cabal/bkpcabal05/all.T
new file mode 100644 (file)
index 0000000..ab75dba
--- /dev/null
@@ -0,0 +1,9 @@
+if config.cleanup:
+   cleanup = 'CLEANUP=1'
+else:
+   cleanup = 'CLEANUP=0'
+
+test('bkpcabal05',
+     normal,
+     run_command,
+     ['$MAKE -s --no-print-directory bkpcabal05 ' + cleanup])
diff --git a/testsuite/tests/backpack/cabal/bkpcabal05/bkpcabal05.cabal b/testsuite/tests/backpack/cabal/bkpcabal05/bkpcabal05.cabal
new file mode 100644 (file)
index 0000000..47e78a4
--- /dev/null
@@ -0,0 +1,12 @@
+name:                bkpcabal05
+version:             0.1.0.0
+license:             BSD3
+author:              Edward Z. Yang
+maintainer:          ezyang@cs.stanford.edu
+build-type:          Simple
+cabal-version:       >=1.25
+
+library
+  signatures: A
+  exposed-modules: M
+  build-depends: base
diff --git a/testsuite/tests/backpack/cabal/bkpcabal05/bkpcabal05.stderr b/testsuite/tests/backpack/cabal/bkpcabal05/bkpcabal05.stderr
new file mode 100644 (file)
index 0000000..6f08796
--- /dev/null
@@ -0,0 +1,5 @@
+
+M.hs:4:5: error:
+    • No instance for (Show T) arising from a use of ‘show’
+    • In the expression: show
+      In an equation for ‘f’: f = show