never executed always true always false
    1 -- | Info about modules in the "home" unit
    2 module GHC.Unit.Home.ModInfo
    3    ( HomeModInfo (..)
    4    , HomePackageTable
    5    , emptyHomePackageTable
    6    , lookupHpt
    7    , eltsHpt
    8    , filterHpt
    9    , allHpt
   10    , anyHpt
   11    , mapHpt
   12    , delFromHpt
   13    , addToHpt
   14    , addHomeModInfoToHpt
   15    , addListToHpt
   16    , lookupHptDirectly
   17    , lookupHptByModule
   18    , listToHpt
   19    , listHMIToHpt
   20    , pprHPT
   21    )
   22 where
   23 
   24 import GHC.Prelude
   25 
   26 import GHC.Unit.Module.ModIface
   27 import GHC.Unit.Module.ModDetails
   28 import GHC.Unit.Module
   29 
   30 import GHC.Linker.Types ( Linkable(..) )
   31 
   32 import GHC.Types.Unique
   33 import GHC.Types.Unique.DFM
   34 
   35 import GHC.Utils.Outputable
   36 import Data.List (sortOn)
   37 import Data.Ord
   38 
   39 -- | Information about modules in the package being compiled
   40 data HomeModInfo = HomeModInfo
   41    { hm_iface    :: !ModIface
   42         -- ^ The basic loaded interface file: every loaded module has one of
   43         -- these, even if it is imported from another package
   44 
   45    , hm_details  :: ModDetails
   46         -- ^ Extra information that has been created from the 'ModIface' for
   47         -- the module, typically during typechecking
   48 
   49         -- This field is LAZY because a ModDetails is constructed by knot tying.
   50 
   51    , hm_linkable :: !(Maybe Linkable)
   52         -- ^ The actual artifact we would like to link to access things in
   53         -- this module.
   54         --
   55         -- 'hm_linkable' might be Nothing:
   56         --
   57         --   1. If this is an .hs-boot module
   58         --
   59         --   2. Temporarily during compilation if we pruned away
   60         --      the old linkable because it was out of date.
   61         --
   62         -- After a complete compilation ('GHC.load'), all 'hm_linkable' fields
   63         -- in the 'HomePackageTable' will be @Just@.
   64         --
   65         -- When re-linking a module ('GHC.Driver.Main.HscNoRecomp'), we construct the
   66         -- 'HomeModInfo' by building a new 'ModDetails' from the old
   67         -- 'ModIface' (only).
   68    }
   69 
   70 -- | Helps us find information about modules in the home package
   71 type HomePackageTable = DModuleNameEnv HomeModInfo
   72    -- Domain = modules in the home unit that have been fully compiled
   73    -- "home" unit id cached (implicit) here for convenience
   74 
   75 -- | Constructs an empty HomePackageTable
   76 emptyHomePackageTable :: HomePackageTable
   77 emptyHomePackageTable  = emptyUDFM
   78 
   79 lookupHpt :: HomePackageTable -> ModuleName -> Maybe HomeModInfo
   80 lookupHpt = lookupUDFM
   81 
   82 lookupHptDirectly :: HomePackageTable -> Unique -> Maybe HomeModInfo
   83 lookupHptDirectly = lookupUDFM_Directly
   84 
   85 eltsHpt :: HomePackageTable -> [HomeModInfo]
   86 eltsHpt = eltsUDFM
   87 
   88 filterHpt :: (HomeModInfo -> Bool) -> HomePackageTable -> HomePackageTable
   89 filterHpt = filterUDFM
   90 
   91 allHpt :: (HomeModInfo -> Bool) -> HomePackageTable -> Bool
   92 allHpt = allUDFM
   93 
   94 anyHpt :: (HomeModInfo -> Bool) -> HomePackageTable -> Bool
   95 anyHpt = anyUDFM
   96 
   97 mapHpt :: (HomeModInfo -> HomeModInfo) -> HomePackageTable -> HomePackageTable
   98 mapHpt = mapUDFM
   99 
  100 delFromHpt :: HomePackageTable -> ModuleName -> HomePackageTable
  101 delFromHpt = delFromUDFM
  102 
  103 addToHpt :: HomePackageTable -> ModuleName -> HomeModInfo -> HomePackageTable
  104 addToHpt = addToUDFM
  105 
  106 addHomeModInfoToHpt :: HomeModInfo -> HomePackageTable -> HomePackageTable
  107 addHomeModInfoToHpt hmi hpt = addToHpt hpt (moduleName (mi_module (hm_iface hmi))) hmi
  108 
  109 addListToHpt
  110   :: HomePackageTable -> [(ModuleName, HomeModInfo)] -> HomePackageTable
  111 addListToHpt = addListToUDFM
  112 
  113 listToHpt :: [(ModuleName, HomeModInfo)] -> HomePackageTable
  114 listToHpt = listToUDFM
  115 
  116 listHMIToHpt :: [HomeModInfo] -> HomePackageTable
  117 listHMIToHpt hmis =
  118   listToHpt [(moduleName (mi_module (hm_iface hmi)), hmi) | hmi <- sorted_hmis]
  119   where
  120     -- Sort to put Non-boot things last, so they overwrite the boot interfaces
  121     -- in the HPT, other than that, the order doesn't matter
  122     sorted_hmis = sortOn (Down . mi_boot . hm_iface) hmis
  123 
  124 lookupHptByModule :: HomePackageTable -> Module -> Maybe HomeModInfo
  125 -- The HPT is indexed by ModuleName, not Module,
  126 -- we must check for a hit on the right Module
  127 lookupHptByModule hpt mod
  128   = case lookupHpt hpt (moduleName mod) of
  129       Just hm | mi_module (hm_iface hm) == mod -> Just hm
  130       _otherwise                               -> Nothing
  131 
  132 pprHPT :: HomePackageTable -> SDoc
  133 -- A bit arbitrary for now
  134 pprHPT hpt = pprUDFM hpt $ \hms ->
  135     vcat [ hang (ppr (mi_module (hm_iface hm)))
  136               2 (ppr (md_types (hm_details hm)))
  137          | hm <- hms ]
  138