Sanity check if we pick up an hsig file without -instantiated-with.
authorEdward Z. Yang <ezyang@cs.stanford.edu>
Fri, 9 Dec 2016 03:32:37 +0000 (19:32 -0800)
committerEdward Z. Yang <ezyang@cs.stanford.edu>
Tue, 13 Dec 2016 07:09:55 +0000 (23:09 -0800)
Summary:
Previously we would just let compilation proceed along until
we tried to pull up the Module for the hsig file, and get
main:A instead of <A>, and get a mysterious error.  Check
for this earlier!

Fixes #12955.

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

Reviewers: simonpj, austin, bgamari

Subscribers: thomie

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

GHC Trac Issues: #12955

compiler/basicTypes/Module.hs
compiler/main/GhcMake.hs
testsuite/tests/backpack/reexport/bkpreex02.stderr
testsuite/tests/backpack/should_compile/bkp24.stderr
testsuite/tests/backpack/should_fail/bkpfail14.stderr
testsuite/tests/backpack/should_fail/bkpfail15.stderr
testsuite/tests/driver/Makefile
testsuite/tests/driver/T12955.hsig [new file with mode: 0644]
testsuite/tests/driver/T12955.stderr [new file with mode: 0644]
testsuite/tests/driver/all.T

index 78abf21..75ff67d 100644 (file)
@@ -690,21 +690,10 @@ instance Outputable IndefUnitId where
       ppr cid <>
         (if not (null insts) -- pprIf
           then
-            -- TODO: Print an instantiation if (1) we would not have qualified
-            -- the module and (2) the module name and module agree
-            let -- is_wanted (mod_name, mod) = qualModule sty mod
-                --                         || mod_name /= moduleName mod
-                (wanted, unwanted) = (insts, [])
-                    {-
-                    -- This was more annoying than helpful
-                    | debugStyle sty = (insts, [])
-                    | otherwise = partition is_wanted insts
-                    -}
-            in brackets (hsep
+            brackets (hcat
                 (punctuate comma $
                     [ ppr modname <> text "=" <> ppr m
-                    | (modname, m) <- wanted] ++
-                    if not (null unwanted) then [text "..."] else []))
+                    | (modname, m) <- insts]))
           else empty)
      where
       cid   = indefUnitIdComponentId uid
index 2340f3f..aa50c3a 100644 (file)
@@ -2049,6 +2049,24 @@ summariseModule hsc_env old_summary_map is_boot (L loc wanted_mod)
                               $$ text "Saw:" <+> quotes (ppr mod_name)
                               $$ text "Expected:" <+> quotes (ppr wanted_mod)
 
+        when (hsc_src == HsigFile && isNothing (lookup mod_name (thisUnitIdInsts dflags))) $
+            let suggested_instantiated_with =
+                    hcat (punctuate comma $
+                        [ ppr k <> text "=" <> ppr v
+                        | (k,v) <- ((mod_name, mkHoleModule mod_name)
+                                : thisUnitIdInsts dflags)
+                        ])
+            in throwOneError $ mkPlainErrMsg dflags' mod_loc $
+                text "Unexpected signature:" <+> quotes (ppr mod_name)
+                $$ if gopt Opt_BuildingCabalPackage dflags
+                    then parens (text "Try adding" <+> quotes (ppr mod_name)
+                            <+> text "to the"
+                            <+> quotes (text "signatures")
+                            <+> text "field in your Cabal file.")
+                    else parens (text "Try passing -instantiated-with=\"" <>
+                                 suggested_instantiated_with <> text "\"" $$
+                                text "replacing <" <> ppr mod_name <> text "> as necessary.")
+
                 -- Find the object timestamp, and return the summary
         obj_timestamp <-
            if isObjectTarget (hscTarget (hsc_dflags hsc_env))
index 44c07c4..8ae6714 100644 (file)
   [2 of 2] Compiling T                ( r-impl/T.hs, nothing )
 [5 of 5] Processing r
   Instantiating r
-  [1 of 1] Including q[H=r-impl:H, T=r-impl:T]
-    Instantiating q[H=r-impl:H, T=r-impl:T]
+  [1 of 1] Including q[H=r-impl:H,T=r-impl:T]
+    Instantiating q[H=r-impl:H,T=r-impl:T]
     [1 of 2] Including timpl
-    [2 of 2] Including p[H=r-impl:H, T=r-impl:T]
-      Instantiating p[H=r-impl:H, T=r-impl:T]
+    [2 of 2] Including p[H=r-impl:H,T=r-impl:T]
+      Instantiating p[H=r-impl:H,T=r-impl:T]
       [1 of 2] Compiling T[sig]           ( p/T.hsig, nothing )
       [2 of 2] Compiling H[sig]           ( p/H.hsig, nothing )
     [1 of 3] Compiling T[sig]           ( q/T.hsig, nothing )
index 73e1f9d..ddafe41 100644 (file)
@@ -15,8 +15,8 @@
   Instantiating r
   [1 of 2] Including q[B=b:B]
     Instantiating q[B=b:B]
-    [1 of 2] Including p[A=a:A, B=b:B]
-      Instantiating p[A=a:A, B=b:B]
+    [1 of 2] Including p[A=a:A,B=b:B]
+      Instantiating p[A=a:A,B=b:B]
       [1 of 3] Compiling A[sig]           ( p/A.hsig, bkp24.out/p/p-BVwzUlgOVR6H8V9umpUZ2h/A.o )
       [2 of 3] Compiling B[sig]           ( p/B.hsig, bkp24.out/p/p-BVwzUlgOVR6H8V9umpUZ2h/B.o )
       [3 of 3] Compiling P                ( p/P.hs, bkp24.out/p/p-BVwzUlgOVR6H8V9umpUZ2h/P.o )
index ddfddee..d89e6ca 100644 (file)
@@ -15,4 +15,4 @@ bkpfail14.bkp:9:9: error:
       Main module: f :: GHC.Types.Bool
       Hsig file:  f :: GHC.Types.Int
       The two types are different
-    • while checking that QMe implements signature Q in p[Q=QMe, Q2=Q2]
+    • while checking that QMe implements signature Q in p[Q=QMe,Q2=Q2]
index e761cb1..f32cd6d 100644 (file)
@@ -14,4 +14,4 @@ bkpfail15.bkp:8:9: error:
       Main module: f :: GHC.Types.Bool
       Hsig file:  f :: GHC.Types.Int
       The two types are different
-    • while checking that q:Q implements signature Q in p[A=<A>, Q=q:Q]
+    • while checking that q:Q implements signature Q in p[A=<A>,Q=q:Q]
index 4e9ef20..2dfb41f 100644 (file)
@@ -636,3 +636,8 @@ T10923:
        "$(TEST_HC)" $(TEST_HC_OPTS) -v1 -O0 -c T10923.hs
        # should NOT output "compilation is NOT required"
        "$(TEST_HC)" $(TEST_HC_OPTS) -v1 -O -c T10923.hs
+
+.PHONY: T12955
+T12955:
+       ! "$(TEST_HC)" $(TEST_HC_OPTS) --make T12955
+       ! "$(TEST_HC)" $(TEST_HC_OPTS) --make T12955 -fbuilding-cabal-package
diff --git a/testsuite/tests/driver/T12955.hsig b/testsuite/tests/driver/T12955.hsig
new file mode 100644 (file)
index 0000000..3b674fc
--- /dev/null
@@ -0,0 +1 @@
+signature T12955 where
diff --git a/testsuite/tests/driver/T12955.stderr b/testsuite/tests/driver/T12955.stderr
new file mode 100644 (file)
index 0000000..acf4000
--- /dev/null
@@ -0,0 +1,9 @@
+
+T12955.hsig:1:11: error:
+    Unexpected signature: ‘T12955’
+    (Try passing -instantiated-with="T12955=<T12955>"
+     replacing <T12955> as necessary.)
+
+T12955.hsig:1:11: error:
+    Unexpected signature: ‘T12955’
+    (Try adding ‘T12955’ to the ‘signatures’ field in your Cabal file.)
index 8cd5c2f..9119c71 100644 (file)
@@ -499,3 +499,5 @@ test('T10923',
      ['$MAKE -s --no-print-directory T10923'])
 
 test('T12752pass', normal, compile, ['-DSHOULD_PASS=1 -Wcpp-undef'])
+
+test('T12955', normal, run_command, ['$MAKE -s --no-print-directory T12955'])