[Git][ghc/ghc][wip/jeltsch/improve-closure-property-check] Document the local variables of `checkHomeUnitsClosed`
Wolfgang Jeltsch pushed to branch wip/jeltsch/improve-closure-property-check at Glasgow Haskell Compiler / GHC Commits: 0d8dbbf4 by Wolfgang Jeltsch at 2026-08-28T21:59:19+03:00 Document the local variables of `checkHomeUnitsClosed` - - - - - 1 changed file: - compiler/GHC/Driver/Downsweep.hs Changes: ===================================== compiler/GHC/Driver/Downsweep.hs ===================================== @@ -949,19 +949,33 @@ checkHomeUnitsClosed unit_env ] where + -- | The 'UnitId' and 'HomeUnitEnv' of each home unit. home_unit_data :: [(UnitId, HomeUnitEnv)] home_unit_data = HUG.unitEnv_assocs (ue_home_unit_graph unit_env) + -- | The 'UnitId's of all home units. home_units :: UniqSet UnitId home_units = mkUniqSet (map fst home_unit_data) + -- | All offending dependencies. A dependency of a unit _u_ on a unit _v_ is + -- offending exactly if _u_ is an external unit reachable from a home unit + -- and _v_ is a home unit. Each such dependency is represented in this list + -- by the pair of the 'UnitId' of _u_ and the 'UnitId' of _v_. offenders :: [(UnitId, UnitId)] offenders = evalState (collect (map (homeUnitEnv_units . snd) home_unit_data)) $ Set.empty where - collect :: [UnitState] -> State (Set GlobalUnitKey) [(UnitId, UnitId)] + -- | Collects offending dependencies. + collect :: [UnitState] + -- ^ The 'UnitState's of the home units from which to traverse + -- the dependency graph. + -> State (Set GlobalUnitKey) [(UnitId, UnitId)] + -- ^ A stateful computation that collects the offending + -- dependencies, using its state to keep track of which units + -- have already been considered as sources of offending + -- dependencies. collect [] = pure [] collect (current_unit_state : remaining_unit_states) @@ -971,23 +985,35 @@ checkHomeUnitsClosed unit_env <*> collect remaining_unit_states where - collect_for_home_unit :: UnitInfoMap - -> [UnitId] - -> State (Set GlobalUnitKey) [(UnitId, UnitId)] + -- | Collects offending dependencies that are reachable from a single home + -- unit. + collect_for_home_unit + :: UnitInfoMap + -- ^ The 'UnitInfoMap' of the home unit. + -> [UnitId] + -- ^ The 'UnitId's of the units from which to traverse the dependency + -- graph. + -> State (Set GlobalUnitKey) [(UnitId, UnitId)] + -- ^ A stateful computation that collects the offending dependencies, + -- using its state to keep track of which units have already been + -- considered as sources of offending dependencies. collect_for_home_unit _ [] = return [] collect_for_home_unit unit_info_map (current_unit : remaining_units) = do let + -- | The 'UnitInfo' of the current unit. unit_info :: UnitInfo unit_info = fromMaybe (pprPanic unit_not_found_msg (ppr current_unit)) $ lookupUniqMap unit_info_map current_unit where + -- | The message that says that a unit was not found. unit_not_found_msg :: String unit_not_found_msg = "Unit not found during closure property check" + -- | A 'GlobalUnitKey' that identifies the current unit. global_unit_key :: GlobalUnitKey global_unit_key = mkGlobalUnitKey current_unit (unitAbiHash unit_info) @@ -998,9 +1024,11 @@ checkHomeUnitsClosed unit_env modify (Set.insert global_unit_key) let + -- | The 'UnitId's of the units that the current unit depends on. needed_units :: [UnitId] needed_units = unitDepends unit_info + -- | The offending dependencies of the current unit. current_offenders :: [(UnitId, UnitId)] current_offenders | current_unit `elementOfUniqSet` home_units @@ -1014,6 +1042,7 @@ checkHomeUnitsClosed unit_env needed_units ++ remaining_units return $ current_offenders ++ remaining_offenders + -- | A fake source span used for reporting violations of the closure property. error_source_span :: SrcSpan error_source_span = mkGeneralSrcSpan (fsLit "<command line>") View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0d8dbbf4a75a120430eefc411e39a69b... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0d8dbbf4a75a120430eefc411e39a69b... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Wolfgang Jeltsch (@jeltsch)