summaryrefslogtreecommitdiff
path: root/compiler/GHC.hs
diff options
context:
space:
mode:
authorFendor <power.walross@gmail.com>2021-02-03 19:12:02 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-03-28 17:26:37 -0400
commit29d758631c0d9124485aafc89cddc4ec5a668653 (patch)
tree72efc6ad23ddc052cecd01b493384b8fbc74daab /compiler/GHC.hs
parentb02c8ef768df33ef4845da2f15583cf143a4d0e2 (diff)
downloadhaskell-29d758631c0d9124485aafc89cddc4ec5a668653.tar.gz
Add UnitId to Target record
In the future, we want `HscEnv` to support multiple home units at the same time. This means, that there will be 'Target's that do not belong to the current 'HomeUnit'. This is an API change without changing behaviour. Update haddock submodule to incorporate API changes.
Diffstat (limited to 'compiler/GHC.hs')
-rw-r--r--compiler/GHC.hs32
1 files changed, 21 insertions, 11 deletions
diff --git a/compiler/GHC.hs b/compiler/GHC.hs
index 4e554e58ce..4054ead5f2 100644
--- a/compiler/GHC.hs
+++ b/compiler/GHC.hs
@@ -935,7 +935,7 @@ removeTarget :: GhcMonad m => TargetId -> m ()
removeTarget target_id
= modifySession (\h -> h{ hsc_targets = filter (hsc_targets h) })
where
- filter targets = [ t | t@(Target id _ _) <- targets, id /= target_id ]
+ filter targets = [ t | t@Target { targetId = id } <- targets, id /= target_id ]
-- | Attempts to guess what Target a string refers to. This function
-- implements the @--make@/GHCi command-line syntax for filenames:
@@ -948,23 +948,25 @@ removeTarget target_id
--
-- - otherwise interpret the string as a module name
--
-guessTarget :: GhcMonad m => String -> Maybe Phase -> m Target
-guessTarget str (Just phase)
- = return (Target (TargetFile str (Just phase)) True Nothing)
-guessTarget str Nothing
+guessTarget :: GhcMonad m => String -> Maybe UnitId -> Maybe Phase -> m Target
+guessTarget str mUnitId (Just phase)
+ = do
+ tuid <- unitIdOrHomeUnit mUnitId
+ return (Target (TargetFile str (Just phase)) True tuid Nothing)
+guessTarget str mUnitId Nothing
| isHaskellSrcFilename file
- = return (target (TargetFile file Nothing))
+ = target (TargetFile file Nothing)
| otherwise
= do exists <- liftIO $ doesFileExist hs_file
if exists
- then return (target (TargetFile hs_file Nothing))
+ then target (TargetFile hs_file Nothing)
else do
exists <- liftIO $ doesFileExist lhs_file
if exists
- then return (target (TargetFile lhs_file Nothing))
+ then target (TargetFile lhs_file Nothing)
else do
if looksLikeModuleName file
- then return (target (TargetModule (mkModuleName file)))
+ then target (TargetModule (mkModuleName file))
else do
dflags <- getDynFlags
liftIO $ throwGhcExceptionIO
@@ -979,8 +981,16 @@ guessTarget str Nothing
hs_file = file <.> "hs"
lhs_file = file <.> "lhs"
- target tid = Target tid obj_allowed Nothing
+ target tid = do
+ tuid <- unitIdOrHomeUnit mUnitId
+ pure $ Target tid obj_allowed tuid Nothing
+-- | Unwrap 'UnitId' or retrieve the 'UnitId'
+-- of the current 'HomeUnit'.
+unitIdOrHomeUnit :: GhcMonad m => Maybe UnitId -> m UnitId
+unitIdOrHomeUnit mUnitId = do
+ currentHomeUnitId <- homeUnitId . ue_home_unit . hsc_unit_env <$> getSession
+ pure (fromMaybe currentHomeUnitId mUnitId)
-- | Inform GHC that the working directory has changed. GHC will flush
-- its cache of module locations, since it may no longer be valid.
@@ -1243,7 +1253,7 @@ compileToCoreSimplified = compileCore True
compileCore :: GhcMonad m => Bool -> FilePath -> m CoreModule
compileCore simplify fn = do
-- First, set the target to the desired filename
- target <- guessTarget fn Nothing
+ target <- guessTarget fn Nothing Nothing
addTarget target
_ <- load LoadAllTargets
-- Then find dependencies