Torsten Schmits pushed to branch wip/torsten.schmits/mwb-26-01/mp-backports at Glasgow Haskell Compiler / GHC
Commits:
-
ff5e16b0
by Sjoerd Visscher at 2026-03-13T16:20:54+01:00
-
ffceb7e6
by Sjoerd Visscher at 2026-03-13T16:36:00+01:00
-
65d1ec83
by Torsten Schmits at 2026-03-13T16:39:40+01:00
10 changed files:
- compiler/GHC/Driver/Backpack.hs
- compiler/GHC/Driver/Make.hs
- compiler/GHC/Driver/MakeFile.hs
- compiler/GHC/Driver/Phases.hs
- compiler/GHC/Driver/Pipeline/Execute.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Unit/Finder.hs
- compiler/GHC/Unit/Finder/Types.hs
- compiler/GHC/Unit/Module/Location.hs
Changes:
| ... | ... | @@ -788,7 +788,7 @@ summariseRequirement pn mod_name = do |
| 788 | 788 | let loc = srcLocSpan (mkSrcLoc (mkFastString (bkp_filename env)) 1 1)
|
| 789 | 789 | |
| 790 | 790 | let fc = hsc_FC hsc_env
|
| 791 | - mod <- liftIO $ addHomeModuleToFinder fc home_unit mod_name location
|
|
| 791 | + mod <- liftIO $ addHomeModuleToFinder fc home_unit mod_name location HsigFile
|
|
| 792 | 792 | |
| 793 | 793 | extra_sig_imports <- liftIO $ findExtraSigImports hsc_env HsigFile mod_name
|
| 794 | 794 | |
| ... | ... | @@ -862,17 +862,14 @@ hsModuleToModSummary home_keys pn hsc_src modname |
| 862 | 862 | -- To add insult to injury, we don't even actually use
|
| 863 | 863 | -- these filenames to figure out where the hi files go.
|
| 864 | 864 | -- A travesty!
|
| 865 | - let location0 = mkHomeModLocation2 fopts modname
|
|
| 865 | + let location = mkHomeModLocation fopts modname
|
|
| 866 | 866 | (unsafeEncodeUtf $ unpackFS unit_fs </>
|
| 867 | 867 | moduleNameSlashes modname)
|
| 868 | - (case hsc_src of
|
|
| 868 | + (case hsc_src of
|
|
| 869 | 869 | HsigFile -> os "hsig"
|
| 870 | 870 | HsBootFile -> os "hs-boot"
|
| 871 | 871 | HsSrcFile -> os "hs")
|
| 872 | - -- DANGEROUS: bootifying can POISON the module finder cache
|
|
| 873 | - let location = case hsc_src of
|
|
| 874 | - HsBootFile -> addBootSuffixLocnOut location0
|
|
| 875 | - _ -> location0
|
|
| 872 | + hsc_src
|
|
| 876 | 873 | -- This duplicates a pile of logic in GHC.Driver.Make
|
| 877 | 874 | hi_timestamp <- liftIO $ modificationTimeIfExists (ml_hi_file location)
|
| 878 | 875 | hie_timestamp <- liftIO $ modificationTimeIfExists (ml_hie_file location)
|
| ... | ... | @@ -903,7 +900,7 @@ hsModuleToModSummary home_keys pn hsc_src modname |
| 903 | 900 | this_mod <- liftIO $ do
|
| 904 | 901 | let home_unit = hsc_home_unit hsc_env
|
| 905 | 902 | let fc = hsc_FC hsc_env
|
| 906 | - addHomeModuleToFinder fc home_unit modname location
|
|
| 903 | + addHomeModuleToFinder fc home_unit modname location hsc_src
|
|
| 907 | 904 | let ms = ModSummary {
|
| 908 | 905 | ms_mod = this_mod,
|
| 909 | 906 | ms_hsc_src = hsc_src,
|
| ... | ... | @@ -2122,16 +2122,23 @@ summariseFile hsc_env' home_unit old_summaries src_fn mb_phase maybe_buf |
| 2122 | 2122 | <- getPreprocessedImports hsc_env src_fn mb_phase maybe_buf
|
| 2123 | 2123 | |
| 2124 | 2124 | let fopts = initFinderOpts (hsc_dflags hsc_env)
|
| 2125 | + (basename, extension) = splitExtension src_fn
|
|
| 2125 | 2126 | |
| 2126 | - -- Make a ModLocation for this file
|
|
| 2127 | - let location = mkHomeModLocation fopts pi_mod_name (unsafeEncodeUtf src_fn)
|
|
| 2127 | + hsc_src
|
|
| 2128 | + | isHaskellSigSuffix (drop 1 extension) = HsigFile
|
|
| 2129 | + | isHaskellBootSuffix (drop 1 extension) = HsBootFile
|
|
| 2130 | + | otherwise = HsSrcFile
|
|
| 2131 | + |
|
| 2132 | + -- Make a ModLocation for this file, adding the @-boot@ suffix to
|
|
| 2133 | + -- all paths if the original was a boot file.
|
|
| 2134 | + location = mkHomeModLocation fopts pi_mod_name (unsafeEncodeUtf basename) (unsafeEncodeUtf extension) hsc_src
|
|
| 2128 | 2135 | |
| 2129 | 2136 | -- Tell the Finder cache where it is, so that subsequent calls
|
| 2130 | 2137 | -- to findModule will find it, even if it's not on any search path
|
| 2131 | 2138 | mod <- liftIO $ do
|
| 2132 | 2139 | let home_unit = hsc_home_unit hsc_env
|
| 2133 | 2140 | let fc = hsc_FC hsc_env
|
| 2134 | - addHomeModuleToFinder fc home_unit pi_mod_name location
|
|
| 2141 | + addHomeModuleToFinder fc home_unit pi_mod_name location hsc_src
|
|
| 2135 | 2142 | |
| 2136 | 2143 | liftIO $ makeNewModSummary hsc_env $ MakeNewModSummary
|
| 2137 | 2144 | { nms_src_fn = src_fn
|
| ... | ... | @@ -2166,13 +2173,10 @@ checkSummaryHash |
| 2166 | 2173 | -- and it was likely flushed in depanal. This is not technically
|
| 2167 | 2174 | -- needed when we're called from sumariseModule but it shouldn't
|
| 2168 | 2175 | -- hurt.
|
| 2169 | - -- Also, only add to finder cache for non-boot modules as the finder cache
|
|
| 2170 | - -- makes sure to add a boot suffix for boot files.
|
|
| 2171 | - _ <- do
|
|
| 2172 | - let fc = hsc_FC hsc_env
|
|
| 2173 | - case ms_hsc_src old_summary of
|
|
| 2174 | - HsSrcFile -> addModuleToFinder fc (ms_mod old_summary) location
|
|
| 2175 | - _ -> return ()
|
|
| 2176 | + let fc = hsc_FC hsc_env
|
|
| 2177 | + mod = ms_mod old_summary
|
|
| 2178 | + hsc_src = ms_hsc_src old_summary
|
|
| 2179 | + addModuleToFinder fc mod location hsc_src
|
|
| 2176 | 2180 | |
| 2177 | 2181 | hi_timestamp <- modificationTimeIfExists (ml_hi_file location)
|
| 2178 | 2182 | hie_timestamp <- modificationTimeIfExists (ml_hie_file location)
|
| ... | ... | @@ -2224,7 +2228,7 @@ summariseModule hsc_env' home_unit old_summary_map is_boot (L _ wanted_mod) mb_p |
| 2224 | 2228 | find_it :: IO SummariseResult
|
| 2225 | 2229 | |
| 2226 | 2230 | find_it = do
|
| 2227 | - found <- findImportedModule hsc_env wanted_mod mb_pkg
|
|
| 2231 | + found <- findImportedModuleWithIsBoot hsc_env wanted_mod is_boot mb_pkg
|
|
| 2228 | 2232 | case found of
|
| 2229 | 2233 | Found location mod
|
| 2230 | 2234 | | isJust (ml_hs_file location) ->
|
| ... | ... | @@ -2242,10 +2246,7 @@ summariseModule hsc_env' home_unit old_summary_map is_boot (L _ wanted_mod) mb_p |
| 2242 | 2246 | just_found location mod = do
|
| 2243 | 2247 | -- Adjust location to point to the hs-boot source file,
|
| 2244 | 2248 | -- hi file, object file, when is_boot says so
|
| 2245 | - let location' = case is_boot of
|
|
| 2246 | - IsBoot -> addBootSuffixLocn location
|
|
| 2247 | - NotBoot -> location
|
|
| 2248 | - src_fn = expectJust "summarise2" (ml_hs_file location')
|
|
| 2249 | + let src_fn = expectJust "summarise2" (ml_hs_file location)
|
|
| 2249 | 2250 | |
| 2250 | 2251 | -- Check that it exists
|
| 2251 | 2252 | -- It might have been deleted since the Finder last found it
|
| ... | ... | @@ -2255,7 +2256,7 @@ summariseModule hsc_env' home_unit old_summary_map is_boot (L _ wanted_mod) mb_p |
| 2255 | 2256 | -- .hs-boot file doesn't exist.
|
| 2256 | 2257 | Nothing -> return NotThere
|
| 2257 | 2258 | Just h -> do
|
| 2258 | - fresult <- new_summary_cache_check location' mod src_fn h
|
|
| 2259 | + fresult <- new_summary_cache_check location mod src_fn h
|
|
| 2259 | 2260 | return $ case fresult of
|
| 2260 | 2261 | Left err -> FoundHomeWithError (moduleUnitId mod, err)
|
| 2261 | 2262 | Right ms -> FoundHome ms
|
| ... | ... | @@ -307,7 +307,7 @@ findDependency :: HscEnv |
| 307 | 307 | findDependency hsc_env srcloc pkg imp dep_boot = do
|
| 308 | 308 | -- Find the module; this will be fast because
|
| 309 | 309 | -- we've done it once during downsweep
|
| 310 | - findImportedModule hsc_env imp pkg >>= \case
|
|
| 310 | + findImportedModuleWithIsBoot hsc_env imp dep_boot pkg >>= \case
|
|
| 311 | 311 | Found loc dep_mod ->
|
| 312 | 312 | pure DepHi {
|
| 313 | 313 | dep_mod,
|
| ... | ... | @@ -356,10 +356,9 @@ writeDependencies include_pkgs root hdl suffixes node deps = |
| 356 | 356 | -- e.g. A.o : B.hi
|
| 357 | 357 | -- A.x_o : B.x_hi
|
| 358 | 358 | import_dep = \case
|
| 359 | - DepHi {dep_path, dep_boot, dep_unit}
|
|
| 359 | + DepHi {dep_path, dep_unit}
|
|
| 360 | 360 | | isNothing dep_unit || include_pkgs
|
| 361 | - , let path = addBootSuffix_maybe dep_boot dep_path
|
|
| 362 | - -> [([obj], hi) | (obj, hi) <- zip obj_files (suffixed path)]
|
|
| 361 | + -> [([obj], hi) | (obj, hi) <- zip obj_files (suffixed dep_path)]
|
|
| 363 | 362 | |
| 364 | 363 | | otherwise
|
| 365 | 364 | -> []
|
| ... | ... | @@ -23,6 +23,7 @@ module GHC.Driver.Phases ( |
| 23 | 23 | isDynLibSuffix,
|
| 24 | 24 | isHaskellUserSrcSuffix,
|
| 25 | 25 | isHaskellSigSuffix,
|
| 26 | + isHaskellBootSuffix,
|
|
| 26 | 27 | isSourceSuffix,
|
| 27 | 28 | |
| 28 | 29 | isHaskellishTarget,
|
| ... | ... | @@ -234,7 +235,7 @@ phaseInputExt Js = "js" |
| 234 | 235 | phaseInputExt StopLn = "o"
|
| 235 | 236 | |
| 236 | 237 | haskellish_src_suffixes, backpackish_suffixes, haskellish_suffixes, cish_suffixes,
|
| 237 | - js_suffixes, haskellish_user_src_suffixes, haskellish_sig_suffixes
|
|
| 238 | + js_suffixes, haskellish_user_src_suffixes, haskellish_sig_suffixes, haskellish_boot_suffixes
|
|
| 238 | 239 | :: [String]
|
| 239 | 240 | -- When a file with an extension in the haskellish_src_suffixes group is
|
| 240 | 241 | -- loaded in --make mode, its imports will be loaded too.
|
| ... | ... | @@ -247,7 +248,8 @@ js_suffixes = [ "js" ] |
| 247 | 248 | |
| 248 | 249 | -- Will not be deleted as temp files:
|
| 249 | 250 | haskellish_user_src_suffixes =
|
| 250 | - haskellish_sig_suffixes ++ [ "hs", "lhs", "hs-boot", "lhs-boot" ]
|
|
| 251 | + haskellish_sig_suffixes ++ haskellish_boot_suffixes ++ [ "hs", "lhs" ]
|
|
| 252 | +haskellish_boot_suffixes = [ "hs-boot", "lhs-boot" ]
|
|
| 251 | 253 | haskellish_sig_suffixes = [ "hsig", "lhsig" ]
|
| 252 | 254 | backpackish_suffixes = [ "bkp" ]
|
| 253 | 255 | |
| ... | ... | @@ -265,11 +267,12 @@ dynlib_suffixes platform = case platformOS platform of |
| 265 | 267 | _ -> ["so"]
|
| 266 | 268 | |
| 267 | 269 | isHaskellishSuffix, isBackpackishSuffix, isHaskellSrcSuffix, isCishSuffix,
|
| 268 | - isHaskellUserSrcSuffix, isJsSuffix, isHaskellSigSuffix
|
|
| 270 | + isHaskellUserSrcSuffix, isJsSuffix, isHaskellSigSuffix, isHaskellBootSuffix
|
|
| 269 | 271 | :: String -> Bool
|
| 270 | 272 | isHaskellishSuffix s = s `elem` haskellish_suffixes
|
| 271 | 273 | isBackpackishSuffix s = s `elem` backpackish_suffixes
|
| 272 | 274 | isHaskellSigSuffix s = s `elem` haskellish_sig_suffixes
|
| 275 | +isHaskellBootSuffix s = s `elem` haskellish_boot_suffixes
|
|
| 273 | 276 | isHaskellSrcSuffix s = s `elem` haskellish_src_suffixes
|
| 274 | 277 | isCishSuffix s = s `elem` cish_suffixes
|
| 275 | 278 | isJsSuffix s = s `elem` js_suffixes
|
| ... | ... | @@ -725,7 +725,7 @@ runHscPhase pipe_env hsc_env0 input_fn src_flavour = do |
| 725 | 725 | mod <- do
|
| 726 | 726 | let home_unit = hsc_home_unit hsc_env
|
| 727 | 727 | let fc = hsc_FC hsc_env
|
| 728 | - addHomeModuleToFinder fc home_unit mod_name location
|
|
| 728 | + addHomeModuleToFinder fc home_unit mod_name location src_flavour
|
|
| 729 | 729 | |
| 730 | 730 | -- Make the ModSummary to hand to hscMain
|
| 731 | 731 | let
|
| ... | ... | @@ -769,24 +769,18 @@ mkOneShotModLocation :: PipeEnv -> DynFlags -> HscSource -> ModuleName -> IO Mod |
| 769 | 769 | mkOneShotModLocation pipe_env dflags src_flavour mod_name = do
|
| 770 | 770 | let PipeEnv{ src_basename=basename,
|
| 771 | 771 | src_suffix=suff } = pipe_env
|
| 772 | - let location1 = mkHomeModLocation2 fopts mod_name (unsafeEncodeUtf basename) (unsafeEncodeUtf suff)
|
|
| 773 | - |
|
| 774 | - -- Boot-ify it if necessary
|
|
| 775 | - let location2
|
|
| 776 | - | HsBootFile <- src_flavour = addBootSuffixLocnOut location1
|
|
| 777 | - | otherwise = location1
|
|
| 778 | - |
|
| 772 | + let location1 = mkHomeModLocation fopts mod_name (unsafeEncodeUtf basename) (unsafeEncodeUtf suff) src_flavour
|
|
| 779 | 773 | |
| 780 | 774 | -- Take -ohi into account if present
|
| 781 | 775 | -- This can't be done in mkHomeModuleLocation because
|
| 782 | 776 | -- it only applies to the module being compiles
|
| 783 | 777 | let ohi = outputHi dflags
|
| 784 | - location3 | Just fn <- ohi = location2{ ml_hi_file_ospath = unsafeEncodeUtf fn }
|
|
| 785 | - | otherwise = location2
|
|
| 778 | + location2 | Just fn <- ohi = location1{ ml_hi_file_ospath = unsafeEncodeUtf fn }
|
|
| 779 | + | otherwise = location1
|
|
| 786 | 780 | |
| 787 | 781 | let dynohi = dynOutputHi dflags
|
| 788 | - location4 | Just fn <- dynohi = location3{ ml_dyn_hi_file_ospath = unsafeEncodeUtf fn }
|
|
| 789 | - | otherwise = location3
|
|
| 782 | + location3 | Just fn <- dynohi = location2{ ml_dyn_hi_file_ospath = unsafeEncodeUtf fn }
|
|
| 783 | + | otherwise = location2
|
|
| 790 | 784 | |
| 791 | 785 | -- Take -o into account if present
|
| 792 | 786 | -- Very like -ohi, but we must *only* do this if we aren't linking
|
| ... | ... | @@ -799,11 +793,11 @@ mkOneShotModLocation pipe_env dflags src_flavour mod_name = do |
| 799 | 793 | location5 | Just ofile <- expl_o_file
|
| 800 | 794 | , let dyn_ofile = fromMaybe (ofile -<.> dynObjectSuf_ dflags) expl_dyn_o_file
|
| 801 | 795 | , isNoLink (ghcLink dflags)
|
| 802 | - = location4 { ml_obj_file_ospath = unsafeEncodeUtf ofile
|
|
| 796 | + = location3 { ml_obj_file_ospath = unsafeEncodeUtf ofile
|
|
| 803 | 797 | , ml_dyn_obj_file_ospath = unsafeEncodeUtf dyn_ofile }
|
| 804 | 798 | | Just dyn_ofile <- expl_dyn_o_file
|
| 805 | - = location4 { ml_dyn_obj_file_ospath = unsafeEncodeUtf dyn_ofile }
|
|
| 806 | - | otherwise = location4
|
|
| 799 | + = location3 { ml_dyn_obj_file_ospath = unsafeEncodeUtf dyn_ofile }
|
|
| 800 | + | otherwise = location3
|
|
| 807 | 801 | return location5
|
| 808 | 802 | where
|
| 809 | 803 | fopts = initFinderOpts dflags
|
| ... | ... | @@ -928,9 +928,9 @@ findAndReadIface hsc_env doc_str mod wanted_mod hi_boot_file = do |
| 928 | 928 | else do
|
| 929 | 929 | let fopts = initFinderOpts dflags
|
| 930 | 930 | -- Look for the file
|
| 931 | - mb_found <- liftIO (findExactModule fc fopts other_fopts unit_state mhome_unit mod)
|
|
| 931 | + mb_found <- liftIO (findExactModule fc fopts other_fopts unit_state mhome_unit mod hi_boot_file)
|
|
| 932 | 932 | case mb_found of
|
| 933 | - InstalledFound (addBootSuffixLocn_maybe hi_boot_file -> loc) mod -> do
|
|
| 933 | + InstalledFound loc -> do
|
|
| 934 | 934 | -- See Note [Home module load error]
|
| 935 | 935 | case mhome_unit of
|
| 936 | 936 | Just home_unit
|
| ... | ... | @@ -663,7 +663,7 @@ initLinkDepsOpts hsc_env = opts |
| 663 | 663 | Maybe.Failed err -> pure (Maybe.Failed err)
|
| 664 | 664 | Maybe.Succeeded iface ->
|
| 665 | 665 | find_location mod <&> \case
|
| 666 | - InstalledFound loc _ -> Maybe.Succeeded (iface, loc)
|
|
| 666 | + InstalledFound loc -> Maybe.Succeeded (iface, loc)
|
|
| 667 | 667 | err -> Maybe.Failed $
|
| 668 | 668 | cannotFindInterface unit_state home_unit
|
| 669 | 669 | (targetProfile dflags) (moduleName mod) err
|
| ... | ... | @@ -671,7 +671,7 @@ initLinkDepsOpts hsc_env = opts |
| 671 | 671 | find_location mod =
|
| 672 | 672 | liftIO $
|
| 673 | 673 | findExactModule (hsc_FC hsc_env) (initFinderOpts dflags)
|
| 674 | - other_fopts unit_state home_unit (toUnitId <$> mod)
|
|
| 674 | + other_fopts unit_state home_unit (toUnitId <$> mod) NotBoot
|
|
| 675 | 675 | |
| 676 | 676 | other_fopts = initFinderOpts . homeUnitEnv_dflags <$> hsc_HUG hsc_env
|
| 677 | 677 |
| ... | ... | @@ -15,6 +15,7 @@ module GHC.Unit.Finder ( |
| 15 | 15 | initFinderCache,
|
| 16 | 16 | flushFinderCaches,
|
| 17 | 17 | findImportedModule,
|
| 18 | + findImportedModuleWithIsBoot,
|
|
| 18 | 19 | findPluginModule,
|
| 19 | 20 | findExactModule,
|
| 20 | 21 | findHomeModule,
|
| ... | ... | @@ -62,6 +63,7 @@ import GHC.Utils.Panic |
| 62 | 63 | |
| 63 | 64 | import GHC.Linker.Types
|
| 64 | 65 | import GHC.Types.PkgQual
|
| 66 | +import GHC.Types.SourceFile
|
|
| 65 | 67 | |
| 66 | 68 | import GHC.Fingerprint
|
| 67 | 69 | import Data.IORef
|
| ... | ... | @@ -171,6 +173,13 @@ findImportedModule hsc_env mod pkg_qual = |
| 171 | 173 | query <- hscUnitIndexQuery hsc_env
|
| 172 | 174 | findImportedModuleNoHsc fc fopts (hsc_unit_env hsc_env) query home_module_map mhome_unit mod pkg_qual
|
| 173 | 175 | |
| 176 | +findImportedModuleWithIsBoot :: HscEnv -> ModuleName -> IsBootInterface -> PkgQual -> IO FindResult
|
|
| 177 | +findImportedModuleWithIsBoot hsc_env mod is_boot pkg_qual = do
|
|
| 178 | + res <- findImportedModule hsc_env mod pkg_qual
|
|
| 179 | + case (res, is_boot) of
|
|
| 180 | + (Found loc mod, IsBoot) -> return (Found (addBootSuffixLocn loc) mod)
|
|
| 181 | + _ -> return res
|
|
| 182 | + |
|
| 174 | 183 | findImportedModuleNoHsc
|
| 175 | 184 | :: FinderCache
|
| 176 | 185 | -> FinderOpts
|
| ... | ... | @@ -261,15 +270,19 @@ findPluginModule fc fopts units query Nothing mod_name = |
| 261 | 270 | -- reading the interface for a module mentioned by another interface,
|
| 262 | 271 | -- for example (a "system import").
|
| 263 | 272 | |
| 264 | -findExactModule :: FinderCache -> FinderOpts -> UnitEnvGraph FinderOpts -> UnitState -> Maybe HomeUnit -> InstalledModule -> IO InstalledFindResult
|
|
| 265 | -findExactModule fc fopts other_fopts unit_state mhome_unit mod = do
|
|
| 266 | - case mhome_unit of
|
|
| 273 | +findExactModule :: FinderCache -> FinderOpts -> UnitEnvGraph FinderOpts -> UnitState -> Maybe HomeUnit -> InstalledModule -> IsBootInterface -> IO InstalledFindResult
|
|
| 274 | +findExactModule fc fopts other_fopts unit_state mhome_unit mod is_boot = do
|
|
| 275 | + res <- case mhome_unit of
|
|
| 267 | 276 | Just home_unit
|
| 268 | 277 | | isHomeInstalledModule home_unit mod
|
| 269 | 278 | -> findInstalledHomeModule fc fopts (homeUnitId home_unit) (moduleName mod)
|
| 270 | 279 | | Just home_fopts <- HUG.unitEnv_lookup_maybe (moduleUnit mod) other_fopts
|
| 271 | 280 | -> findInstalledHomeModule fc home_fopts (moduleUnit mod) (moduleName mod)
|
| 272 | 281 | _ -> findPackageModule fc unit_state fopts mod
|
| 282 | + case (res, is_boot) of
|
|
| 283 | + (InstalledFound loc, IsBoot) -> return (InstalledFound (addBootSuffixLocn loc))
|
|
| 284 | + _ -> return res
|
|
| 285 | + |
|
| 273 | 286 | |
| 274 | 287 | -- -----------------------------------------------------------------------------
|
| 275 | 288 | -- Helpers
|
| ... | ... | @@ -329,7 +342,7 @@ findLookupResult fc fopts r = case r of |
| 329 | 342 | -- with just the location of the thing that was
|
| 330 | 343 | -- instantiated; you probably also need all of the
|
| 331 | 344 | -- implicit locations from the instances
|
| 332 | - InstalledFound loc _ -> return (Found loc m)
|
|
| 345 | + InstalledFound loc -> return (Found loc m)
|
|
| 333 | 346 | InstalledNoPackage _ -> return (NoPackage (moduleUnit m))
|
| 334 | 347 | InstalledNotFound fp _ -> return (NotFound{ fr_paths = fmap unsafeDecodeUtf fp, fr_pkg = Just (moduleUnit m)
|
| 335 | 348 | , fr_pkgs_hidden = []
|
| ... | ... | @@ -374,16 +387,18 @@ modLocationCache fc mod do_this = do |
| 374 | 387 | addToFinderCache fc mod result
|
| 375 | 388 | return result
|
| 376 | 389 | |
| 377 | -addModuleToFinder :: FinderCache -> Module -> ModLocation -> IO ()
|
|
| 378 | -addModuleToFinder fc mod loc = do
|
|
| 390 | +addModuleToFinder :: FinderCache -> Module -> ModLocation -> HscSource -> IO ()
|
|
| 391 | +addModuleToFinder fc mod loc src_flavour = do
|
|
| 379 | 392 | let imod = toUnitId <$> mod
|
| 380 | - addToFinderCache fc imod (InstalledFound loc imod)
|
|
| 393 | + unless (src_flavour == HsBootFile) $
|
|
| 394 | + addToFinderCache fc imod (InstalledFound loc)
|
|
| 381 | 395 | |
| 382 | 396 | -- This returns a module because it's more convenient for users
|
| 383 | -addHomeModuleToFinder :: FinderCache -> HomeUnit -> ModuleName -> ModLocation -> IO Module
|
|
| 384 | -addHomeModuleToFinder fc home_unit mod_name loc = do
|
|
| 397 | +addHomeModuleToFinder :: FinderCache -> HomeUnit -> ModuleName -> ModLocation -> HscSource -> IO Module
|
|
| 398 | +addHomeModuleToFinder fc home_unit mod_name loc src_flavour = do
|
|
| 385 | 399 | let mod = mkHomeInstalledModule home_unit mod_name
|
| 386 | - addToFinderCache fc mod (InstalledFound loc mod)
|
|
| 400 | + unless (src_flavour == HsBootFile) $
|
|
| 401 | + addToFinderCache fc mod (InstalledFound loc)
|
|
| 387 | 402 | return (mkHomeModule home_unit mod_name)
|
| 388 | 403 | |
| 389 | 404 | uncacheModule :: FinderCache -> HomeUnit -> ModuleName -> IO ()
|
| ... | ... | @@ -399,7 +414,7 @@ findHomeModule fc fopts home_unit mod_name = do |
| 399 | 414 | let uid = homeUnitAsUnit home_unit
|
| 400 | 415 | r <- findInstalledHomeModule fc fopts (homeUnitId home_unit) mod_name
|
| 401 | 416 | return $ case r of
|
| 402 | - InstalledFound loc _ -> Found loc (mkHomeModule home_unit mod_name)
|
|
| 417 | + InstalledFound loc -> Found loc (mkHomeModule home_unit mod_name)
|
|
| 403 | 418 | InstalledNoPackage _ -> NoPackage uid -- impossible
|
| 404 | 419 | InstalledNotFound fps _ -> NotFound {
|
| 405 | 420 | fr_paths = fmap unsafeDecodeUtf fps,
|
| ... | ... | @@ -424,7 +439,7 @@ findHomePackageModule fc fopts home_unit mod_name = do |
| 424 | 439 | let uid = RealUnit (Definite home_unit)
|
| 425 | 440 | r <- findInstalledHomeModule fc fopts home_unit mod_name
|
| 426 | 441 | return $ case r of
|
| 427 | - InstalledFound loc _ -> Found loc (mkModule uid mod_name)
|
|
| 442 | + InstalledFound loc -> Found loc (mkModule uid mod_name)
|
|
| 428 | 443 | InstalledNoPackage _ -> NoPackage uid -- impossible
|
| 429 | 444 | InstalledNotFound fps _ -> NotFound {
|
| 430 | 445 | fr_paths = fmap unsafeDecodeUtf fps,
|
| ... | ... | @@ -494,7 +509,7 @@ findInstalledHomeModule fc fopts home_unit mod_name = do |
| 494 | 509 | -- This is important only when compiling the base package (where GHC.Prim
|
| 495 | 510 | -- is a home module).
|
| 496 | 511 | if mod `installedModuleEq` gHC_PRIM
|
| 497 | - then return (InstalledFound (error "GHC.Prim ModLocation") mod)
|
|
| 512 | + then return (InstalledFound (error "GHC.Prim ModLocation"))
|
|
| 498 | 513 | else searchPathExts search_dirs mod exts
|
| 499 | 514 | |
| 500 | 515 | -- | Prepend the working directory to the search path.
|
| ... | ... | @@ -527,7 +542,7 @@ findPackageModule_ fc fopts mod pkg_conf = do |
| 527 | 542 | |
| 528 | 543 | -- special case for GHC.Prim; we won't find it in the filesystem.
|
| 529 | 544 | if mod `installedModuleEq` gHC_PRIM
|
| 530 | - then return (InstalledFound (error "GHC.Prim ModLocation") mod)
|
|
| 545 | + then return (InstalledFound (error "GHC.Prim ModLocation"))
|
|
| 531 | 546 | else
|
| 532 | 547 | |
| 533 | 548 | let
|
| ... | ... | @@ -551,7 +566,7 @@ findPackageModule_ fc fopts mod pkg_conf = do |
| 551 | 566 | -- don't bother looking for it.
|
| 552 | 567 | let basename = unsafeEncodeUtf $ moduleNameSlashes (moduleName mod)
|
| 553 | 568 | loc = mk_hi_loc one basename
|
| 554 | - in return $ InstalledFound loc mod
|
|
| 569 | + in return $ InstalledFound loc
|
|
| 555 | 570 | _otherwise ->
|
| 556 | 571 | searchPathExts import_dirs mod [(package_hisuf, mk_hi_loc)]
|
| 557 | 572 | |
| ... | ... | @@ -585,7 +600,7 @@ searchPathExts paths mod exts = search to_search |
| 585 | 600 | search ((file, loc) : rest) = do
|
| 586 | 601 | b <- doesFileExist file
|
| 587 | 602 | if b
|
| 588 | - then return $ InstalledFound loc mod
|
|
| 603 | + then return $ InstalledFound loc
|
|
| 589 | 604 | else search rest
|
| 590 | 605 | |
| 591 | 606 | mkHomeModLocationSearched :: FinderOpts -> ModuleName -> FileExt
|
| ... | ... | @@ -627,10 +642,12 @@ mkHomeModLocationSearched fopts mod suff path basename = |
| 627 | 642 | -- ext
|
| 628 | 643 | -- The filename extension of the source file (usually "hs" or "lhs").
|
| 629 | 644 | |
| 630 | -mkHomeModLocation :: FinderOpts -> ModuleName -> OsPath -> ModLocation
|
|
| 631 | -mkHomeModLocation dflags mod src_filename =
|
|
| 632 | - let (basename,extension) = OsPath.splitExtension src_filename
|
|
| 633 | - in mkHomeModLocation2 dflags mod basename extension
|
|
| 645 | +mkHomeModLocation :: FinderOpts -> ModuleName -> OsPath -> FileExt -> HscSource -> ModLocation
|
|
| 646 | +mkHomeModLocation dflags mod src_basename ext hsc_src =
|
|
| 647 | + let loc = mkHomeModLocation2 dflags mod src_basename ext
|
|
| 648 | + in case hsc_src of
|
|
| 649 | + HsBootFile -> addBootSuffixLocnOut loc
|
|
| 650 | + _ -> loc
|
|
| 634 | 651 | |
| 635 | 652 | mkHomeModLocation2 :: FinderOpts
|
| 636 | 653 | -> ModuleName
|
| ... | ... | @@ -30,7 +30,7 @@ data FinderCache = FinderCache { fcModuleCache :: (IORef FinderCacheState) |
| 30 | 30 | }
|
| 31 | 31 | |
| 32 | 32 | data InstalledFindResult
|
| 33 | - = InstalledFound ModLocation InstalledModule
|
|
| 33 | + = InstalledFound ModLocation
|
|
| 34 | 34 | | InstalledNoPackage UnitId
|
| 35 | 35 | | InstalledNotFound [OsPath] (Maybe UnitId)
|
| 36 | 36 |
| ... | ... | @@ -13,8 +13,6 @@ module GHC.Unit.Module.Location |
| 13 | 13 | )
|
| 14 | 14 | , pattern ModLocation
|
| 15 | 15 | , addBootSuffix
|
| 16 | - , addBootSuffix_maybe
|
|
| 17 | - , addBootSuffixLocn_maybe
|
|
| 18 | 16 | , addBootSuffixLocn
|
| 19 | 17 | , addBootSuffixLocnOut
|
| 20 | 18 | , removeBootSuffix
|
| ... | ... | @@ -24,7 +22,6 @@ where |
| 24 | 22 | import GHC.Prelude
|
| 25 | 23 | |
| 26 | 24 | import GHC.Data.OsPath
|
| 27 | -import GHC.Unit.Types
|
|
| 28 | 25 | import GHC.Utils.Outputable
|
| 29 | 26 | |
| 30 | 27 | import qualified System.OsString as OsString
|
| ... | ... | @@ -96,26 +93,10 @@ removeBootSuffix pathWithBootSuffix = |
| 96 | 93 | Just path -> path
|
| 97 | 94 | Nothing -> error "removeBootSuffix: no -boot suffix"
|
| 98 | 95 | |
| 99 | --- | Add the @-boot@ suffix if the @Bool@ argument is @True@
|
|
| 100 | -addBootSuffix_maybe :: IsBootInterface -> OsPath -> OsPath
|
|
| 101 | -addBootSuffix_maybe is_boot path = case is_boot of
|
|
| 102 | - IsBoot -> addBootSuffix path
|
|
| 103 | - NotBoot -> path
|
|
| 104 | - |
|
| 105 | -addBootSuffixLocn_maybe :: IsBootInterface -> ModLocation -> ModLocation
|
|
| 106 | -addBootSuffixLocn_maybe is_boot locn = case is_boot of
|
|
| 107 | - IsBoot -> addBootSuffixLocn locn
|
|
| 108 | - _ -> locn
|
|
| 109 | - |
|
| 110 | 96 | -- | Add the @-boot@ suffix to all file paths associated with the module
|
| 111 | 97 | addBootSuffixLocn :: ModLocation -> ModLocation
|
| 112 | 98 | addBootSuffixLocn locn
|
| 113 | - = locn { ml_hs_file_ospath = fmap addBootSuffix (ml_hs_file_ospath locn)
|
|
| 114 | - , ml_hi_file_ospath = addBootSuffix (ml_hi_file_ospath locn)
|
|
| 115 | - , ml_dyn_hi_file_ospath = addBootSuffix (ml_dyn_hi_file_ospath locn)
|
|
| 116 | - , ml_obj_file_ospath = addBootSuffix (ml_obj_file_ospath locn)
|
|
| 117 | - , ml_dyn_obj_file_ospath = addBootSuffix (ml_dyn_obj_file_ospath locn)
|
|
| 118 | - , ml_hie_file_ospath = addBootSuffix (ml_hie_file_ospath locn) }
|
|
| 99 | + = addBootSuffixLocnOut locn { ml_hs_file_ospath = fmap addBootSuffix (ml_hs_file_ospath locn) }
|
|
| 119 | 100 | |
| 120 | 101 | -- | Add the @-boot@ suffix to all output file paths associated with the
|
| 121 | 102 | -- module, not including the input file itself
|
| ... | ... | @@ -157,3 +138,5 @@ pattern ModLocation |
| 157 | 138 | , ml_dyn_obj_file_ospath = unsafeEncodeUtf ml_dyn_obj_file
|
| 158 | 139 | , ml_hie_file_ospath = unsafeEncodeUtf ml_hie_file
|
| 159 | 140 | }
|
| 141 | + |
|
| 142 | +{-# complete ModLocation #-} |