Commit 62332f36 authored by Edward Z. Yang's avatar Edward Z. Yang
Browse files

Setup tcg_imports earlier during signature matching, so orphans are visible.

Previously, we updated tcg_imports after doing all of the
actual matching, which was fine for outputting the interface,
but not good enough for checking if all type classes were
implemented; we weren't treating orphans as visible (when
they needed to be.)

Fixes #12945.
Signed-off-by: default avatarEdward Z. Yang <>

Test Plan: validate

Reviewers: simonpj, austin, bgamari

Subscribers: thomie

Differential Revision:

GHC Trac Issues: #12945
parent c5fbbac9
......@@ -538,13 +538,24 @@ checkImplements impl_mod (IndefModule uid mod_name) = do
let insts = indefUnitIdInsts uid
-- STEP 1: Load the implementing interface, and make a RdrEnv
-- for its exports
-- for its exports. Also, add its 'ImportAvails' to 'tcg_imports',
-- so that we treat all orphan instances it provides as visible
-- when we verify that all instances are checked (see #12945), and so that
-- when we eventually write out the interface we record appropriate
-- dependency information.
impl_iface <- initIfaceTcRn $
loadSysInterface (text "checkImplements 1") impl_mod
let impl_gr = mkGlobalRdrEnv
(gresFromAvails Nothing (mi_exports impl_iface))
nsubst = mkNameShape (moduleName impl_mod) (mi_exports impl_iface)
dflags <- getDynFlags
let avails = calculateAvails dflags
impl_iface False{- safe -} False{- boot -}
updGblEnv (\tcg_env -> tcg_env {
tcg_imports = tcg_imports tcg_env `plusImportAvails` avails
}) $ do
-- STEP 2: Load the *unrenamed, uninstantiated* interface for
-- the ORIGINAL signature. We are going to eventually rename it,
-- but we must proceed slowly, because it is NOT known if the
......@@ -579,15 +590,10 @@ checkImplements impl_mod (IndefModule uid mod_name) = do
tcg_env <- getGblEnv
checkHsigIface tcg_env impl_gr sig_details
-- STEP 7: Make sure we have the right exports and imports,
-- in case we're going to serialize this out (only relevant
-- if we're actually instantiating).
dflags <- getDynFlags
let avails = calculateAvails dflags
impl_iface False{- safe -} False{- boot -}
-- STEP 7: Return the updated 'TcGblEnv' with the signature exports,
-- so we write them out.
return tcg_env {
tcg_exports = mi_exports sig_iface,
tcg_imports = tcg_imports tcg_env `plusImportAvails` avails
tcg_exports = mi_exports sig_iface
-- | Given 'tcg_mod', instantiate a 'ModIface' from the indefinite
......@@ -32,3 +32,4 @@ test('bkp37', normal, backpack_compile, [''])
test('bkp38', normal, backpack_compile, [''])
test('bkp39', normal, backpack_compile, [''])
test('bkp40', normal, backpack_compile, [''])
test('bkp41', normal, backpack_compile, [''])
unit impl where
module A where
data T = T
module B(module A, module B) where
import A
instance Show T where
show T = "T"
unit sig where
signature B where
data T = T
instance Show T
module App where
import B
app = print T
unit main where
dependency sig[B=impl:B]
[1 of 3] Processing impl
Instantiating impl
[1 of 2] Compiling A ( impl/A.hs, bkp41.out/impl/A.o )
[2 of 2] Compiling B ( impl/B.hs, bkp41.out/impl/B.o )
[2 of 3] Processing sig
[1 of 2] Compiling B[sig] ( sig/B.hsig, nothing )
[2 of 2] Compiling App ( sig/App.hs, nothing )
[3 of 3] Processing main
Instantiating main
[1 of 1] Including sig[B=impl:B]
Instantiating sig[B=impl:B]
[1 of 2] Compiling B[sig] ( sig/B.hsig, bkp41.out/sig/sig-HVnmSw44WZeBfwnUur4wzl/B.o )
[2 of 2] Compiling App ( sig/App.hs, bkp41.out/sig/sig-HVnmSw44WZeBfwnUur4wzl/App.o )
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