Commit 24f6bec9 authored by Edward Z. Yang's avatar Edward Z. Yang

Sanity check if we pick up an hsig file without -instantiated-with.

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: default avatarEdward 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
parent 8f6d241a
......@@ -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
......
......@@ -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))
......
......@@ -15,11 +15,11 @@
[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 )
......
......@@ -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 )
......
......@@ -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]
......@@ -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]
......@@ -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
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.)
......@@ -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'])
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