Hannes Siebenhandl pushed to branch wip/fendor/homeunit-is-just at Glasgow Haskell Compiler / GHC
Commits:
18 changed files:
- compiler/GHC.hs
- compiler/GHC/Driver/Backpack.hs
- compiler/GHC/Driver/Env.hs
- compiler/GHC/Driver/Main.hs
- compiler/GHC/Driver/Pipeline/Execute.hs
- compiler/GHC/Driver/Session/Units.hs
- compiler/GHC/Iface/Errors.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Linker/Deps.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/StgToJS/Linker/Linker.hs
- compiler/GHC/Tc/Utils/Backpack.hs
- compiler/GHC/Tc/Utils/Monad.hs
- compiler/GHC/Unit/Env.hs
- compiler/GHC/Unit/Finder.hs
- compiler/GHC/Unit/Home.hs
- compiler/GHC/Unit/Home/Graph.hs
- ghc/GHCi/UI.hs
Changes:
| ... | ... | @@ -677,7 +677,7 @@ setUnitDynFlagsNoCheck uid dflags1 = do |
| 677 | 677 | { homeUnitEnv_units = unit_state
|
| 678 | 678 | , homeUnitEnv_unit_dbs = Just dbs
|
| 679 | 679 | , homeUnitEnv_dflags = updated_dflags
|
| 680 | - , homeUnitEnv_home_unit = Just home_unit
|
|
| 680 | + , homeUnitEnv_home_unit = home_unit
|
|
| 681 | 681 | }
|
| 682 | 682 | |
| 683 | 683 | let unit_env = UnitEnv.ue_updateHomeUnitEnv upd uid (hsc_unit_env hsc_env)
|
| ... | ... | @@ -768,7 +768,7 @@ setProgramDynFlags_ invalidate_needed dflags = do |
| 768 | 768 | , homeUnitEnv_unit_dbs = Just dbs
|
| 769 | 769 | , homeUnitEnv_dflags = updated_dflags
|
| 770 | 770 | , homeUnitEnv_hpt = old_hpt
|
| 771 | - , homeUnitEnv_home_unit = Just home_unit
|
|
| 771 | + , homeUnitEnv_home_unit = home_unit
|
|
| 772 | 772 | }
|
| 773 | 773 | |
| 774 | 774 | let dflags1 = homeUnitEnv_dflags $ HUG.unitEnv_lookup (ue_currentUnit old_unit_env) home_unit_graph
|
| ... | ... | @@ -892,7 +892,7 @@ setProgramHUG_ invalidate_needed new_hug0 = do |
| 892 | 892 | , homeUnitEnv_unit_dbs = Just dbs
|
| 893 | 893 | , homeUnitEnv_dflags = updated_dflags
|
| 894 | 894 | , homeUnitEnv_hpt = old_hpt
|
| 895 | - , homeUnitEnv_home_unit = Just home_unit
|
|
| 895 | + , homeUnitEnv_home_unit = home_unit
|
|
| 896 | 896 | }
|
| 897 | 897 | |
| 898 | 898 | -- When changing the DynFlags, we want the changes to apply to future
|
| ... | ... | @@ -1691,7 +1691,7 @@ findQualifiedModule pkgqual mod_name = withSession $ \hsc_env -> do |
| 1691 | 1691 | Nothing -> liftIO $ do
|
| 1692 | 1692 | res <- findImportedModule hsc_env mod_name pkgqual
|
| 1693 | 1693 | case res of
|
| 1694 | - Found loc m | notHomeModuleMaybe mhome_unit m -> return m
|
|
| 1694 | + Found loc m | notHomeModule mhome_unit m -> return m
|
|
| 1695 | 1695 | | otherwise -> modNotLoadedError dflags m loc
|
| 1696 | 1696 | err -> throwOneError sec $ noModError hsc_env noSrcSpan mod_name err
|
| 1697 | 1697 |
| ... | ... | @@ -459,7 +459,7 @@ addUnit u = do |
| 459 | 459 | , ue_home_unit_graph =
|
| 460 | 460 | HUG.unitEnv_singleton
|
| 461 | 461 | (homeUnitId home_unit)
|
| 462 | - (HUG.mkHomeUnitEnv unit_state (Just dbs) dflags (ue_hpt old_unit_env) (Just home_unit))
|
|
| 462 | + (HUG.mkHomeUnitEnv unit_state (Just dbs) dflags (ue_hpt old_unit_env) (home_unit))
|
|
| 463 | 463 | , ue_eps = ue_eps old_unit_env
|
| 464 | 464 | , ue_module_graph = ue_module_graph old_unit_env
|
| 465 | 465 | }
|
| ... | ... | @@ -117,7 +117,7 @@ runInteractiveHsc hsc_env = runHsc (mkInteractiveHscEnv hsc_env) |
| 117 | 117 | hsc_home_unit :: HscEnv -> HomeUnit
|
| 118 | 118 | hsc_home_unit = ue_unsafeHomeUnit . hsc_unit_env
|
| 119 | 119 | |
| 120 | -hsc_home_unit_maybe :: HscEnv -> Maybe HomeUnit
|
|
| 120 | +hsc_home_unit_maybe :: HscEnv -> HomeUnit
|
|
| 121 | 121 | hsc_home_unit_maybe = ue_homeUnit . hsc_unit_env
|
| 122 | 122 | |
| 123 | 123 | hsc_units :: HasDebugCallStack => HscEnv -> UnitState
|
| ... | ... | @@ -374,7 +374,7 @@ lookupIfaceByModuleHsc hsc_env mod = do |
| 374 | 374 | lookupIfaceByModule (hsc_HUG hsc_env) (eps_PIT eps) mod
|
| 375 | 375 | |
| 376 | 376 | mainModIs :: HomeUnitEnv -> Module
|
| 377 | -mainModIs hue = mkHomeModule (expectJust $ homeUnitEnv_home_unit hue) (mainModuleNameIs (homeUnitEnv_dflags hue))
|
|
| 377 | +mainModIs hue = mkHomeModule (homeUnitEnv_home_unit hue) (mainModuleNameIs (homeUnitEnv_dflags hue))
|
|
| 378 | 378 | |
| 379 | 379 | -- | Retrieve the target code interpreter
|
| 380 | 380 | --
|
| ... | ... | @@ -38,6 +38,7 @@ module GHC.Driver.Main |
| 38 | 38 | newHscEnv
|
| 39 | 39 | , newHscEnvWithHUG
|
| 40 | 40 | , initHscEnv
|
| 41 | + , createHomeUnitEnvFromFlags
|
|
| 41 | 42 | |
| 42 | 43 | -- * Compiling complete source files
|
| 43 | 44 | , Messager, batchMsg, batchMultiMsg
|
| ... | ... | @@ -298,6 +299,7 @@ import Data.Bifunctor |
| 298 | 299 | import qualified GHC.Unit.Home.Graph as HUG
|
| 299 | 300 | import GHC.Unit.Home.PackageTable
|
| 300 | 301 | import qualified GHC.ByteCode.Serialize as ByteCode
|
| 302 | +import qualified Data.Set as Set
|
|
| 301 | 303 | |
| 302 | 304 | {- **********************************************************************
|
| 303 | 305 | %* *
|
| ... | ... | @@ -307,18 +309,15 @@ import qualified GHC.ByteCode.Serialize as ByteCode |
| 307 | 309 | |
| 308 | 310 | newHscEnv :: FilePath -> DynFlags -> IO HscEnv
|
| 309 | 311 | newHscEnv top_dir dflags = do
|
| 310 | - hpt <- emptyHomePackageTable
|
|
| 311 | - newHscEnvWithHUG top_dir dflags (homeUnitId_ dflags) (home_unit_graph hpt)
|
|
| 312 | - where
|
|
| 313 | - home_unit_graph hpt = HUG.unitEnv_singleton
|
|
| 314 | - (homeUnitId_ dflags)
|
|
| 315 | - (HUG.mkHomeUnitEnv emptyUnitState Nothing dflags hpt Nothing)
|
|
| 312 | + logger <- initLogger
|
|
| 313 | + -- TODO: doesn't quite work, we call 'initUnits' in 'createHomeUnitEnvFromFlags'
|
|
| 314 | + (home_unit_graph, mainUnitId) <- createHomeUnitEnvFromFlags logger (NE.singleton dflags)
|
|
| 315 | + newHscEnvWithHUG logger top_dir dflags mainUnitId home_unit_graph
|
|
| 316 | 316 | |
| 317 | -newHscEnvWithHUG :: FilePath -> DynFlags -> UnitId -> HomeUnitGraph -> IO HscEnv
|
|
| 318 | -newHscEnvWithHUG top_dir top_dynflags cur_unit home_unit_graph = do
|
|
| 317 | +newHscEnvWithHUG :: Logger -> FilePath -> DynFlags -> UnitId -> HomeUnitGraph -> IO HscEnv
|
|
| 318 | +newHscEnvWithHUG logger top_dir top_dynflags cur_unit home_unit_graph = do
|
|
| 319 | 319 | nc_var <- newNameCache
|
| 320 | 320 | fc_var <- initFinderCache
|
| 321 | - logger <- initLogger
|
|
| 322 | 321 | tmpfs <- initTmpFs
|
| 323 | 322 | let dflags = homeUnitEnv_dflags $ HUG.unitEnv_lookup cur_unit home_unit_graph
|
| 324 | 323 | unit_env <- initUnitEnv cur_unit home_unit_graph (ghcNameVersion dflags) (targetPlatform dflags)
|
| ... | ... | @@ -338,6 +337,24 @@ newHscEnvWithHUG top_dir top_dynflags cur_unit home_unit_graph = do |
| 338 | 337 | , hsc_llvm_config = llvm_config
|
| 339 | 338 | }
|
| 340 | 339 | |
| 340 | +createHomeUnitEnvFromFlags :: Logger -> NE.NonEmpty DynFlags -> IO (HomeUnitGraph, UnitId)
|
|
| 341 | +createHomeUnitEnvFromFlags logger unitDflags = do
|
|
| 342 | + let home_units = Set.fromList (NE.toList $ NE.map homeUnitId_ unitDflags)
|
|
| 343 | + |
|
| 344 | + homeUnitEnvs <- forM (NE.toList unitDflags) $ \dflags -> do
|
|
| 345 | + let cached_unit_dbs = Nothing
|
|
| 346 | + hue_flags = dflags
|
|
| 347 | + |
|
| 348 | + (dbs,unit_state,home_unit,mconstants) <- liftIO $ initUnits logger hue_flags cached_unit_dbs home_units
|
|
| 349 | + |
|
| 350 | + updated_dflags <- liftIO $ updatePlatformConstants dflags mconstants
|
|
| 351 | + hpt <- liftIO emptyHomePackageTable
|
|
| 352 | + pure (homeUnitId home_unit, HUG.mkHomeUnitEnv unit_state (Just dbs) updated_dflags hpt home_unit)
|
|
| 353 | + |
|
| 354 | + let activeUnit = homeUnitId_ $ NE.head unitDflags
|
|
| 355 | + let home_unit_graph = HUG.hugFromList homeUnitEnvs
|
|
| 356 | + return (home_unit_graph, activeUnit)
|
|
| 357 | + |
|
| 341 | 358 | -- | Initialize HscEnv from an optional top_dir path
|
| 342 | 359 | initHscEnv :: Maybe FilePath -> IO HscEnv
|
| 343 | 360 | initHscEnv mb_top_dir = do
|
| ... | ... | @@ -473,7 +473,7 @@ runCcPhase cc_phase pipe_env hsc_env location input_fn = do |
| 473 | 473 | -- way we do the import depends on whether we're currently compiling
|
| 474 | 474 | -- the base package or not.
|
| 475 | 475 | ++ (case home_unit of
|
| 476 | - Just hu
|
|
| 476 | + hu
|
|
| 477 | 477 | | isHomeUnitId hu ghcInternalUnitId
|
| 478 | 478 | , platformOS platform == OSMinGW32
|
| 479 | 479 | -> ["-DCOMPILING_GHC_INTERNAL_PACKAGE"]
|
| ... | ... | @@ -17,10 +17,7 @@ import GHC.Driver.Config.Diagnostic |
| 17 | 17 | |
| 18 | 18 | import GHC.Unit.Env
|
| 19 | 19 | import GHC.Unit (UnitId)
|
| 20 | -import GHC.Unit.Home.PackageTable
|
|
| 21 | 20 | import qualified GHC.Unit.Home.Graph as HUG
|
| 22 | -import GHC.Unit.State ( emptyUnitState )
|
|
| 23 | -import qualified GHC.Unit.State as State
|
|
| 24 | 21 | |
| 25 | 22 | import GHC.Types.SrcLoc
|
| 26 | 23 | import GHC.Types.SourceError
|
| ... | ... | @@ -42,6 +39,7 @@ import GHC.ResponseFile (expandResponse) |
| 42 | 39 | import Data.Bifunctor
|
| 43 | 40 | import GHC.Data.Graph.Directed
|
| 44 | 41 | import qualified Data.List.NonEmpty as NE
|
| 42 | +import GHC.Driver.Main (createHomeUnitEnvFromFlags)
|
|
| 45 | 43 | |
| 46 | 44 | -- Strip out any ["+RTS", ..., "-RTS"] sequences in the command string list.
|
| 47 | 45 | removeRTS :: [String] -> [String]
|
| ... | ... | @@ -125,24 +123,7 @@ initMulti unitArgsFiles lintDynFlagsAndSrcs = do |
| 125 | 123 | |
| 126 | 124 | checkDuplicateUnits initial_dflags (NE.toList (NE.zip unitArgsFiles unitDflags))
|
| 127 | 125 | |
| 128 | - (initial_home_graph, mainUnitId) <- liftIO $ createUnitEnvFromFlags unitDflags
|
|
| 129 | - let home_units = HUG.allUnits initial_home_graph
|
|
| 130 | - |
|
| 131 | - home_unit_graph <- forM initial_home_graph $ \homeUnitEnv -> do
|
|
| 132 | - let cached_unit_dbs = homeUnitEnv_unit_dbs homeUnitEnv
|
|
| 133 | - hue_flags = homeUnitEnv_dflags homeUnitEnv
|
|
| 134 | - dflags = homeUnitEnv_dflags homeUnitEnv
|
|
| 135 | - (dbs,unit_state,home_unit,mconstants) <- liftIO $ State.initUnits logger hue_flags cached_unit_dbs home_units
|
|
| 136 | - |
|
| 137 | - updated_dflags <- liftIO $ updatePlatformConstants dflags mconstants
|
|
| 138 | - emptyHpt <- liftIO $ emptyHomePackageTable
|
|
| 139 | - pure $ HomeUnitEnv
|
|
| 140 | - { homeUnitEnv_units = unit_state
|
|
| 141 | - , homeUnitEnv_unit_dbs = Just dbs
|
|
| 142 | - , homeUnitEnv_dflags = updated_dflags
|
|
| 143 | - , homeUnitEnv_hpt = emptyHpt
|
|
| 144 | - , homeUnitEnv_home_unit = Just home_unit
|
|
| 145 | - }
|
|
| 126 | + (home_unit_graph, mainUnitId) <- liftIO $ createHomeUnitEnvFromFlags logger unitDflags
|
|
| 146 | 127 | |
| 147 | 128 | checkUnitCycles initial_dflags home_unit_graph
|
| 148 | 129 | |
| ... | ... | @@ -232,16 +213,3 @@ offsetDynFlags dflags = |
| 232 | 213 | augment_maybe (Just f) = Just (augment f)
|
| 233 | 214 | augment f | isRelative f, Just offset <- workingDirectory dflags = offset </> f
|
| 234 | 215 | | otherwise = f |
| 235 | - |
|
| 236 | - |
|
| 237 | -createUnitEnvFromFlags :: NE.NonEmpty DynFlags -> IO (HomeUnitGraph, UnitId)
|
|
| 238 | -createUnitEnvFromFlags unitDflags = do
|
|
| 239 | - unitEnvList <- forM unitDflags $ \dflags -> do
|
|
| 240 | - emptyHpt <- emptyHomePackageTable
|
|
| 241 | - let newInternalUnitEnv =
|
|
| 242 | - HUG.mkHomeUnitEnv emptyUnitState Nothing dflags emptyHpt Nothing
|
|
| 243 | - return (homeUnitId_ dflags, newInternalUnitEnv)
|
|
| 244 | - let activeUnit = fst $ NE.head unitEnvList
|
|
| 245 | - return (HUG.hugFromList (NE.toList unitEnvList), activeUnit)
|
|
| 246 | - |
|
| 247 | - |
| ... | ... | @@ -27,7 +27,7 @@ badIfaceFile file err |
| 27 | 27 | = vcat [text "Bad interface file:" <+> text file,
|
| 28 | 28 | nest 4 err]
|
| 29 | 29 | |
| 30 | -cannotFindInterface :: UnitState -> Maybe HomeUnit -> Profile
|
|
| 30 | +cannotFindInterface :: UnitState -> HomeUnit -> Profile
|
|
| 31 | 31 | -> ModuleName -> InstalledFindResult -> MissingInterfaceError
|
| 32 | 32 | cannotFindInterface us mhu p mn ifr =
|
| 33 | 33 | CantFindErr us FindingInterface $
|
| ... | ... | @@ -35,7 +35,7 @@ cannotFindInterface us mhu p mn ifr = |
| 35 | 35 | |
| 36 | 36 | cantFindInstalledErr
|
| 37 | 37 | :: UnitState
|
| 38 | - -> Maybe HomeUnit
|
|
| 38 | + -> HomeUnit
|
|
| 39 | 39 | -> Profile
|
| 40 | 40 | -> ModuleName
|
| 41 | 41 | -> InstalledFindResult
|
| ... | ... | @@ -52,7 +52,7 @@ cantFindInstalledErr unit_state mhome_unit profile mod_name find_result |
| 52 | 52 | |
| 53 | 53 | InstalledNotFound files mb_pkg
|
| 54 | 54 | | Just pkg <- mb_pkg
|
| 55 | - , notHomeUnitId mhome_unit pkg
|
|
| 55 | + , not (isHomeUnitId mhome_unit pkg)
|
|
| 56 | 56 | -> not_found_in_package pkg $ fmap unsafeDecodeUtf files
|
| 57 | 57 | |
| 58 | 58 | | null files
|
| ... | ... | @@ -111,11 +111,7 @@ cantFindErr unit_env profile mod_name find_result |
| 111 | 111 | , fr_mods_hidden = mod_hiddens, fr_pkgs_hidden = pkg_hiddens
|
| 112 | 112 | , fr_unusables = unusables, fr_suggestions = suggest }
|
| 113 | 113 | | Just pkg <- mb_pkg
|
| 114 | - , Nothing <- mhome_unit -- no home-unit
|
|
| 115 | - -> not_found_in_package (toUnitId pkg) files
|
|
| 116 | - |
|
| 117 | - | Just pkg <- mb_pkg
|
|
| 118 | - , Just home_unit <- mhome_unit -- there is a home-unit but the
|
|
| 114 | + , home_unit <- mhome_unit -- there is a home-unit but the
|
|
| 119 | 115 | , not (isHomeUnit home_unit pkg) -- module isn't from it
|
| 120 | 116 | -> not_found_in_package (toUnitId pkg) files
|
| 121 | 117 |
| ... | ... | @@ -711,12 +711,12 @@ dontLeakTheHUG thing_inside = do |
| 711 | 711 | -- | Returns @True@ if a 'ModIface' comes from an external package.
|
| 712 | 712 | -- In this case, we should NOT load it into the EPS; the entities
|
| 713 | 713 | -- should instead come from the local merged signature interface.
|
| 714 | -is_external_sig :: Maybe HomeUnit -> ModIface -> Bool
|
|
| 714 | +is_external_sig :: HomeUnit -> ModIface -> Bool
|
|
| 715 | 715 | is_external_sig mhome_unit iface =
|
| 716 | 716 | -- It's a signature iface...
|
| 717 | 717 | mi_semantic_module iface /= mi_module iface &&
|
| 718 | 718 | -- and it's not from the local package
|
| 719 | - notHomeModuleMaybe mhome_unit (mi_module iface)
|
|
| 719 | + notHomeModule mhome_unit (mi_module iface)
|
|
| 720 | 720 | |
| 721 | 721 | -- | This is an improved version of 'findAndReadIface' which can also
|
| 722 | 722 | -- handle the case when a user requests @p[A=<B>]:M@ but we only
|
| ... | ... | @@ -745,7 +745,7 @@ computeInterface hsc_env doc_str hi_boot_file mod0 = do |
| 745 | 745 | m mod0 hi_boot_file
|
| 746 | 746 | case getModuleInstantiation mod0 of
|
| 747 | 747 | (imod, Just indef)
|
| 748 | - | Just home_unit <- mhome_unit
|
|
| 748 | + | home_unit <- mhome_unit
|
|
| 749 | 749 | , isHomeUnitIndefinite home_unit ->
|
| 750 | 750 | find_iface imod >>= \case
|
| 751 | 751 | Succeeded (iface0, path) ->
|
| ... | ... | @@ -803,13 +803,13 @@ moduleFreeHolesPrecise doc_str mod |
| 803 | 803 | return (Succeeded (renameFreeHoles ifhs insts))
|
| 804 | 804 | Failed err -> return (Failed err)
|
| 805 | 805 | |
| 806 | -wantHiBootFile :: Maybe HomeUnit -> ExternalPackageState -> Module -> WhereFrom
|
|
| 806 | +wantHiBootFile :: HomeUnit -> ExternalPackageState -> Module -> WhereFrom
|
|
| 807 | 807 | -> MaybeErr MissingInterfaceError IsBootInterface
|
| 808 | 808 | -- Figure out whether we want Foo.hi or Foo.hi-boot
|
| 809 | 809 | wantHiBootFile mhome_unit eps mod from
|
| 810 | 810 | = case from of
|
| 811 | 811 | ImportByUser usr_boot
|
| 812 | - | usr_boot == IsBoot && notHomeModuleMaybe mhome_unit mod
|
|
| 812 | + | usr_boot == IsBoot && notHomeModule mhome_unit mod
|
|
| 813 | 813 | -> Failed (BadSourceImport mod)
|
| 814 | 814 | | otherwise -> Succeeded usr_boot
|
| 815 | 815 | |
| ... | ... | @@ -817,7 +817,7 @@ wantHiBootFile mhome_unit eps mod from |
| 817 | 817 | -> Succeeded NotBoot
|
| 818 | 818 | |
| 819 | 819 | ImportBySystem
|
| 820 | - | notHomeModuleMaybe mhome_unit mod
|
|
| 820 | + | notHomeModule mhome_unit mod
|
|
| 821 | 821 | -> Succeeded NotBoot
|
| 822 | 822 | -- If the module to be imported is not from this package
|
| 823 | 823 | -- don't look it up in eps_is_boot, because that is keyed
|
| ... | ... | @@ -163,8 +163,7 @@ get_link_deps opts pls maybe_normal_osuf span mods = do |
| 163 | 163 | -- It's not in the HPT because we are in one shot mode,
|
| 164 | 164 | -- so use the Finder to get a ModLocation...
|
| 165 | 165 | case ue_homeUnit unit_env of
|
| 166 | - Nothing -> no_obj mod
|
|
| 167 | - Just home_unit -> do
|
|
| 166 | + home_unit -> do
|
|
| 168 | 167 | |
| 169 | 168 | let fc = ldFinderCache opts
|
| 170 | 169 | let fopts = ldFinderOpts opts
|
| ... | ... | @@ -452,7 +452,7 @@ renamePkgQual :: UnitEnv -> ModuleName -> Maybe FastString -> PkgQual |
| 452 | 452 | renamePkgQual unit_env mn mb_pkg = case mb_pkg of
|
| 453 | 453 | Nothing -> NoPkgQual
|
| 454 | 454 | Just pkg_fs
|
| 455 | - | Just uid <- homeUnitId <$> ue_homeUnit unit_env
|
|
| 455 | + | uid <- homeUnitId (ue_homeUnit unit_env)
|
|
| 456 | 456 | , pkg_fs == fsLit "this"
|
| 457 | 457 | -> ThisPkg uid
|
| 458 | 458 |
| ... | ... | @@ -489,8 +489,7 @@ computeLinkDependencies cfg unit_env link_spec finder_opts finder_cache ar_cache |
| 489 | 489 | -- It's not in the HPT because we are in one shot mode,
|
| 490 | 490 | -- so use the Finder to get a ModLocation...
|
| 491 | 491 | case ue_homeUnit unit_env of
|
| 492 | - Nothing -> pprPanic "getDeps: No home-unit: " (pprModule mod)
|
|
| 493 | - Just home_unit -> do
|
|
| 492 | + home_unit -> do
|
|
| 494 | 493 | mb_stuff <- findHomeModule finder_cache finder_opts home_unit (moduleName mod)
|
| 495 | 494 | case mb_stuff of
|
| 496 | 495 | Found loc mod -> found loc mod
|
| ... | ... | @@ -285,7 +285,7 @@ implicitRequirements hsc_env normal_imports |
| 285 | 285 | forM normal_imports $ \(mb_pkg, L _ imp) -> do
|
| 286 | 286 | found <- findImportedModule hsc_env imp mb_pkg
|
| 287 | 287 | case found of
|
| 288 | - Found _ mod | notHomeModuleMaybe mhome_unit mod ->
|
|
| 288 | + Found _ mod | notHomeModule mhome_unit mod ->
|
|
| 289 | 289 | return (uniqDSetToList (moduleFreeHoles mod))
|
| 290 | 290 | _ -> return []
|
| 291 | 291 | where
|
| ... | ... | @@ -307,7 +307,7 @@ implicitRequirementsShallow hsc_env normal_imports = go ([], []) normal_imports |
| 307 | 307 | go (accL, accR) ((_stage, mb_pkg, L _ imp):imports) = do
|
| 308 | 308 | found <- findImportedModule hsc_env imp mb_pkg
|
| 309 | 309 | let acc' = case found of
|
| 310 | - Found _ mod | notHomeModuleMaybe mhome_unit mod ->
|
|
| 310 | + Found _ mod | notHomeModule mhome_unit mod ->
|
|
| 311 | 311 | case moduleUnit mod of
|
| 312 | 312 | HoleUnit -> (moduleName mod : accL, accR)
|
| 313 | 313 | RealUnit _ -> (accL, accR)
|
| ... | ... | @@ -2406,7 +2406,7 @@ initIfaceTcRn thing_inside |
| 2406 | 2406 | !knot_vars = tcg_type_env_var tcg_env
|
| 2407 | 2407 | -- When we are instantiating a signature, we DEFINITELY
|
| 2408 | 2408 | -- do not want to knot tie.
|
| 2409 | - is_instantiate = fromMaybe False (isHomeUnitInstantiating <$> mhome_unit)
|
|
| 2409 | + is_instantiate = (isHomeUnitInstantiating mhome_unit)
|
|
| 2410 | 2410 | ; let { if_env = IfGblEnv {
|
| 2411 | 2411 | if_doc = text "initIfaceTcRn",
|
| 2412 | 2412 | if_rec_types =
|
| ... | ... | @@ -214,14 +214,13 @@ preloadUnitsInfo' unit_env ids0 = all_infos |
| 214 | 214 | where
|
| 215 | 215 | unit_state = HUG.homeUnitEnv_units (ue_currentHomeUnitEnv unit_env)
|
| 216 | 216 | ids = ids0 ++ inst_ids
|
| 217 | - inst_ids = case ue_homeUnit unit_env of
|
|
| 218 | - Nothing -> []
|
|
| 219 | - Just home_unit
|
|
| 220 | - -- An indefinite package will have insts to HOLE,
|
|
| 217 | + home_unit = ue_homeUnit unit_env
|
|
| 218 | + inst_ids
|
|
| 219 | + -- An indefinite package will have insts to HOLE,
|
|
| 221 | 220 | -- which is not a real package. Don't look it up.
|
| 222 | 221 | -- Fixes #14525
|
| 223 | - | isHomeUnitIndefinite home_unit -> []
|
|
| 224 | - | otherwise -> map (toUnitId . moduleUnit . snd) (homeUnitInstantiations home_unit)
|
|
| 222 | + | isHomeUnitIndefinite home_unit = []
|
|
| 223 | + | otherwise = map (toUnitId . moduleUnit . snd) (homeUnitInstantiations home_unit)
|
|
| 225 | 224 | pkg_map = unitInfoMap unit_state
|
| 226 | 225 | preload = preloadUnits unit_state
|
| 227 | 226 | |
| ... | ... | @@ -302,20 +301,18 @@ ue_setFlags dflags env = |
| 302 | 301 | -- Query and modify home units in HomeUnitEnv
|
| 303 | 302 | -- -------------------------------------------------------
|
| 304 | 303 | |
| 305 | -ue_homeUnit :: UnitEnv -> Maybe HomeUnit
|
|
| 304 | +ue_homeUnit :: UnitEnv -> HomeUnit
|
|
| 306 | 305 | ue_homeUnit = HUG.homeUnitEnv_home_unit . ue_currentHomeUnitEnv
|
| 307 | 306 | |
| 308 | 307 | ue_unsafeHomeUnit :: UnitEnv -> HomeUnit
|
| 309 | -ue_unsafeHomeUnit ue = case ue_homeUnit ue of
|
|
| 310 | - Nothing -> panic "ue_unsafeHomeUnit: No home unit"
|
|
| 311 | - Just h -> h
|
|
| 308 | +ue_unsafeHomeUnit ue = ue_homeUnit ue
|
|
| 312 | 309 | |
| 313 | 310 | ue_unitHomeUnit :: UnitId -> UnitEnv -> HomeUnit
|
| 314 | 311 | ue_unitHomeUnit uid = expectJust . ue_unitHomeUnit_maybe uid
|
| 315 | 312 | |
| 316 | 313 | ue_unitHomeUnit_maybe :: UnitId -> UnitEnv -> Maybe HomeUnit
|
| 317 | 314 | ue_unitHomeUnit_maybe uid ue_env =
|
| 318 | - HUG.homeUnitEnv_home_unit =<< HUG.lookupHugUnitId uid (ue_home_unit_graph ue_env)
|
|
| 315 | + HUG.homeUnitEnv_home_unit <$> HUG.lookupHugUnitId uid (ue_home_unit_graph ue_env)
|
|
| 319 | 316 | |
| 320 | 317 | -- -------------------------------------------------------
|
| 321 | 318 | -- Query and modify the currently active unit
|
| ... | ... | @@ -195,33 +195,29 @@ findImportedModuleNoHsc |
| 195 | 195 | :: FinderCache
|
| 196 | 196 | -> FinderOpts
|
| 197 | 197 | -> UnitEnv
|
| 198 | - -> Maybe HomeUnit
|
|
| 198 | + -> HomeUnit
|
|
| 199 | 199 | -> ModuleName
|
| 200 | 200 | -> PkgQual
|
| 201 | 201 | -> IO FindResult
|
| 202 | 202 | findImportedModuleNoHsc fc fopts ue mhome_unit mod_name mb_pkg =
|
| 203 | 203 | case mb_pkg of
|
| 204 | 204 | NoPkgQual -> unqual_import
|
| 205 | - ThisPkg uid | (homeUnitId <$> mhome_unit) == Just uid -> home_import
|
|
| 205 | + ThisPkg uid | (homeUnitId mhome_unit) == uid -> home_import
|
|
| 206 | 206 | | Just os <- lookup uid other_fopts -> home_pkg_import (uid, os)
|
| 207 | - | otherwise -> pprPanic "findImportModule" (ppr mod_name $$ ppr mb_pkg $$ ppr (homeUnitId <$> mhome_unit) $$ ppr uid $$ ppr (map fst all_opts))
|
|
| 207 | + | otherwise -> pprPanic "findImportModule" (ppr mod_name $$ ppr mb_pkg $$ ppr (homeUnitId mhome_unit) $$ ppr uid $$ ppr (map fst all_opts))
|
|
| 208 | 208 | OtherPkg _ -> pkg_import
|
| 209 | 209 | where
|
| 210 | - all_opts = case mhome_unit of
|
|
| 211 | - Nothing -> other_fopts
|
|
| 212 | - Just home_unit -> (homeUnitId home_unit, fopts) : other_fopts
|
|
| 210 | + all_opts = (homeUnitId mhome_unit, fopts) : other_fopts
|
|
| 213 | 211 | |
| 214 | 212 | |
| 215 | - home_import = case mhome_unit of
|
|
| 216 | - Just home_unit -> findHomeModule fc fopts home_unit mod_name
|
|
| 217 | - Nothing -> pure $ NoPackage (panic "findImportedModule: no home-unit")
|
|
| 213 | + home_import = findHomeModule fc fopts mhome_unit mod_name
|
|
| 218 | 214 | |
| 219 | 215 | |
| 220 | 216 | home_pkg_import (uid, opts)
|
| 221 | 217 | -- If the module is reexported, then look for it as if it was from the perspective
|
| 222 | 218 | -- of that package which reexports it.
|
| 223 | 219 | | Just real_mod_name <- lookupUniqMap (finder_reexportedModules opts) mod_name =
|
| 224 | - findImportedModuleNoHsc fc opts ue (Just $ DefiniteHomeUnit uid Nothing) real_mod_name NoPkgQual
|
|
| 220 | + findImportedModuleNoHsc fc opts ue (DefiniteHomeUnit uid Nothing) real_mod_name NoPkgQual
|
|
| 225 | 221 | | elementOfUniqSet mod_name (finder_hiddenModules opts) =
|
| 226 | 222 | return (mkHomeHidden uid)
|
| 227 | 223 | | otherwise =
|
| ... | ... | @@ -238,9 +234,7 @@ findImportedModuleNoHsc fc fopts ue mhome_unit mod_name mb_pkg = |
| 238 | 234 | `orIfNotFound`
|
| 239 | 235 | findExposedPackageModule fc fopts units mod_name NoPkgQual
|
| 240 | 236 | |
| 241 | - units = case mhome_unit of
|
|
| 242 | - Nothing -> ue_homeUnitState ue
|
|
| 243 | - Just home_unit -> HUG.homeUnitEnv_units $ ue_findHomeUnitEnv (homeUnitId home_unit) ue
|
|
| 237 | + units = HUG.homeUnitEnv_units $ ue_findHomeUnitEnv (homeUnitId mhome_unit) ue
|
|
| 244 | 238 | hpt_deps :: [UnitId]
|
| 245 | 239 | hpt_deps = Set.toList (homeUnitDepends units)
|
| 246 | 240 | other_fopts = map (\uid -> (uid, initFinderOpts (homeUnitEnv_dflags (ue_findHomeUnitEnv uid ue)))) hpt_deps
|
| ... | ... | @@ -249,13 +243,11 @@ findImportedModuleNoHsc fc fopts ue mhome_unit mod_name mb_pkg = |
| 249 | 243 | -- plugin. This consults the same set of exposed packages as
|
| 250 | 244 | -- 'findImportedModule', unless @-hide-all-plugin-packages@ or
|
| 251 | 245 | -- @-plugin-package@ are specified.
|
| 252 | -findPluginModuleNoHsc :: FinderCache -> FinderOpts -> UnitState -> Maybe HomeUnit -> ModuleName -> IO FindResult
|
|
| 253 | -findPluginModuleNoHsc fc fopts units (Just home_unit) mod_name =
|
|
| 246 | +findPluginModuleNoHsc :: FinderCache -> FinderOpts -> UnitState -> HomeUnit -> ModuleName -> IO FindResult
|
|
| 247 | +findPluginModuleNoHsc fc fopts units home_unit mod_name =
|
|
| 254 | 248 | findHomeModule fc fopts home_unit mod_name
|
| 255 | 249 | `orIfNotFound`
|
| 256 | 250 | findExposedPluginPackageModule fc fopts units mod_name
|
| 257 | -findPluginModuleNoHsc fc fopts units Nothing mod_name =
|
|
| 258 | - findExposedPluginPackageModule fc fopts units mod_name
|
|
| 259 | 251 | |
| 260 | 252 | findPluginModule :: HscEnv -> ModuleName -> IO FindResult
|
| 261 | 253 | findPluginModule hsc_env mod_name = do
|
| ... | ... | @@ -267,15 +259,15 @@ findPluginModule hsc_env mod_name = do |
| 267 | 259 | |
| 268 | 260 | -- | A version of findExactModule which takes the exact parts of the HscEnv it needs
|
| 269 | 261 | -- directly.
|
| 270 | -findExactModuleNoHsc :: FinderCache -> FinderOpts -> UnitEnvGraph FinderOpts -> UnitState -> Maybe HomeUnit -> InstalledModule -> IsBootInterface -> IO InstalledFindResult
|
|
| 262 | +findExactModuleNoHsc :: FinderCache -> FinderOpts -> UnitEnvGraph FinderOpts -> UnitState -> HomeUnit -> InstalledModule -> IsBootInterface -> IO InstalledFindResult
|
|
| 271 | 263 | findExactModuleNoHsc fc fopts other_fopts unit_state mhome_unit mod is_boot = do
|
| 272 | 264 | res <- case mhome_unit of
|
| 273 | - Just home_unit
|
|
| 265 | + home_unit
|
|
| 274 | 266 | | isHomeInstalledModule home_unit mod
|
| 275 | 267 | -> findInstalledHomeModule fc fopts (homeUnitId home_unit) (moduleName mod)
|
| 276 | 268 | | Just home_fopts <- HUG.unitEnv_lookup_maybe (moduleUnit mod) other_fopts
|
| 277 | 269 | -> findInstalledHomeModule fc home_fopts (moduleUnit mod) (moduleName mod)
|
| 278 | - _ -> findPackageModule fc unit_state fopts mod
|
|
| 270 | + | otherwise -> findPackageModule fc unit_state fopts mod
|
|
| 279 | 271 | case (res, is_boot) of
|
| 280 | 272 | (InstalledFound loc, IsBoot) -> return (InstalledFound (addBootSuffixLocn loc))
|
| 281 | 273 | _ -> return res
|
| ... | ... | @@ -211,9 +211,8 @@ homeModuleNameInstantiation hu mod_name = |
| 211 | 211 | -- the instantiating module of @r:A@ in @p[A=q[]:B]@ is @r:A@.
|
| 212 | 212 | -- the instantiating module of @p:A@ in @p@ is @p:A@.
|
| 213 | 213 | -- the instantiating module of @r:A@ in @p@ is @r:A@.
|
| 214 | -homeModuleInstantiation :: Maybe HomeUnit -> Module -> Module
|
|
| 215 | -homeModuleInstantiation mhu mod
|
|
| 216 | - | Just hu <- mhu
|
|
| 217 | - , isHomeModule hu mod = homeModuleNameInstantiation hu (moduleName mod)
|
|
| 214 | +homeModuleInstantiation :: HomeUnit -> Module -> Module
|
|
| 215 | +homeModuleInstantiation hu mod
|
|
| 216 | + | isHomeModule hu mod = homeModuleNameInstantiation hu (moduleName mod)
|
|
| 218 | 217 | | otherwise = mod
|
| 219 | 218 |
| ... | ... | @@ -160,11 +160,11 @@ data HomeUnitEnv = HomeUnitEnv |
| 160 | 160 | --
|
| 161 | 161 | -- (This changes a previous invariant: changed Jan 05.)
|
| 162 | 162 | |
| 163 | - , homeUnitEnv_home_unit :: !(Maybe HomeUnit)
|
|
| 163 | + , homeUnitEnv_home_unit :: !(HomeUnit)
|
|
| 164 | 164 | -- ^ Home-unit
|
| 165 | 165 | }
|
| 166 | 166 | |
| 167 | -mkHomeUnitEnv :: UnitState -> Maybe [UnitDatabase UnitId] -> DynFlags -> HomePackageTable -> Maybe HomeUnit -> HomeUnitEnv
|
|
| 167 | +mkHomeUnitEnv :: UnitState -> Maybe [UnitDatabase UnitId] -> DynFlags -> HomePackageTable -> HomeUnit -> HomeUnitEnv
|
|
| 168 | 168 | mkHomeUnitEnv us dbs dflags hpt home_unit = HomeUnitEnv
|
| 169 | 169 | { homeUnitEnv_units = us
|
| 170 | 170 | , homeUnitEnv_unit_dbs = dbs
|
| ... | ... | @@ -383,6 +383,6 @@ pprHomeUnitEnv :: UnitId -> HomeUnitEnv -> IO SDoc |
| 383 | 383 | pprHomeUnitEnv uid env = do
|
| 384 | 384 | hptDoc <- pprHPT $ homeUnitEnv_hpt env
|
| 385 | 385 | return $
|
| 386 | - ppr uid <+> text "(flags:" <+> ppr (homeUnitId_ $ homeUnitEnv_dflags env) <> text "," <+> ppr (fmap homeUnitId $ homeUnitEnv_home_unit env) <> text ")" <+> text "->"
|
|
| 386 | + ppr uid <+> text "(flags:" <+> ppr (homeUnitId_ $ homeUnitEnv_dflags env) <> text "," <+> ppr ( homeUnitId $ homeUnitEnv_home_unit env) <> text ")" <+> text "->"
|
|
| 387 | 387 | $$ nest 4 hptDoc
|
| 388 | 388 |
| ... | ... | @@ -737,7 +737,7 @@ installInteractiveHomeUnits = do |
| 737 | 737 | [ sessionUnitExposedFlag ] ++
|
| 738 | 738 | [ homeUnitPkgFlag uid
|
| 739 | 739 | | homeUnitEnv <- Foldable.toList $ hsc_HUG hsc_env
|
| 740 | - , Just homeUnit <- [homeUnitEnv_home_unit homeUnitEnv]
|
|
| 740 | + , let homeUnit = homeUnitEnv_home_unit homeUnitEnv
|
|
| 741 | 741 | , let uid = homeUnitId homeUnit
|
| 742 | 742 | ] ++
|
| 743 | 743 | (packageFlags dflags0)
|
| ... | ... | @@ -753,7 +753,7 @@ installInteractiveHomeUnits = do |
| 753 | 753 | { packageFlags =
|
| 754 | 754 | [ homeUnitPkgFlag uid
|
| 755 | 755 | | homeUnitEnv <- Foldable.toList $ hsc_HUG hsc_env
|
| 756 | - , Just homeUnit <- [homeUnitEnv_home_unit homeUnitEnv]
|
|
| 756 | + , let homeUnit = homeUnitEnv_home_unit homeUnitEnv
|
|
| 757 | 757 | , let uid = homeUnitId homeUnit
|
| 758 | 758 | ] ++
|
| 759 | 759 | (packageFlags dflags)
|
| ... | ... | @@ -801,7 +801,7 @@ installInteractiveHomeUnits = do |
| 801 | 801 | (dbs,unit_state,home_unit,_mconstants) <-
|
| 802 | 802 | liftIO $ initUnits logger dflags (Just cached_unit_dbs) all_home_units
|
| 803 | 803 | hpt <- liftIO emptyHomePackageTable
|
| 804 | - pure (HUG.mkHomeUnitEnv unit_state (Just dbs) dflags hpt (Just home_unit))
|
|
| 804 | + pure (HUG.mkHomeUnitEnv unit_state (Just dbs) dflags hpt home_unit)
|
|
| 805 | 805 | |
| 806 | 806 | reportError :: GhciMonad m => GhciCommandMessage -> m ()
|
| 807 | 807 | reportError err = do
|