Skip to content

Commit 0975d2b

Browse files
sheafMarge Bot
authored andcommitted
Revert "Remove hptAllFamInstances usage during upsweep"
This reverts commit 3bf6720.
1 parent 624afa4 commit 0975d2b

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

compiler/GHC/Driver/Env.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ hugCompleteSigsBelow hsc uid mn = foldr (++) [] <$>
246246
hugSomeThingsBelowUs (md_complete_matches . hm_details) False hsc uid mn
247247

248248
-- | Find instances visible from the given set of imports
249-
hugInstancesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [(Module, FamInstEnv)])
249+
hugInstancesBelow :: HscEnv -> UnitId -> ModuleNameWithIsBoot -> IO (InstEnv, [FamInst])
250250
hugInstancesBelow hsc_env uid mnwib = do
251251
let mn = gwib_mod mnwib
252252
(insts, famInsts) <-
@@ -256,7 +256,7 @@ hugInstancesBelow hsc_env uid mnwib = do
256256
-- Don't include instances for the current module
257257
in if moduleName (mi_module (hm_iface mod_info)) == mn
258258
then []
259-
else [(md_insts details, [(mi_module $ hm_iface mod_info, extendFamInstEnvList emptyFamInstEnv $ md_fam_insts details)])])
259+
else [(md_insts details, md_fam_insts details)])
260260
True -- Include -hi-boot
261261
hsc_env
262262
uid

compiler/GHC/Tc/Instance/Family.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,8 @@ why we still do redundant checks.
286286
-- We don't need to check the current module, this is done in
287287
-- tcExtendLocalFamInstEnv.
288288
-- See Note [The type family instance consistency story].
289-
checkFamInstConsistency :: ModuleEnv FamInstEnv -> [Module] -> TcM ()
290-
checkFamInstConsistency hpt_fam_insts directlyImpMods
289+
checkFamInstConsistency :: [Module] -> TcM ()
290+
checkFamInstConsistency directlyImpMods
291291
= do { (eps, hug) <- getEpsAndHug
292292
; traceTc "checkFamInstConsistency" (ppr directlyImpMods)
293293
; let { -- Fetch the iface of a given module. Must succeed as
@@ -317,6 +317,7 @@ checkFamInstConsistency hpt_fam_insts directlyImpMods
317317
-- See Note [Order of type family consistency checks]
318318
}
319319

320+
; hpt_fam_insts <- liftIO $ HUG.allFamInstances hug
320321
; debug_consistent_set <- mapM (\x -> (\y -> (x, length y)) <$> modConsistent x) directlyImpMods
321322
; traceTc "init_consistent_set" (ppr debug_consistent_set)
322323
; let init_consistent_set = map fst (reverse (sortOn snd debug_consistent_set))

compiler/GHC/Tc/Module.hs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ import GHC.Core.TyCo.Ppr( debugPprType )
119119
import GHC.Core.TyCo.Tidy( tidyTopType )
120120
import GHC.Core.FamInstEnv
121121
( FamInst, pprFamInst, famInstsRepTyCons, orphNamesOfFamInst
122-
, famInstEnvElts, extendFamInstEnvList, normaliseType, emptyFamInstEnv, unionFamInstEnv )
122+
, famInstEnvElts, extendFamInstEnvList, normaliseType )
123123

124124
import GHC.Parser.Header ( mkPrelImports )
125125

@@ -464,8 +464,8 @@ tcRnImports hsc_env import_decls
464464
= do { (rn_imports, imp_user_spec, rdr_env, imports) <- rnImports import_decls
465465
-- Get the default declarations for the classes imported by this module
466466
-- and group them by class.
467-
; tc_defaults <- NE.groupBy ((==) `on` cd_class) . (concatMap defaultList)
468-
<$> tcGetClsDefaults (M.keys $ imp_mods imports)
467+
; tc_defaults <-(NE.groupBy ((==) `on` cd_class) . (concatMap defaultList))
468+
<$> tcGetClsDefaults (M.keys $ imp_mods imports)
469469
; this_mod <- getModule
470470
; gbl_env <- getGblEnv
471471
; let unitId = homeUnitId $ hsc_home_unit hsc_env
@@ -477,10 +477,8 @@ tcRnImports hsc_env import_decls
477477
-- filtering also ensures that we don't see instances from
478478
-- modules batch (@--make@) compiled before this one, but
479479
-- which are not below this one.
480-
; (home_insts, home_mod_fam_inst_env) <- liftIO $
480+
; (home_insts, home_fam_insts) <- liftIO $
481481
hugInstancesBelow hsc_env unitId mnwib
482-
; let home_fam_inst_env = foldl' unionFamInstEnv emptyFamInstEnv $ snd <$> home_mod_fam_inst_env
483-
; let hpt_fam_insts = mkModuleEnv home_mod_fam_inst_env
484482

485483
-- We use 'unsafeInterleaveIO' to avoid redundant memory allocations
486484
-- See Note [Lazily loading COMPLETE pragmas] from GHC.HsToCore.Monad
@@ -506,7 +504,8 @@ tcRnImports hsc_env import_decls
506504
tcg_rn_imports = rn_imports,
507505
tcg_default = foldMap subsume tc_defaults,
508506
tcg_inst_env = tcg_inst_env gbl `unionInstEnv` home_insts,
509-
tcg_fam_inst_env = unionFamInstEnv (tcg_fam_inst_env gbl) home_fam_inst_env
507+
tcg_fam_inst_env = extendFamInstEnvList (tcg_fam_inst_env gbl)
508+
home_fam_insts
510509
}) $ do {
511510

512511
; traceRn "rn1" (ppr (imp_direct_dep_mods imports))
@@ -536,7 +535,7 @@ tcRnImports hsc_env import_decls
536535
$ imports }
537536
; logger <- getLogger
538537
; withTiming logger (text "ConsistencyCheck"<+>brackets (ppr this_mod)) (const ())
539-
$ checkFamInstConsistency hpt_fam_insts dir_imp_mods
538+
$ checkFamInstConsistency dir_imp_mods
540539
; traceRn "rn1: } checking family instance consistency" empty
541540

542541
; gbl_env <- getGblEnv

compiler/GHC/Unit/Home/Graph.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module GHC.Unit.Home.Graph
4343

4444
-- * Very important queries
4545
, allInstances
46+
, allFamInstances
4647
, allAnns
4748
, allCompleteSigs
4849

@@ -109,6 +110,10 @@ allInstances hug = foldr go (pure (emptyInstEnv, [])) hug where
109110
go hue = liftA2 (\(a,b) (a',b') -> (a `unionInstEnv` a', b ++ b'))
110111
(hptAllInstances (homeUnitEnv_hpt hue))
111112

113+
allFamInstances :: HomeUnitGraph -> IO (ModuleEnv FamInstEnv)
114+
allFamInstances hug = foldr go (pure emptyModuleEnv) hug where
115+
go hue = liftA2 plusModuleEnv (hptAllFamInstances (homeUnitEnv_hpt hue))
116+
112117
allAnns :: HomeUnitGraph -> IO AnnEnv
113118
allAnns hug = foldr go (pure emptyAnnEnv) hug where
114119
go hue = liftA2 plusAnnEnv (hptAllAnnotations (homeUnitEnv_hpt hue))

compiler/GHC/Unit/Home/PackageTable.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ module GHC.Unit.Home.PackageTable
4141
-- * Queries about home modules
4242
, hptCompleteSigs
4343
, hptAllInstances
44+
, hptAllFamInstances
4445
, hptAllAnnotations
4546

4647
-- ** More Traversal-based queries
@@ -207,6 +208,14 @@ hptAllInstances hpt = do
207208
let (insts, famInsts) = unzip hits
208209
return (foldl' unionInstEnv emptyInstEnv insts, concat famInsts)
209210

211+
-- | Find all the family instance declarations from the HPT
212+
hptAllFamInstances :: HomePackageTable -> IO (ModuleEnv FamInstEnv)
213+
hptAllFamInstances = fmap mkModuleEnv . concatHpt (\hmi -> [(hmiModule hmi, hmiFamInstEnv hmi)])
214+
where
215+
hmiModule = mi_module . hm_iface
216+
hmiFamInstEnv = extendFamInstEnvList emptyFamInstEnv
217+
. md_fam_insts . hm_details
218+
210219
-- | All annotations from the HPT
211220
hptAllAnnotations :: HomePackageTable -> IO AnnEnv
212221
hptAllAnnotations = fmap mkAnnEnv . concatHpt (md_anns . hm_details)

0 commit comments

Comments
 (0)